From 6f2cca5799305f94f2c9f96d099f4282513bf8d5 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Fri, 26 Jun 2015 18:05:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=BE=D0=BF=20=D0=B2=20=D0=B2=D0=B8?= =?UTF-8?q?=D0=B4=D0=B5=20=D0=B3=D1=80=D0=B0=D1=84=D0=B8=D0=BA=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/AppKernel.php | 1 + composer.json | 3 +- composer.lock | 172 +++++++++++++++++- .../Controller/UserController.php | 52 +++++- .../Resources/translations/messages.ru.yml | 3 +- .../Resources/views/User/top.html.twig | 34 ++-- 6 files changed, 237 insertions(+), 28 deletions(-) diff --git a/app/AppKernel.php b/app/AppKernel.php index 49fa758..694ca22 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -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(), ); diff --git a/composer.json b/composer.json index 7c6a1af..058368b 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/composer.lock b/composer.lock index e29b519..1c65f54 100644 --- a/composer.lock +++ b/composer.lock @@ -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": [ diff --git a/src/Skobkin/Bundle/PointToolsBundle/Controller/UserController.php b/src/Skobkin/Bundle/PointToolsBundle/Controller/UserController.php index 8f442e3..42c160b 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Controller/UserController.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Controller/UserController.php @@ -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; + } } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.ru.yml b/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.ru.yml index 4b57053..e1e9d66 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.ru.yml +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.ru.yml @@ -33,4 +33,5 @@ No log data found: Лог отсутствует # Топ пользователей Top users: Популярные пользователи -Subscribers count: Подписчиков \ No newline at end of file +Subscribers count: Подписчиков +amount: Количество \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/top.html.twig b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/top.html.twig index 6c11d28..d5ba95d 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/top.html.twig +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/top.html.twig @@ -2,25 +2,17 @@ {% block header_title %}Top @ Point Tools{% endblock %} -{% block content %} -

{{ 'Top users'|trans }}

- - - - - - - - - - - {% for user in top_users %} - - - - - - {% endfor %} - -
#{{ 'User'|trans }}{{ 'Subscribers count'|trans }}
{{ loop.index }}@{{ user.login }}{{ user.subscribersCount }}
+{% block head_js %} + {{ parent() }} + + + +{% endblock %} + +{% block content %} + + +
{% endblock %}