Топ в виде графика.

This commit is contained in:
Alexey Skobkin 2015-06-26 18:05:26 +03:00
parent 57cedf5417
commit 6f2cca5799
6 changed files with 237 additions and 28 deletions

View file

@ -18,6 +18,7 @@ class AppKernel extends Kernel
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Misd\GuzzleBundle\MisdGuzzleBundle(),
new Ob\HighchartsBundle\ObHighchartsBundle(),
new Skobkin\Bundle\PointToolsBundle\SkobkinPointToolsBundle(),
);

View file

@ -21,7 +21,8 @@
"incenteev/composer-parameter-handler": "~2.0",
"misd/guzzle-bundle": "~1.0",
"doctrine/migrations": "1.0.*@dev",
"doctrine/doctrine-migrations-bundle": "2.1.*@dev"
"doctrine/doctrine-migrations-bundle": "2.1.*@dev",
"ob/highcharts-bundle": "^1.2"
},
"require-dev": {
"sensio/generator-bundle": "~2.3"

172
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "6f8a78a0b471fceb335f2e83e43985ef",
"hash": "bfe197a5b9e16d562aba89cb97f380bf",
"packages": [
{
"name": "doctrine/annotations",
@ -519,7 +519,7 @@
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/DoctrineMigrationsBundle/zipball/1e8cd4415bd2f893eb828216b529a75e8b61d579",
"url": "https://api.github.com/repos/doctrine/DoctrineMigrationsBundle/zipball/861d3564c03b3867845ffd87d9b19f49dc673c69",
"reference": "1e8cd4415bd2f893eb828216b529a75e8b61d579",
"shasum": ""
},
@ -698,7 +698,7 @@
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/migrations/zipball/abb87d84ed21fd30c27bd3b52252a495a36d32fb",
"url": "https://api.github.com/repos/doctrine/migrations/zipball/43619782df4e9ae6be6b24557f0429471eeee848",
"reference": "abb87d84ed21fd30c27bd3b52252a495a36d32fb",
"shasum": ""
},
@ -1242,6 +1242,61 @@
],
"time": "2015-03-09 09:58:04"
},
{
"name": "ob/highcharts-bundle",
"version": "1.2",
"target-dir": "Ob/HighchartsBundle",
"source": {
"type": "git",
"url": "https://github.com/marcaube/ObHighchartsBundle.git",
"reference": "cce67aa209f2a8b14db520c8e50a15cd5f5c23d0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/marcaube/ObHighchartsBundle/zipball/cce67aa209f2a8b14db520c8e50a15cd5f5c23d0",
"reference": "cce67aa209f2a8b14db520c8e50a15cd5f5c23d0",
"shasum": ""
},
"require": {
"php": ">=5.3.0",
"symfony/symfony": "~2.3",
"zendframework/zend-json": "2.3.0"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
}
},
"autoload": {
"psr-0": {
"Ob\\HighchartsBundle": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Marc Aubé"
}
],
"description": "Symfony2 Bundle that ease the use of highcharts to display rich graph and charts in your app",
"homepage": "https://github.com/marcaube/ObHighchartsBundle",
"keywords": [
"Symfony2",
"chart",
"charting",
"charts",
"graph",
"graphs",
"highcharts",
"marcaube",
"ob"
],
"time": "2014-08-04 23:56:54"
},
{
"name": "psr/log",
"version": "1.0.0",
@ -1683,7 +1738,7 @@
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/symfony/zipball/7493c2bef54fb818c5304bdd9d2194890b839422",
"url": "https://api.github.com/repos/symfony/symfony/zipball/a0af4ef1bfe8788288a2e5f95635134cba3ea842",
"reference": "7493c2bef54fb818c5304bdd9d2194890b839422",
"shasum": ""
},
@ -1903,6 +1958,115 @@
"templating"
],
"time": "2015-04-19 08:30:27"
},
{
"name": "zendframework/zend-json",
"version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/zendframework/zend-json.git",
"reference": "cf8e594a8a6516d06c25a3dc07e3be462fbea84d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zendframework/zend-json/zipball/cf8e594a8a6516d06c25a3dc07e3be462fbea84d",
"reference": "cf8e594a8a6516d06c25a3dc07e3be462fbea84d",
"shasum": ""
},
"require": {
"php": ">=5.3.23",
"zendframework/zend-stdlib": "self.version"
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "dev-master",
"zendframework/zend-http": "self.version",
"zendframework/zend-server": "self.version"
},
"suggest": {
"zendframework/zend-http": "Zend\\Http component",
"zendframework/zend-server": "Zend\\Server component",
"zendframework/zendxml": "To support Zend\\Json\\Json::fromXml() usage"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.2-dev",
"dev-develop": "2.3-dev"
}
},
"autoload": {
"psr-4": {
"Zend\\Json\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"description": "provides convenience methods for serializing native PHP to JSON and decoding JSON to native PHP",
"homepage": "https://github.com/zendframework/zend-json",
"keywords": [
"json",
"zf2"
],
"time": "2014-03-12 16:10:15"
},
{
"name": "zendframework/zend-stdlib",
"version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/zendframework/zend-stdlib.git",
"reference": "426b5396e89e7da2db9678bc9a0b57865f84fe0f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zendframework/zend-stdlib/zipball/426b5396e89e7da2db9678bc9a0b57865f84fe0f",
"reference": "426b5396e89e7da2db9678bc9a0b57865f84fe0f",
"shasum": ""
},
"require": {
"php": ">=5.3.23"
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "dev-master",
"zendframework/zend-eventmanager": "self.version",
"zendframework/zend-filter": "self.version",
"zendframework/zend-serializer": "self.version",
"zendframework/zend-servicemanager": "self.version"
},
"suggest": {
"zendframework/zend-eventmanager": "To support aggregate hydrator usage",
"zendframework/zend-filter": "To support naming strategy hydrator usage",
"zendframework/zend-serializer": "Zend\\Serializer component",
"zendframework/zend-servicemanager": "To support hydrator plugin manager usage"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.2-dev",
"dev-develop": "2.3-dev"
}
},
"autoload": {
"psr-4": {
"Zend\\Stdlib\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"homepage": "https://github.com/zendframework/zend-stdlib",
"keywords": [
"stdlib",
"zf2"
],
"time": "2014-03-12 16:10:15"
}
],
"packages-dev": [

View file

@ -3,9 +3,11 @@
namespace Skobkin\Bundle\PointToolsBundle\Controller;
use Doctrine\ORM\EntityManager;
use Skobkin\Bundle\PointToolsBundle\Entity\TopUserDTO;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Skobkin\Bundle\PointToolsBundle\Service\UserApi;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Ob\HighchartsBundle\Highcharts\Highchart;
use Symfony\Component\HttpFoundation\Request;
class UserController extends Controller
@ -37,8 +39,13 @@ class UserController extends Controller
public function topAction()
{
$topUsers = $this->getDoctrine()->getManager()->getRepository('SkobkinPointToolsBundle:User')->getTopUsers();
$topChart = $this->createTopUsersGraph($topUsers);
return $this->render('@SkobkinPointTools/User/top.html.twig', [
'top_users' => $this->getDoctrine()->getManager()->getRepository('SkobkinPointToolsBundle:User')->getTopUsers(),
'top_users' => $topUsers,
'top_chart' => $topChart,
]);
}
@ -54,4 +61,47 @@ class UserController extends Controller
}
return $this->redirectToRoute('user_show', ['login' => $login]);
}
/**
* @param TopUserDTO[] $topUsers
* @return Highchart
*/
private function createTopUsersGraph(array $topUsers = [])
{
$translator = $this->container->get('translator');
$chartData = [
'titles' => [],
'subscribers' => [],
];
// Preparing chart data
foreach ($topUsers as $user) {
$chartData['titles'][] = $user->login;
$chartData['subscribers'][] = $user->subscribersCount;
}
// Chart
$series = [[
'name' => $translator->trans('Subscribers'),
'data' => $chartData['subscribers'],
]];
// Initializing chart
$ob = new Highchart();
$ob->chart->renderTo('top-chart');
$ob->chart->type('bar');
$ob->title->text($translator->trans('Top users'));
$ob->xAxis->title(['text' => null]);
$ob->xAxis->categories($chartData['titles']);
$ob->yAxis->title(['text' => $translator->trans('amount')]);
$ob->plotOptions->bar([
'dataLabels' => [
'enabled' => true
]
]);
$ob->series($series);
return $ob;
}
}

View file

@ -33,4 +33,5 @@ No log data found: Лог отсутствует
# Топ пользователей
Top users: Популярные пользователи
Subscribers count: Подписчиков
Subscribers count: Подписчиков
amount: Количество

View file

@ -2,25 +2,17 @@
{% block header_title %}Top @ Point Tools{% endblock %}
{% block content %}
<h1>{{ 'Top users'|trans }}</h1>
<table class="table table-striped">
<thead>
<tr>
<td>&#35;</td>
<td>{{ 'User'|trans }}</td>
<td>{{ 'Subscribers count'|trans }}</td>
</tr>
</thead>
<tbody>
{% for user in top_users %}
<tr>
<td>{{ loop.index }}</td>
<td><a href="{{ url('user_show', {login: user.login}) }}">@{{ user.login }}</a></td>
<td>{{ user.subscribersCount }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% block head_js %}
{{ parent() }}
<script src="//yastatic.net/jquery/2.1.4/jquery.min.js"></script>
<script src="//code.highcharts.com/4.0.1/highcharts.js"></script>
<script src="//code.highcharts.com/4.0.1/modules/exporting.js"></script>
{% endblock %}
{% block content %}
<script type="text/javascript">
{{ chart(top_chart) }}
</script>
<div id="top-chart" style="min-width: 400px; height: 600px; margin: 0 auto;"></div>
{% endblock %}