Files
kimai2/src/AppBundle/Repository/PostRepository.php
Kevin Papst 579b962c85 first draft
2016-10-20 22:10:41 +02:00

62 lines
1.5 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <weaverryan@gmail.com>
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*/
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;
}
}