53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Deblan\Bundle\BlogBundle\Page;
|
|
|
|
use Trinity\Bundle\ContentManagerBundle\Model\Page;
|
|
use Trinity\Bundle\ContentManagerBundle\Model\PageableInterface;
|
|
use Pagerfanta\Adapter\PropelAdapter;
|
|
use Pagerfanta\Exception\NotValidCurrentPageException;
|
|
use Pagerfanta\Pagerfanta as Pager;
|
|
use Deblan\Bundle\BlogBundle\Model\TinyPostQuery;
|
|
|
|
class TinyPage extends Page implements PageableInterface
|
|
{
|
|
public function __construct($template = 'DeblanBlogBundle:Default:tiny.html.twig')
|
|
{
|
|
parent::__construct($template);
|
|
}
|
|
|
|
public function initPager()
|
|
{
|
|
$this->pager = new Pager(new PropelAdapter($this->getQuery()));
|
|
$this->pager->setMaxPerPage(10);
|
|
}
|
|
|
|
public function getPager()
|
|
{
|
|
return $this->pager;
|
|
}
|
|
|
|
public function getQuery()
|
|
{
|
|
return $this->query = TinyPostQuery::create()
|
|
->orderByUpdated(\Criteria::DESC)
|
|
->useTinyUserEntriesPostQuery()
|
|
->filterByMarked(true)
|
|
->endUse();
|
|
}
|
|
|
|
public function setQuery($query)
|
|
{
|
|
$this->query = $query;
|
|
}
|
|
|
|
public function setPage($page)
|
|
{
|
|
try {
|
|
$this->getPager()->setCurrentPage($page, false, true);
|
|
} catch (NotValidCurrentPageException $e) {
|
|
$this->getPager()->setCurrentPage(1, false, true);
|
|
}
|
|
}
|
|
}
|