From 7b6ee13585ce3ba88f8b288ed7f5c2ee1c5fc9eb Mon Sep 17 00:00:00 2001 From: "Gergely POLONKAI (W00d5t0ck)" Date: Sun, 16 Sep 2012 23:32:07 +0200 Subject: [PATCH] Added tag display functionality Signed-off-by: Gergely POLONKAI (W00d5t0ck) --- .../FrontBundle/Controller/AdminController.php | 9 +++++++++ .../FrontBundle/Controller/BlogController.php | 6 ++++++ .../FrontBundle/Controller/DefaultController.php | 5 +++++ src/GergelyPolonkai/FrontBundle/Form/PostType.php | 1 + .../Resources/views/Blog/postViewer.html.twig | 7 +++++++ 5 files changed, 28 insertions(+) diff --git a/src/GergelyPolonkai/FrontBundle/Controller/AdminController.php b/src/GergelyPolonkai/FrontBundle/Controller/AdminController.php index 9024b22..59c86d7 100644 --- a/src/GergelyPolonkai/FrontBundle/Controller/AdminController.php +++ b/src/GergelyPolonkai/FrontBundle/Controller/AdminController.php @@ -73,6 +73,12 @@ class AdminController extends Controller if ($request->getMethod() === 'POST') { $form->bind($request); if ($form->isValid()) { + if (($tags = $form->get('tags')->getData()) != '') { + $tagManager = $this->get('fpn_tag.tag_manager'); + $tagNames = $tagManager->splitTagNames($tags); + $tagList = $tagManager->loadOrCreateTags($tagNames); + $tagManager->addTags($tagList, $post); + } if ($form->get('updateDate')->getData() == 1) { $post->setCreatedAt(new \DateTime('now')); } @@ -80,10 +86,13 @@ class AdminController extends Controller $em = $this->getDoctrine()->getEntityManager(); $em->persist($post); $em->flush(); + $tagManager->saveTagging($post); return $this->redirect($this->generateUrl('GergelyPolonkaiFrontBundle_adminBlogList')); } } + $tagManager = $this->get('fpn_tag.tag_manager'); + $tagManager->loadTagging($post); return array( 'form' => $form->createView(), diff --git a/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php b/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php index 6f773a5..18114d4 100644 --- a/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php +++ b/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php @@ -36,6 +36,11 @@ class BlogController extends Controller ->setMaxResults($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 / $postsPerPage); @@ -66,6 +71,7 @@ class BlogController extends Controller $query->setParameter(':date1', $date); $query->setParameter(':date2', $date2); $post = $query->getOneOrNullResult(); + $this->get('fpn_tag.tag_manager')->loadTagging($post); return array( 'post' => $post, diff --git a/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php b/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php index 59f0967..f0d8bb1 100644 --- a/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php +++ b/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php @@ -24,6 +24,11 @@ class DefaultController extends Controller $query->setMaxResults(4); $posts = $query->getResult(); + $tagManager = $this->get('fpn_tag.tag_manager'); + foreach ($posts as $post) { + $tagManager->loadTagging($post); + } + return array( 'posts' => $posts, ); diff --git a/src/GergelyPolonkai/FrontBundle/Form/PostType.php b/src/GergelyPolonkai/FrontBundle/Form/PostType.php index 244e5ae..edae981 100644 --- a/src/GergelyPolonkai/FrontBundle/Form/PostType.php +++ b/src/GergelyPolonkai/FrontBundle/Form/PostType.php @@ -15,6 +15,7 @@ class PostType extends AbstractType ->add('draft', null, array('required' => false)) ->add('updateDate', 'checkbox', array('property_path' => false, 'required' => false, 'label' => 'Update creation date')) ->add('content', 'ckeditor') + ->add('tags', 'text', array('property_path' => false, 'required' => false, 'label' => 'Tags')) ; } diff --git a/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/postViewer.html.twig b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/postViewer.html.twig index 8f86567..5d07667 100644 --- a/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/postViewer.html.twig +++ b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/postViewer.html.twig @@ -2,4 +2,11 @@

{% if title_links %}{% endif %}{{ post.title }}{% if title_links %}{% endif %}

{{ post.content|insert_code_chunks }} +{% if post.tags|length > 0 %} + +{% endif %}