Added tag display functionality

Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Gergely POLONKAI (W00d5t0ck) 2012-09-16 23:32:07 +02:00
parent 507a8a5721
commit 7b6ee13585
5 changed files with 28 additions and 0 deletions

View File

@ -73,6 +73,12 @@ class AdminController extends Controller
if ($request->getMethod() === 'POST') { if ($request->getMethod() === 'POST') {
$form->bind($request); $form->bind($request);
if ($form->isValid()) { 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) { if ($form->get('updateDate')->getData() == 1) {
$post->setCreatedAt(new \DateTime('now')); $post->setCreatedAt(new \DateTime('now'));
} }
@ -80,10 +86,13 @@ class AdminController extends Controller
$em = $this->getDoctrine()->getEntityManager(); $em = $this->getDoctrine()->getEntityManager();
$em->persist($post); $em->persist($post);
$em->flush(); $em->flush();
$tagManager->saveTagging($post);
return $this->redirect($this->generateUrl('GergelyPolonkaiFrontBundle_adminBlogList')); return $this->redirect($this->generateUrl('GergelyPolonkaiFrontBundle_adminBlogList'));
} }
} }
$tagManager = $this->get('fpn_tag.tag_manager');
$tagManager->loadTagging($post);
return array( return array(
'form' => $form->createView(), 'form' => $form->createView(),

View File

@ -36,6 +36,11 @@ class BlogController extends Controller
->setMaxResults($postsPerPage); ->setMaxResults($postsPerPage);
$paginator = new Paginator($query, $fetchJoinCollection = true); $paginator = new Paginator($query, $fetchJoinCollection = true);
$tagManager = $this->get('fpn_tag.tag_manager');
foreach ($paginator as $post) {
$tagManager->loadTagging($post);
}
$count = $paginator->count(); $count = $paginator->count();
$pageCount = ceil($count / $postsPerPage); $pageCount = ceil($count / $postsPerPage);
@ -66,6 +71,7 @@ class BlogController extends Controller
$query->setParameter(':date1', $date); $query->setParameter(':date1', $date);
$query->setParameter(':date2', $date2); $query->setParameter(':date2', $date2);
$post = $query->getOneOrNullResult(); $post = $query->getOneOrNullResult();
$this->get('fpn_tag.tag_manager')->loadTagging($post);
return array( return array(
'post' => $post, 'post' => $post,

View File

@ -24,6 +24,11 @@ class DefaultController extends Controller
$query->setMaxResults(4); $query->setMaxResults(4);
$posts = $query->getResult(); $posts = $query->getResult();
$tagManager = $this->get('fpn_tag.tag_manager');
foreach ($posts as $post) {
$tagManager->loadTagging($post);
}
return array( return array(
'posts' => $posts, 'posts' => $posts,
); );

View File

@ -15,6 +15,7 @@ class PostType extends AbstractType
->add('draft', null, array('required' => false)) ->add('draft', null, array('required' => false))
->add('updateDate', 'checkbox', array('property_path' => false, 'required' => false, 'label' => 'Update creation date')) ->add('updateDate', 'checkbox', array('property_path' => false, 'required' => false, 'label' => 'Update creation date'))
->add('content', 'ckeditor') ->add('content', 'ckeditor')
->add('tags', 'text', array('property_path' => false, 'required' => false, 'label' => 'Tags'))
; ;
} }

View File

@ -2,4 +2,11 @@
<h3>{% if title_links %}<a href="{{ path('GergelyPolonkaiFrontBundle_blogViewPost', {year: post.createdAt|date('Y'), month: post.createdAt|date('m'), day: post.createdAt|date('d'), slug: post.slug}) }}">{% endif %}{{ post.title }}{% if title_links %}</a>{% endif %}</h3> <h3>{% if title_links %}<a href="{{ path('GergelyPolonkaiFrontBundle_blogViewPost', {year: post.createdAt|date('Y'), month: post.createdAt|date('m'), day: post.createdAt|date('d'), slug: post.slug}) }}">{% endif %}{{ post.title }}{% if title_links %}</a>{% endif %}</h3>
<p class="article-date">{{ post.createdAt|date('m-d-Y :: H:i') }} by {{ post.user.name }}</p> <p class="article-date">{{ post.createdAt|date('m-d-Y :: H:i') }} by {{ post.user.name }}</p>
{{ post.content|insert_code_chunks }} {{ post.content|insert_code_chunks }}
{% if post.tags|length > 0 %}
<p class="article-tags">Tags:
{% for tag in post.tags %}
{{ tag.name }}
{% endfor %}
</p>
{% endif %}
</div> </div>