]>
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; |
f808b016 | 9 | use Wallabag\UserBundle\Entity\User; |
891456ba NL |
10 | |
11 | class PreparePagerForEntries | |
12 | { | |
891456ba | 13 | private $router; |
2fe2e411 | 14 | private $tokenStorage; |
891456ba | 15 | |
2fe2e411 | 16 | public function __construct(TokenStorageInterface $tokenStorage, Router $router) |
891456ba | 17 | { |
2fe2e411 | 18 | $this->tokenStorage = $tokenStorage; |
891456ba NL |
19 | $this->router = $router; |
20 | } | |
21 | ||
22 | /** | |
23 | * @param AdapterInterface $adapter | |
18c38dff | 24 | * @param User $user If user isn't logged in, we can force it (like for rss) |
891456ba NL |
25 | * |
26 | * @return null|Pagerfanta | |
27 | */ | |
18c38dff | 28 | public function prepare(AdapterInterface $adapter, User $user = null) |
891456ba | 29 | { |
18c38dff JB |
30 | if (null === $user) { |
31 | $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; | |
32 | } | |
2fe2e411 | 33 | |
2a1ceb67 | 34 | if (null === $user || !\is_object($user)) { |
53da8ad8 | 35 | return; |
2fe2e411 NL |
36 | } |
37 | ||
891456ba | 38 | $entries = new Pagerfanta($adapter); |
2fe2e411 | 39 | $entries->setMaxPerPage($user->getConfig()->getItemsPerPage()); |
891456ba NL |
40 | |
41 | return $entries; | |
42 | } | |
43 | } |