Pagination of subscribers events on user page. KnpPaginatorBundle added.

This commit is contained in:
Alexey Skobkin 2016-12-11 02:43:25 +03:00
parent dd0707c97a
commit 65cc08d91f
8 changed files with 198 additions and 60 deletions

View file

@ -21,6 +21,7 @@ class AppKernel extends Kernel
new Misd\GuzzleBundle\MisdGuzzleBundle(), new Misd\GuzzleBundle\MisdGuzzleBundle(),
new Ob\HighchartsBundle\ObHighchartsBundle(), new Ob\HighchartsBundle\ObHighchartsBundle(),
new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(), new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
new Skobkin\Bundle\PointToolsBundle\SkobkinPointToolsBundle(), new Skobkin\Bundle\PointToolsBundle\SkobkinPointToolsBundle(),
); );

View file

@ -86,3 +86,7 @@ swiftmailer:
knp_markdown: knp_markdown:
parser: parser:
service: markdown.parser.point service: markdown.parser.point
knp_paginator:
template:
pagination: KnpPaginatorBundle:Pagination:twitter_bootstrap_v3_pagination.html.twig

View file

@ -23,7 +23,8 @@
"ob/highcharts-bundle": "^1.2", "ob/highcharts-bundle": "^1.2",
"doctrine/doctrine-migrations-bundle": "^1.0", "doctrine/doctrine-migrations-bundle": "^1.0",
"jms/serializer-bundle": "^1.1", "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": { "require-dev": {
"sensio/generator-bundle": "~2.3", "sensio/generator-bundle": "~2.3",

134
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", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "15efa608e772ff5c6381daec33cf9114", "content-hash": "730ff4da78d65c53b95f3a273c73c89b",
"packages": [ "packages": [
{ {
"name": "doctrine/annotations", "name": "doctrine/annotations",
@ -1319,6 +1319,77 @@
], ],
"time": "2015-11-10T12:26:42+00:00" "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", "name": "knplabs/knp-markdown-bundle",
"version": "1.4.2", "version": "1.4.2",
@ -1380,6 +1451,67 @@
], ],
"time": "2015-12-15T20:41:45+00:00" "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", "name": "kriswallsmith/assetic",
"version": "v1.3.0", "version": "v1.3.0",

View file

@ -15,7 +15,7 @@ class UserController extends Controller
/** /**
* @param string $login * @param string $login
*/ */
public function showAction($login) public function showAction(Request $request, $login)
{ {
/** @var EntityManager $em */ /** @var EntityManager $em */
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
@ -27,12 +27,20 @@ class UserController extends Controller
throw $this->createNotFoundException('User ' . $login . ' not found.'); 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'); $userApi = $this->container->get('skobkin_point_tools.api_user');
return $this->render('SkobkinPointToolsBundle:User:show.html.twig', [ return $this->render('SkobkinPointToolsBundle:User:show.html.twig', [
'user' => $user, 'user' => $user,
'subscribers' => $em->getRepository('SkobkinPointToolsBundle:User')->findUserSubscribersById($user->getId()), '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), 'rename_log' => $em->getRepository('SkobkinPointToolsBundle:UserRenameEvent')->findBy(['user' => $user], ['date' => 'DESC'], 10),
'avatar_url' => $userApi->getAvatarUrl($user, UserApi::AVATAR_SIZE_LARGE), 'avatar_url' => $userApi->getAvatarUrl($user, UserApi::AVATAR_SIZE_LARGE),
]); ]);

View file

@ -4,6 +4,7 @@ namespace Skobkin\Bundle\PointToolsBundle\Repository;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\QueryBuilder;
use Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent; use Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent;
use Skobkin\Bundle\PointToolsBundle\Entity\User; 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 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'); $qb = $this->createQueryBuilder('se');
return $qb return $qb
@ -44,9 +43,7 @@ class SubscriptionEventRepository extends EntityRepository
->join('se.subscriber', 's') ->join('se.subscriber', 's')
->where('se.author = :author') ->where('se.author = :author')
->orderBy('se.date', 'desc') ->orderBy('se.date', 'desc')
->setMaxResults($limit) ->setParameter('author', $user->getId())
->setParameter('author', $user)
->getQuery()->getResult()
; ;
} }

View file

@ -1,16 +1,20 @@
# Russian language for Point tools # Russian language for Point tools
# Шапка # Header
Toggle navigation: Переключить навигацию Toggle navigation: Переключить навигацию
Main: Главная Main: Главная
Top: Топ Top: Топ
Report a bug: Сообщить об ошибке Report a bug: Сообщить об ошибке
Last: Последнее Last: Последнее
# Подвал # Footer
Source code: Исходный код Source code: Исходный код
# Главная # Pagination
Previous: Предыдущая
Next: Следующая
# Index page
All users: Всего пользователей All users: Всего пользователей
Subscribed users: Подписчиков сервиса Subscribed users: Подписчиков сервиса
24 hours events: Событий за сутки 24 hours events: Событий за сутки
@ -21,7 +25,7 @@ Last events: Последние события
Username: Имя пользователя Username: Имя пользователя
Search: Поиск Search: Поиск
# Страница пользователя # User page
Subscribers: Подписчики Subscribers: Подписчики
Subscriptions log: Лог подписок Subscriptions log: Лог подписок
User: Пользователь User: Пользователь
@ -35,10 +39,10 @@ No subscribers data found: Информация о подписчиках отс
No rename log data found: Лог переименований отсутствует No rename log data found: Лог переименований отсутствует
No subscribers log data found: Лог подписчиков отсутствует No subscribers log data found: Лог подписчиков отсутствует
# Страница поста # Post page
in response to: в ответ на in response to: в ответ на
# Топ пользователей # Top page
Top users: Популярные пользователи Top users: Популярные пользователи
Subscribers count: Подписчиков Subscribers count: Подписчиков
amount: Количество amount: Количество

View file

@ -79,50 +79,41 @@
</div> </div>
<div class="user-subscriptions-log"> <div class="user-subscriptions-log">
<h3>{{ 'Subscriptions log'|trans }}</h3>
{% if subscriptions_log|length > 0 %} {% if subscriptions_log|length > 0 %}
<div class="panel-group" id="accordion-log"> <table class="table table-striped">
<div class="panel panel-default"> <thead>
<div class="panel-heading" id="heading-subscriptions-log"> <tr>
<h4 class="panel-title"> <td>{{ 'User'|trans }}</td>
<a data-toggle="collapse" data-parent="#accordion-log" aria-expanded="true" href="#collapse-log"> <td>{{ 'Action'|trans }}</td>
<span class="glyphicon glyphicon-collapse-down"></span> {{ 'Subscriptions log'|trans }} <td>{{ 'Date'|trans }}</td>
</a> </tr>
</h4> </thead>
</div> <tbody>
<div id="collapse-log" class="panel-collapse collapse in" aria-labelledby="heading-subscriptions-log"> {% for event in subscriptions_log %}
<div class="panel-body"> <tr>
<table class="table table-striped"> <td>
<thead> <a href="{{ url('user_show', {login: event.subscriber.login}) }}">@{{ event.subscriber.login }}</a>
<tr> </td>
<td>{{ 'User'|trans }}</td> <td>
<td>{{ 'Action'|trans }}</td> <span class="glyphicon {% if event.action == 'subscribe' %}glyphicon-plus{% elseif event.action == 'unsubscribe' %}glyphicon-minus{% endif %}"></span>
<td>{{ 'Date'|trans }}</td> </td>
</tr> <td>
</thead> {# @todo Use DateTime helper: https://sonata-project.org/bundles/intl/master/doc/reference/datetime.html #}
<tbody> {{ event.date|date('d F Y H:i:s') }}
{% for event in subscriptions_log %} </td>
<tr> </tr>
<td> {% endfor %}
<a href="{{ url('user_show', {login: event.subscriber.login}) }}">@{{ event.subscriber.login }}</a> </tbody>
</td> </table>
<td>
<span class="glyphicon {% if event.action == 'subscribe' %}glyphicon-plus{% elseif event.action == 'unsubscribe' %}glyphicon-minus{% endif %}"></span>
</td>
<td>
{# @todo Use DateTime helper: https://sonata-project.org/bundles/intl/master/doc/reference/datetime.html #}
{{ event.date|date('d F Y H:i:s') }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% else %} {% else %}
<div class="alert alert-warning" role="alert">{{ 'No subscribers log data found'|trans }}</div> <div class="alert alert-warning" role="alert">{{ 'No subscribers log data found'|trans }}</div>
{% endif %} {% endif %}
</div> </div>
<div class="navigation">
{{ knp_pagination_render(subscriptions_log) }}
</div>
{% endblock %} {% endblock %}