File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed
Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change 2525 *
2626 * @author Ryan Weaver <weaverryan@gmail.com>
2727 * @author Javier Eguiluz <javier.eguiluz@gmail.com>
28+ * @author Yonel Ceruto <yonelceruto@gmail.com>
2829 */
2930class PostRepository extends EntityRepository
3031{
3132 /**
32- * @return Query
33+ * @param int $page
34+ *
35+ * @return Pagerfanta
3336 */
34- public function queryLatest ( )
37+ public function findLatest ( $ page = 1 )
3538 {
36- return $ this ->getEntityManager ()
39+ $ query = $ this ->getEntityManager ()
3740 ->createQuery ('
38- SELECT p
41+ SELECT p, t
3942 FROM AppBundle:Post p
43+ LEFT JOIN p.tags t
4044 WHERE p.publishedAt <= :now
4145 ORDER BY p.publishedAt DESC
4246 ' )
4347 ->setParameter ('now ' , new \DateTime ())
4448 ;
49+
50+ return $ this ->createPaginator ($ query , $ page );
4551 }
4652
47- /**
48- * @param int $page
49- *
50- * @return Pagerfanta
51- */
52- public function findLatest ($ page = 1 )
53+ private function createPaginator (Query $ query , $ page )
5354 {
54- $ paginator = new Pagerfanta (new DoctrineORMAdapter ($ this -> queryLatest (), false ));
55+ $ paginator = new Pagerfanta (new DoctrineORMAdapter ($ query ));
5556 $ paginator ->setMaxPerPage (Post::NUM_ITEMS );
5657 $ paginator ->setCurrentPage ($ page );
5758
You can’t perform that action at this time.
0 commit comments