diff --git a/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php b/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php index 18114d4..604bfe0 100644 --- a/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php +++ b/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php @@ -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, + ); + } } diff --git a/src/GergelyPolonkai/FrontBundle/Entity/Tag.php b/src/GergelyPolonkai/FrontBundle/Entity/Tag.php index ee307ca..0e9e19e 100644 --- a/src/GergelyPolonkai/FrontBundle/Entity/Tag.php +++ b/src/GergelyPolonkai/FrontBundle/Entity/Tag.php @@ -9,7 +9,7 @@ use FPN\TagBundle\Entity\Tag as BaseTag; * * @author polesz * - * @ORM\Entity + * @ORM\Entity(repositoryClass="DoctrineExtensions\Taggable\Entity\TagRepository") * @ORM\Table(name="tags") */ class Tag extends BaseTag diff --git a/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/list.html.twig b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/list.html.twig index da9c0d1..d17da7b 100644 --- a/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/list.html.twig +++ b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/list.html.twig @@ -26,6 +26,9 @@ {% block content %} {{ block('paginator') }} +{% if posts|length == 0 %} +No posts found. +{% endif %} {% for post in posts %} {% include 'GergelyPolonkaiFrontBundle:Blog:postViewer.html.twig' with {'post': post, 'title_links': true} %} {% endfor %} diff --git a/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/postViewer.html.twig b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/postViewer.html.twig index 5d07667..5e9bb11 100644 --- a/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/postViewer.html.twig +++ b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/postViewer.html.twig @@ -5,7 +5,7 @@ {% if post.tags|length > 0 %}
{% endif %}