]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php
EntriesExport/epub: remove TOC page
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / PreparePagerForEntries.php
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 use Wallabag\UserBundle\Entity\User;
10
11 class PreparePagerForEntries
12 {
13 private $router;
14 private $tokenStorage;
15
16 public function __construct(TokenStorageInterface $tokenStorage, Router $router)
17 {
18 $this->tokenStorage = $tokenStorage;
19 $this->router = $router;
20 }
21
22 /**
23 * @param AdapterInterface $adapter
24 * @param User $user If user isn't logged in, we can force it (like for rss)
25 *
26 * @return null|Pagerfanta
27 */
28 public function prepare(AdapterInterface $adapter, User $user = null)
29 {
30 if (null === $user) {
31 $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
32 }
33
34 if (null === $user || !\is_object($user)) {
35 return;
36 }
37
38 $entries = new Pagerfanta($adapter);
39 $entries->setMaxPerPage($user->getConfig()->getItemsPerPage());
40
41 return $entries;
42 }
43 }