diff --git a/app/AppKernel.php b/app/AppKernel.php index 066ebaf..4fc2eb2 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -21,6 +21,7 @@ class AppKernel extends Kernel new Misd\GuzzleBundle\MisdGuzzleBundle(), new Ob\HighchartsBundle\ObHighchartsBundle(), new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(), + new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(), new Skobkin\Bundle\PointToolsBundle\SkobkinPointToolsBundle(), ); diff --git a/app/config/config.yml b/app/config/config.yml index cafefe9..81b601e 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -86,3 +86,7 @@ swiftmailer: knp_markdown: parser: service: markdown.parser.point + +knp_paginator: + template: + pagination: KnpPaginatorBundle:Pagination:twitter_bootstrap_v3_pagination.html.twig \ No newline at end of file diff --git a/composer.json b/composer.json index e7ff2e8..36f8885 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ "ob/highcharts-bundle": "^1.2", "doctrine/doctrine-migrations-bundle": "^1.0", "jms/serializer-bundle": "^1.1", - "knplabs/knp-markdown-bundle": "^1.4" + "knplabs/knp-markdown-bundle": "^1.4", + "knplabs/knp-paginator-bundle": "^2.5" }, "require-dev": { "sensio/generator-bundle": "~2.3", diff --git a/composer.lock b/composer.lock index b8c3905..9afffc3 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" ], - "content-hash": "15efa608e772ff5c6381daec33cf9114", + "content-hash": "730ff4da78d65c53b95f3a273c73c89b", "packages": [ { "name": "doctrine/annotations", @@ -1319,6 +1319,77 @@ ], "time": "2015-11-10T12:26:42+00:00" }, + { + "name": "knplabs/knp-components", + "version": "1.3.4", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/knp-components.git", + "reference": "f98bcc6d348fbe863a224b468e11fb5e91e28f2a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/knp-components/zipball/f98bcc6d348fbe863a224b468e11fb5e91e28f2a", + "reference": "f98bcc6d348fbe863a224b468e11fb5e91e28f2a", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "doctrine/mongodb-odm": "~1.0@beta", + "doctrine/orm": "~2.4", + "doctrine/phpcr-odm": "~1.2", + "jackalope/jackalope-doctrine-dbal": "~1.2", + "phpunit/phpunit": "~4.2", + "ruflin/elastica": "~1.0", + "symfony/event-dispatcher": "~2.5" + }, + "suggest": { + "doctrine/common": "to allow usage pagination with Doctrine ArrayCollection", + "doctrine/mongodb-odm": "to allow usage pagination with Doctrine ODM MongoDB", + "doctrine/orm": "to allow usage pagination with Doctrine ORM", + "doctrine/phpcr-odm": "to allow usage pagination with Doctrine ODM PHPCR", + "propel/propel1": "to allow usage pagination with Propel ORM", + "ruflin/Elastica": "to allow usage pagination with ElasticSearch Client", + "solarium/solarium": "to allow usage pagination with Solarium Client" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Knp\\Component": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "KnpLabs Team", + "homepage": "http://knplabs.com" + }, + { + "name": "Symfony Community", + "homepage": "http://github.com/KnpLabs/knp-components/contributors" + } + ], + "description": "Knplabs component library", + "homepage": "http://github.com/KnpLabs/knp-components", + "keywords": [ + "components", + "knp", + "knplabs", + "pager", + "paginator" + ], + "time": "2016-12-06T18:10:24+00:00" + }, { "name": "knplabs/knp-markdown-bundle", "version": "1.4.2", @@ -1380,6 +1451,67 @@ ], "time": "2015-12-15T20:41:45+00:00" }, + { + "name": "knplabs/knp-paginator-bundle", + "version": "2.5.3", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/KnpPaginatorBundle.git", + "reference": "c988761005504007c6c87d6a557641281194a0e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/KnpPaginatorBundle/zipball/c988761005504007c6c87d6a557641281194a0e5", + "reference": "c988761005504007c6c87d6a557641281194a0e5", + "shasum": "" + }, + "require": { + "knplabs/knp-components": "~1.2", + "php": ">=5.3.3", + "symfony/framework-bundle": "~2.3|~3.0", + "twig/twig": "~1.12|~2" + }, + "require-dev": { + "symfony/expression-language": "~2.4|~3.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.5.x-dev" + } + }, + "autoload": { + "psr-4": { + "Knp\\Bundle\\PaginatorBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "KnpLabs Team", + "homepage": "http://knplabs.com" + }, + { + "name": "Symfony2 Community", + "homepage": "http://github.com/KnpLabs/KnpPaginatorBundle/contributors" + } + ], + "description": "Paginator bundle for Symfony2 to automate pagination and simplify sorting and other features", + "homepage": "http://github.com/KnpLabs/KnpPaginatorBundle", + "keywords": [ + "Symfony2", + "bundle", + "knp", + "knplabs", + "pager", + "pagination", + "paginator" + ], + "time": "2016-04-20T11:40:30+00:00" + }, { "name": "kriswallsmith/assetic", "version": "v1.3.0", diff --git a/src/Skobkin/Bundle/PointToolsBundle/Controller/UserController.php b/src/Skobkin/Bundle/PointToolsBundle/Controller/UserController.php index b1af69b..76412ec 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Controller/UserController.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Controller/UserController.php @@ -15,7 +15,7 @@ class UserController extends Controller /** * @param string $login */ - public function showAction($login) + public function showAction(Request $request, $login) { /** @var EntityManager $em */ $em = $this->getDoctrine()->getManager(); @@ -27,12 +27,20 @@ class UserController extends Controller throw $this->createNotFoundException('User ' . $login . ' not found.'); } + $paginator = $this->get('knp_paginator'); + + $subscriberEventsPagination = $paginator->paginate( + $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->createUserLastSubscribersEventsQuery($user), + $request->query->getInt('page', 1), + 10 + ); + $userApi = $this->container->get('skobkin_point_tools.api_user'); return $this->render('SkobkinPointToolsBundle:User:show.html.twig', [ 'user' => $user, 'subscribers' => $em->getRepository('SkobkinPointToolsBundle:User')->findUserSubscribersById($user->getId()), - 'subscriptions_log' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getUserLastSubscribersEventsById($user, 10), + 'subscriptions_log' => $subscriberEventsPagination, 'rename_log' => $em->getRepository('SkobkinPointToolsBundle:UserRenameEvent')->findBy(['user' => $user], ['date' => 'DESC'], 10), 'avatar_url' => $userApi->getAvatarUrl($user, UserApi::AVATAR_SIZE_LARGE), ]); diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionEventRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionEventRepository.php index 7f88194..e3af769 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionEventRepository.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionEventRepository.php @@ -4,6 +4,7 @@ namespace Skobkin\Bundle\PointToolsBundle\Repository; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\QueryBuilder; use Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent; use Skobkin\Bundle\PointToolsBundle\Entity\User; @@ -27,16 +28,14 @@ class SubscriptionEventRepository extends EntityRepository } /** + * Creates QueryBuilder object for pagination of user subscribers events + * * @param User $user - * @param integer $limit - * @return SubscriptionEvent[] + * + * @return QueryBuilder */ - public function getUserLastSubscribersEventsById(User $user, $limit) + public function createUserLastSubscribersEventsQuery(User $user) { - if (!is_int($limit)) { - throw new \InvalidArgumentException('$limit must be an integer'); - } - $qb = $this->createQueryBuilder('se'); return $qb @@ -44,9 +43,7 @@ class SubscriptionEventRepository extends EntityRepository ->join('se.subscriber', 's') ->where('se.author = :author') ->orderBy('se.date', 'desc') - ->setMaxResults($limit) - ->setParameter('author', $user) - ->getQuery()->getResult() + ->setParameter('author', $user->getId()) ; } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.ru.yml b/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.ru.yml index 7a5f564..fcd8cad 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.ru.yml +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.ru.yml @@ -1,16 +1,20 @@ # Russian language for Point tools -# Шапка +# Header Toggle navigation: Переключить навигацию Main: Главная Top: Топ Report a bug: Сообщить об ошибке Last: Последнее -# Подвал +# Footer Source code: Исходный код -# Главная +# Pagination +Previous: Предыдущая +Next: Следующая + +# Index page All users: Всего пользователей Subscribed users: Подписчиков сервиса 24 hours events: Событий за сутки @@ -21,7 +25,7 @@ Last events: Последние события Username: Имя пользователя Search: Поиск -# Страница пользователя +# User page Subscribers: Подписчики Subscriptions log: Лог подписок User: Пользователь @@ -35,10 +39,10 @@ No subscribers data found: Информация о подписчиках отс No rename log data found: Лог переименований отсутствует No subscribers log data found: Лог подписчиков отсутствует -# Страница поста +# Post page in response to: в ответ на -# Топ пользователей +# Top page Top users: Популярные пользователи Subscribers count: Подписчиков amount: Количество \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/show.html.twig b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/show.html.twig index 038b949..1d44924 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/show.html.twig +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/show.html.twig @@ -79,50 +79,41 @@
+

{{ 'Subscriptions log'|trans }}

+ {% if subscriptions_log|length > 0 %} -
-
- -
-
- - - - - - - - - - {% for event in subscriptions_log %} - - - - - - {% endfor %} - -
{{ 'User'|trans }}{{ 'Action'|trans }}{{ 'Date'|trans }}
- @{{ event.subscriber.login }} - - - - {# @todo Use DateTime helper: https://sonata-project.org/bundles/intl/master/doc/reference/datetime.html #} - {{ event.date|date('d F Y H:i:s') }} -
-
-
-
-
+ + + + + + + + + + {% for event in subscriptions_log %} + + + + + + {% endfor %} + +
{{ 'User'|trans }}{{ 'Action'|trans }}{{ 'Date'|trans }}
+ @{{ event.subscriber.login }} + + + + {# @todo Use DateTime helper: https://sonata-project.org/bundles/intl/master/doc/reference/datetime.html #} + {{ event.date|date('d F Y H:i:s') }} +
{% else %} {% endif %}
+ + {% endblock %}