Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/AppBundle/Repository/PostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,34 @@
*
* @author Ryan Weaver <[email protected]>
* @author Javier Eguiluz <[email protected]>
* @author Yonel Ceruto <[email protected]>
*/
class PostRepository extends EntityRepository
{
/**
* @return Query
* @param int $page
*
* @return Pagerfanta
*/
public function queryLatest()
public function findLatest($page = 1)
{
return $this->getEntityManager()
$query = $this->getEntityManager()
->createQuery('
SELECT p
SELECT p, t
FROM AppBundle:Post p
LEFT JOIN p.tags t
WHERE p.publishedAt <= :now
ORDER BY p.publishedAt DESC
')
->setParameter('now', new \DateTime())
;

return $this->createPaginator($query, $page);
}

/**
* @param int $page
*
* @return Pagerfanta
*/
public function findLatest($page = 1)
private function createPaginator(Query $query, $page)
{
$paginator = new Pagerfanta(new DoctrineORMAdapter($this->queryLatest(), false));
$paginator = new Pagerfanta(new DoctrineORMAdapter($query));
$paginator->setMaxPerPage(Post::NUM_ITEMS);
$paginator->setCurrentPage($page);

Expand Down