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