You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/* For licensing terms, see /license.txt */
|
|
|
|
namespace Chamilo\CoreBundle\EventSubscriber;
|
|
|
|
use Knp\Component\Pager\Event\ItemsEvent;
|
|
use Knp\Component\Pager\Event\PaginationEvent;
|
|
use Knp\Component\Pager\Pagination\SlidingPagination;
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|
|
|
class PaginationSubscriber implements EventSubscriberInterface
|
|
{
|
|
public function items(ItemsEvent $event): void
|
|
{
|
|
if (\is_array($event->target)) {
|
|
$event->items = $event->target;
|
|
$event->count = \count($event->target);
|
|
$event->stopPropagation();
|
|
}
|
|
}
|
|
|
|
public function pagination(PaginationEvent $event): void
|
|
{
|
|
if (\is_array($event->target)) {
|
|
$event->setPagination(new SlidingPagination());
|
|
}
|
|
|
|
$event->stopPropagation();
|
|
}
|
|
|
|
public static function getSubscribedEvents()
|
|
{
|
|
return [
|
|
'knp_pager.items' => ['items', 1/*increased priority to override any internal*/],
|
|
'knp_pager.pagination' => ['pagination', 0],
|
|
];
|
|
}
|
|
}
|
|
|