]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Helper; | |
4 | ||
5 | use Pagerfanta\Adapter\AdapterInterface; | |
6 | use Pagerfanta\Pagerfanta; | |
7 | use Symfony\Component\Routing\Router; | |
8 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | |
9 | ||
10 | class PreparePagerForEntries | |
11 | { | |
12 | private $router; | |
13 | private $tokenStorage; | |
14 | ||
15 | public function __construct(TokenStorageInterface $tokenStorage, Router $router) | |
16 | { | |
17 | $this->tokenStorage = $tokenStorage; | |
18 | $this->router = $router; | |
19 | } | |
20 | ||
21 | /** | |
22 | * @param AdapterInterface $adapter | |
23 | * | |
24 | * @return null|Pagerfanta | |
25 | */ | |
26 | public function prepare(AdapterInterface $adapter) | |
27 | { | |
28 | $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; | |
29 | ||
30 | if (null === $user || !is_object($user)) { | |
31 | return; | |
32 | } | |
33 | ||
34 | $entries = new Pagerfanta($adapter); | |
35 | $entries->setMaxPerPage($user->getConfig()->getItemsPerPage()); | |
36 | ||
37 | return $entries; | |
38 | } | |
39 | } |