Pagination of last events.
This commit is contained in:
parent
65cc08d91f
commit
74b39d7918
|
@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -4,17 +4,8 @@
|
|||
{# TODO classes #}
|
||||
<div class="last-subscriptions-log">
|
||||
{% if last_events|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> {{ 'Last events'|trans }}
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="collapse-log" class="panel-collapse collapse in" aria-labelledby="heading-subscriptions-log">
|
||||
<div class="panel-body">
|
||||
<h3>{{ 'Last events'|trans }}</h3>
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -44,12 +35,12 @@
|
|||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% 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 %}
|
||||
</div>
|
||||
|
||||
<div class="navigation">
|
||||
{{ knp_pagination_render(last_events) }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue