vendor/knplabs/knp-components/src/Knp/Component/Pager/Event/Subscriber/Paginate/PropelQuerySubscriber.php line 13

Open in your IDE?
  1. <?php
  2. namespace Knp\Component\Pager\Event\Subscriber\Paginate;
  3. use Knp\Component\Pager\Event\ItemsEvent;
  4. use Knp\Component\Pager\PaginatorInterface;
  5. use ModelCriteria;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class PropelQuerySubscriber implements EventSubscriberInterface
  8. {
  9.     public function items(ItemsEvent $event): void
  10.     {
  11.         if ($event->target instanceof ModelCriteria) {
  12.             // process count
  13.             $countQuery = clone $event->target;
  14.             $countQuery
  15.                 ->limit(0)
  16.                 ->offset(0)
  17.             ;
  18.             if ($event->options[PaginatorInterface::DISTINCT]) {
  19.                 $countQuery->distinct();
  20.             }
  21.             $event->count intval($countQuery->count());
  22.             // process items
  23.             $result null;
  24.             if ($event->count) {
  25.                 $resultQuery = clone $event->target;
  26.                 if ($event->options[PaginatorInterface::DISTINCT]) {
  27.                     $resultQuery->distinct();
  28.                 }
  29.                 $resultQuery
  30.                     ->offset($event->getOffset())
  31.                     ->limit($event->getLimit())
  32.                 ;
  33.                 $result $resultQuery->find();
  34.             } else {
  35.                 $result = []; // count is 0
  36.             }
  37.             $event->items $result;
  38.             $event->stopPropagation();
  39.         }
  40.     }
  41.     public static function getSubscribedEvents(): array
  42.     {
  43.         return [
  44.             'knp_pager.items' => ['items'0],
  45.         ];
  46.     }
  47. }