Merged in feature_subscriptions_log_pagination (pull request #10)

Feature pagination
This commit is contained in:
Alexey Eschenko 2016-12-11 02:56:30 +03:00
commit 5671092c81
12 changed files with 251 additions and 133 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

@ -5,16 +5,25 @@ namespace Skobkin\Bundle\PointToolsBundle\Controller;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class EventsController extends Controller class EventsController extends Controller
{ {
public function lastAction() public function lastAction(Request $request)
{ {
/** @var EntityManager $em */ /** @var EntityManager $em */
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$paginator = $this->get('knp_paginator');
$eventsPagination = $paginator->paginate(
$em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->createLastSubscriptionEventsQuery(),
$request->query->getInt('page', 1),
20
);
return $this->render('SkobkinPointToolsBundle:Events:last.html.twig', [ return $this->render('SkobkinPointToolsBundle:Events:last.html.twig', [
'last_events' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getLastSubscriptionEvents(20), 'last_events' => $eventsPagination,
]); ]);
} }
} }

View file

@ -43,7 +43,6 @@ class MainController extends Controller
'subscribers_count' => $em->getRepository('SkobkinPointToolsBundle:Subscription')->getUserSubscribersCountById($this->container->getParameter('point_id')), 'subscribers_count' => $em->getRepository('SkobkinPointToolsBundle:Subscription')->getUserSubscribersCountById($this->container->getParameter('point_id')),
'events_count' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getLastDayEventsCount(), 'events_count' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getLastDayEventsCount(),
'service_login' => $this->container->getParameter('point_login'), 'service_login' => $this->container->getParameter('point_login'),
'last_events' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getLastSubscriptionEvents(10),
]); ]);
} }

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,34 +43,24 @@ 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()
; ;
} }
/** /**
* Get last $limit subscriptions * Get last subscriptions QueryBuilder for pagination
* *
* @param integer $limit * @return QueryBuilder
* @return SubscriptionEvent[]
*/ */
public function getLastSubscriptionEvents($limit) public function createLastSubscriptionEventsQuery()
{ {
if (!is_int($limit)) {
throw new \InvalidArgumentException('$limit must be an integer');
}
$qb = $this->createQueryBuilder('se'); $qb = $this->createQueryBuilder('se');
return $qb return $qb
->select() ->select(['se', 'a', 's'])
->innerJoin('se.author', 'a')
->innerJoin('se.subscriber', 's')
->orderBy('se.date', 'desc') ->orderBy('se.date', 'desc')
->setMaxResults($limit)
->getQuery()
->setFetchMode('SkobkinPointToolsBundle:SubscriptionEvent', 'author', ClassMetadata::FETCH_EAGER)
->setFetchMode('SkobkinPointToolsBundle:SubscriptionEvent', 'subscriber', ClassMetadata::FETCH_EAGER)
->getResult()
; ;
} }
} }

View file

@ -1,11 +0,0 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>Symfony2 is great</source>
<target>J'aime Symfony2</target>
</trans-unit>
</body>
</file>
</xliff>

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

@ -4,17 +4,8 @@
{# TODO classes #} {# TODO classes #}
<div class="last-subscriptions-log"> <div class="last-subscriptions-log">
{% if last_events|length > 0 %} {% if last_events|length > 0 %}
<div class="panel-group" id="accordion-log"> <h3>{{ 'Last events'|trans }}</h3>
<div class="panel panel-default">
<div class="panel-heading" id="heading-subscriptions-log">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion-log" aria-expanded="true" href="#collapse-log">
<span class="glyphicon glyphicon-collapse-down"></span> {{ 'Last events'|trans }}
</a>
</h4>
</div>
<div id="collapse-log" class="panel-collapse collapse in" aria-labelledby="heading-subscriptions-log">
<div class="panel-body">
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
@ -44,12 +35,12 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
</div>
</div>
</div>
</div>
{% else %} {% else %}
<div class="alert alert-warning" role="alert">{{ 'No 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(last_events) }}
</div>
{% endblock %} {% endblock %}

View file

@ -79,18 +79,9 @@
</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">
<div class="panel panel-default">
<div class="panel-heading" id="heading-subscriptions-log">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion-log" aria-expanded="true" href="#collapse-log">
<span class="glyphicon glyphicon-collapse-down"></span> {{ 'Subscriptions log'|trans }}
</a>
</h4>
</div>
<div id="collapse-log" class="panel-collapse collapse in" aria-labelledby="heading-subscriptions-log">
<div class="panel-body">
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
@ -116,13 +107,13 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </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 %}