mirror of
https://github.com/wallabag/wallabag.git
synced 2024-06-02 13:29:22 +00:00
41 lines
1 KiB
PHP
41 lines
1 KiB
PHP
<?php
|
|
|
|
namespace Wallabag\CoreBundle\Helper;
|
|
|
|
use Pagerfanta\Adapter\AdapterInterface;
|
|
use Pagerfanta\Pagerfanta;
|
|
use Symfony\Component\Routing\Router;
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
|
|
|
class PreparePagerForEntries
|
|
{
|
|
private $router;
|
|
private $tokenStorage;
|
|
|
|
public function __construct(TokenStorageInterface $tokenStorage, Router $router)
|
|
{
|
|
$this->tokenStorage = $tokenStorage;
|
|
$this->router = $router;
|
|
}
|
|
|
|
/**
|
|
* @param AdapterInterface $adapter
|
|
* @param int $page
|
|
*
|
|
* @return null|Pagerfanta
|
|
*/
|
|
public function prepare(AdapterInterface $adapter, $page = 1)
|
|
{
|
|
$user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
|
|
|
|
if (null === $user || !is_object($user)) {
|
|
return null;
|
|
}
|
|
|
|
$entries = new Pagerfanta($adapter);
|
|
$entries->setMaxPerPage($user->getConfig()->getItemsPerPage());
|
|
|
|
return $entries;
|
|
}
|
|
}
|