* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace AppBundle\Repository; use AppBundle\Entity\Post; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Pagerfanta; /** * FIXME CAN BE REMOVED * * This custom Doctrine repository contains some methods which are useful when * querying for blog post information. * See http://symfony.com/doc/current/book/doctrine.html#custom-repository-classes * * @author Ryan Weaver * @author Javier Eguiluz */ class PostRepository extends EntityRepository { /** * @return Query */ public function queryLatest() { return $this->getEntityManager() ->createQuery(' SELECT p FROM AppBundle:Post p WHERE p.publishedAt <= :now ORDER BY p.publishedAt DESC ') ->setParameter('now', new \DateTime()) ; } /** * @param int $page * * @return Pagerfanta */ public function findLatest($page = 1) { $paginator = new Pagerfanta(new DoctrineORMAdapter($this->queryLatest(), false)); $paginator->setMaxPerPage(Post::NUM_ITEMS); $paginator->setCurrentPage($page); return $paginator; } }