diff --git a/src/Skobkin/Bundle/PointToolsBundle/Controller/EventsController.php b/src/Skobkin/Bundle/PointToolsBundle/Controller/EventsController.php index 1eab3e7..ca740d2 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Controller/EventsController.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Controller/EventsController.php @@ -5,16 +5,25 @@ namespace Skobkin\Bundle\PointToolsBundle\Controller; use Doctrine\ORM\EntityManager; use Doctrine\ORM\QueryBuilder; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\HttpFoundation\Request; class EventsController extends Controller { - public function lastAction() + public function lastAction(Request $request) { /** @var EntityManager $em */ $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', [ - 'last_events' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getLastSubscriptionEvents(20), + 'last_events' => $eventsPagination, ]); } } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Controller/MainController.php b/src/Skobkin/Bundle/PointToolsBundle/Controller/MainController.php index ed4e72f..4197fec 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Controller/MainController.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Controller/MainController.php @@ -43,7 +43,6 @@ class MainController extends Controller 'subscribers_count' => $em->getRepository('SkobkinPointToolsBundle:Subscription')->getUserSubscribersCountById($this->container->getParameter('point_id')), 'events_count' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getLastDayEventsCount(), 'service_login' => $this->container->getParameter('point_login'), - 'last_events' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getLastSubscriptionEvents(10), ]); } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionEventRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionEventRepository.php index e3af769..0e69548 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionEventRepository.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionEventRepository.php @@ -48,27 +48,19 @@ class SubscriptionEventRepository extends EntityRepository } /** - * Get last $limit subscriptions + * Get last subscriptions QueryBuilder for pagination * - * @param integer $limit - * @return SubscriptionEvent[] + * @return QueryBuilder */ - public function getLastSubscriptionEvents($limit) + public function createLastSubscriptionEventsQuery() { - if (!is_int($limit)) { - throw new \InvalidArgumentException('$limit must be an integer'); - } - $qb = $this->createQueryBuilder('se'); return $qb - ->select() + ->select(['se', 'a', 's']) + ->innerJoin('se.author', 'a') + ->innerJoin('se.subscriber', 's') ->orderBy('se.date', 'desc') - ->setMaxResults($limit) - ->getQuery() - ->setFetchMode('SkobkinPointToolsBundle:SubscriptionEvent', 'author', ClassMetadata::FETCH_EAGER) - ->setFetchMode('SkobkinPointToolsBundle:SubscriptionEvent', 'subscriber', ClassMetadata::FETCH_EAGER) - ->getResult() ; } } \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.fr.xlf b/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.fr.xlf deleted file mode 100644 index fd59e6c..0000000 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.fr.xlf +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - Symfony2 is great - J'aime Symfony2 - - - - diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/Events/last.html.twig b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/Events/last.html.twig index 8ab37a6..e9bedeb 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/Events/last.html.twig +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/Events/last.html.twig @@ -4,52 +4,43 @@ {# TODO classes #}
{% if last_events|length > 0 %} -
-
- -
-
- - - - - - - - - - - {% for event in last_events %} - - - - - - - {% endfor %} - -
{{ 'Subscriber'|trans }}{{ 'Author'|trans }}{{ 'Action'|trans }}{{ 'Date'|trans }}
- @{{ event.subscriber.login }} - - @{{ event.author.login }} - - - - {# Use DateTime helper: https://sonata-project.org/bundles/intl/master/doc/reference/datetime.html #} - {{ event.date|date('d F Y H:i:s') }} -
-
-
-
-
+

{{ 'Last events'|trans }}

+ + + + + + + + + + + + {% for event in last_events %} + + + + + + + {% endfor %} + +
{{ 'Subscriber'|trans }}{{ 'Author'|trans }}{{ 'Action'|trans }}{{ 'Date'|trans }}
+ @{{ event.subscriber.login }} + + @{{ event.author.login }} + + + + {# 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 %}