|  |  |  | @@ -4,9 +4,11 @@ namespace GergelyPolonkai\FrontBundle\Controller; | 
		
	
		
			
				|  |  |  |  | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 
		
	
		
			
				|  |  |  |  | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 
		
	
		
			
				|  |  |  |  | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | 
		
	
		
			
				|  |  |  |  | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | 
		
	
		
			
				|  |  |  |  | use Doctrine\ORM\Tools\Pagination\Paginator; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | use GergelyPolonkai\FrontBundle\Entity\Post; | 
		
	
		
			
				|  |  |  |  | use GergelyPolonkai\FrontBundle\Entity\Tag; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | /** | 
		
	
		
			
				|  |  |  |  |  * Description of BlogController | 
		
	
	
		
			
				
					
					|  |  |  | @@ -17,6 +19,9 @@ use GergelyPolonkai\FrontBundle\Entity\Post; | 
		
	
		
			
				|  |  |  |  |  */ | 
		
	
		
			
				|  |  |  |  | class BlogController extends Controller | 
		
	
		
			
				|  |  |  |  | { | 
		
	
		
			
				|  |  |  |  |     // TODO: Make this a config parameter | 
		
	
		
			
				|  |  |  |  |     private $postsPerPage = 10; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |     /** | 
		
	
		
			
				|  |  |  |  |      * @Route("/", name="GergelyPolonkaiFrontBundle_blogListing") | 
		
	
		
			
				|  |  |  |  |      * @Route("/page/{cPage}", name="GergelyPolonkaiFrontBundle_blogListingPage", requirements={"cPage": "\d+"}) | 
		
	
	
		
			
				
					
					|  |  |  | @@ -24,16 +29,14 @@ class BlogController extends Controller | 
		
	
		
			
				|  |  |  |  |      */ | 
		
	
		
			
				|  |  |  |  |     public function listAction($cPage = 1) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         // TODO: Make this a config parameter | 
		
	
		
			
				|  |  |  |  |         $postsPerPage = 10; | 
		
	
		
			
				|  |  |  |  |         --$cPage; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |         $query = $this | 
		
	
		
			
				|  |  |  |  |                 ->getDoctrine() | 
		
	
		
			
				|  |  |  |  |                 ->getEntityManager() | 
		
	
		
			
				|  |  |  |  |                 ->createQuery("SELECT p FROM GergelyPolonkaiFrontBundle:Post p WHERE p.draft = FALSE ORDER BY p.createdAt DESC") | 
		
	
		
			
				|  |  |  |  |                 ->setFirstResult($cPage * $postsPerPage) | 
		
	
		
			
				|  |  |  |  |                 ->setMaxResults($postsPerPage); | 
		
	
		
			
				|  |  |  |  |                 ->setFirstResult($cPage * $this->postsPerPage) | 
		
	
		
			
				|  |  |  |  |                 ->setMaxResults($this->postsPerPage); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |         $paginator = new Paginator($query, $fetchJoinCollection = true); | 
		
	
		
			
				|  |  |  |  |         $tagManager = $this->get('fpn_tag.tag_manager'); | 
		
	
	
		
			
				
					
					|  |  |  | @@ -42,13 +45,13 @@ class BlogController extends Controller | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |         $count = $paginator->count(); | 
		
	
		
			
				|  |  |  |  |         $pageCount = ceil($count / $postsPerPage); | 
		
	
		
			
				|  |  |  |  |         $pageCount = ceil($count / $this->postsPerPage); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |         return array( | 
		
	
		
			
				|  |  |  |  |             'cpage'   => $cPage, | 
		
	
		
			
				|  |  |  |  |             'count'   => $pageCount, | 
		
	
		
			
				|  |  |  |  |             'posts'   => $paginator, | 
		
	
		
			
				|  |  |  |  |             'perPage' => $postsPerPage, | 
		
	
		
			
				|  |  |  |  |             'perPage' => $this->postsPerPage, | 
		
	
		
			
				|  |  |  |  |         ); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
	
		
			
				
					
					|  |  |  | @@ -93,4 +96,43 @@ class BlogController extends Controller | 
		
	
		
			
				|  |  |  |  |             'posts' => $posts, | 
		
	
		
			
				|  |  |  |  |         ); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |     /** | 
		
	
		
			
				|  |  |  |  |      * @Route("/tag/{name}/", name="GergelyPolonkaiFrontBundle_blogTagList") | 
		
	
		
			
				|  |  |  |  |      * @Route("/tag/{name}/page/{cPage}", name="GergelyPolonkaiFrontBundle_blogListingPage", requirements={"cPage": "\d+"}) | 
		
	
		
			
				|  |  |  |  |      * @Template("GergelyPolonkaiFrontBundle:Blog:list.html.twig") | 
		
	
		
			
				|  |  |  |  |      * @ParamConverter("tag") | 
		
	
		
			
				|  |  |  |  |      */ | 
		
	
		
			
				|  |  |  |  |     public function tagListAction(Tag $tag, $cPage = 1) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         $tagRepository = $this->getDoctrine()->getRepository('GergelyPolonkaiFrontBundle:Tag'); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |         $ids = $tagRepository->getResourceIdsForTag('gergelypolonkaifront_post', $tag->getName()); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |         --$cPage; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |         $query = $this | 
		
	
		
			
				|  |  |  |  |                     ->getDoctrine() | 
		
	
		
			
				|  |  |  |  |                     ->getEntityManager() | 
		
	
		
			
				|  |  |  |  |                     ->createQuery("SELECT p FROM GergelyPolonkaiFrontBundle:Post p WHERE p.draft = FALSE AND p.id IN (:idList) ORDER BY p.createdAt DESC") | 
		
	
		
			
				|  |  |  |  |                     ->setParameter('idList', $ids) | 
		
	
		
			
				|  |  |  |  |                     ->setFirstResult($cPage * $this->postsPerPage) | 
		
	
		
			
				|  |  |  |  |                     ->setMaxResults($this->postsPerPage); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |         $paginator = new Paginator($query, $fetchJoinCollection = true); | 
		
	
		
			
				|  |  |  |  |         $tagManager = $this->get('fpn_tag.tag_manager'); | 
		
	
		
			
				|  |  |  |  |         foreach ($paginator as $post) { | 
		
	
		
			
				|  |  |  |  |             $tagManager->loadTagging($post); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |         $count = $paginator->count(); | 
		
	
		
			
				|  |  |  |  |         $pageCount = ceil($count / $this->postsPerPage); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |         return array( | 
		
	
		
			
				|  |  |  |  |             'cpage'   => $cPage, | 
		
	
		
			
				|  |  |  |  |             'count'   => $pageCount, | 
		
	
		
			
				|  |  |  |  |             'posts'   => $paginator, | 
		
	
		
			
				|  |  |  |  |             'perPage' => $this->postsPerPage, | 
		
	
		
			
				|  |  |  |  |         ); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | } | 
		
	
	
		
			
				
					
					| 
							
							
							
						 |  |  |   |