Passed
Push — master ( 5deee6...e0f7b0 )
by Julito
10:06
created

PaginationSubscriber::items()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 4
c 1
b 1
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\EventSubscriber;
6
7
use Knp\Component\Pager\Event\ItemsEvent;
8
use Knp\Component\Pager\Event\PaginationEvent;
9
use Knp\Component\Pager\Pagination\SlidingPagination;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
12
class PaginationSubscriber implements EventSubscriberInterface
13
{
14
    protected $defaultLocale;
15
    protected $parameterBag;
16
    protected $settingsManager;
17
18
    public function items(ItemsEvent $event)
19
    {
20
        if (is_array($event->target)) {
21
            $event->items = $event->target;
22
            $event->count = count($event->target);
23
            $event->stopPropagation();
24
        }
25
    }
26
27
    public function pagination(PaginationEvent $event)
28
    {
29
        if (is_array($event->target)) {
30
            $event->setPagination(new SlidingPagination);
31
        }
32
33
        $event->stopPropagation();
34
    }
35
36
    public static function getSubscribedEvents()
37
    {
38
        return [
39
            'knp_pager.items' => ['items', 1/*increased priority to override any internal*/],
40
            'knp_pager.pagination' => ['pagination', 0]
41
        ];
42
    }
43
}
44