diff --git a/src/KekRozsak/FrontBundle/Controller/ForumController.php b/src/KekRozsak/FrontBundle/Controller/ForumController.php index b8f6351..11c973c 100644 --- a/src/KekRozsak/FrontBundle/Controller/ForumController.php +++ b/src/KekRozsak/FrontBundle/Controller/ForumController.php @@ -7,6 +7,8 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; +use KekRozsak\FrontBundle\Entity\ForumTopicGroup; +use KekRozsak\FrontBundle\Entity\ForumTopic; use KekRozsak\FrontBundle\Entity\ForumPost; use KekRozsak\FrontBundle\Form\Type\ForumPostType; @@ -32,16 +34,12 @@ class ForumController extends Controller } /** - * @Route("/{topicGroupSlug}", name="KekRozsakFrontBundle_forum_topic_list") + * @Route("/{slug}", name="KekRozsakFrontBundle_forum_topic_list") * @Template("KekRozsakFrontBundle:Forum:topic_list.html.twig") + * @ParamConverter("topicGroup") */ - public function topicListAction($topicGroupSlug) + public function topicListAction(ForumTopicgRoup $topicGroup) { - $groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumTopicGroup'); - - if (!($topicGroup = $groupRepo->findOneBySlug($topicGroupSlug))) - throw $this->createNotFoundException('A kért témakör nem létezik!'); - return array( 'topicGroup' => $topicGroup, ); @@ -50,19 +48,11 @@ class ForumController extends Controller /** * @Route("/{topicGroupSlug}/{topicSlug}", name="KekRozsakFrontBundle_forum_post_list") * @Template("KekRozsakFrontBundle:Forum:post_list.html.twig") + * @ParamConverter("topic", options={"mapping"={"topicGroup"="topicGroup", "topicSlug"="slug"}}) + * @ParamConverter("topicGroup", options={"mapping"={"topicGroupSlug"="slug"}}) */ - public function postListAction($topicGroupSlug, $topicSlug) + public function postListAction(ForumTopicGroup $topicGroup, ForumTopic $topic) { - // Get the topic group based on slug - $groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumTopicGroup'); - if (!($topicGroup = $groupRepo->findOneBySlug($topicGroupSlug))) - throw $this->createNotFoundException('A kért témakör nem létezik!'); - - // Get the topic based on slug - $topicRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumTopic'); - if (!($topic = $topicRepo->findOneBy(array('topicGroup' => $topicGroup, 'slug' => $topicSlug)))) - throw $this->createNotFoundException('A kért téma nem létezik!'); - // Get the list of posts in the requested topic $postRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumPost'); $posts = $postRepo->findBy(array('topic' => $topic), array('createdAt' => 'DESC') /* TODO: , limit, offset */); @@ -87,8 +77,8 @@ class ForumController extends Controller $em->flush(); return $this->redirect($this->generateUrl('KekRozsakFrontBundle_forum_post_list', array( - 'topicGroupSlug' => $topicGroupSlug, - 'topicSlug' => $topicSlug, + 'topicGroupSlug' => $topicGroup->getSlug(), + 'topicSlug' => $topic->getSlug(), ))); } } diff --git a/src/KekRozsak/FrontBundle/Entity/ForumPost.php b/src/KekRozsak/FrontBundle/Entity/ForumPost.php index 38b5036..f441a43 100644 --- a/src/KekRozsak/FrontBundle/Entity/ForumPost.php +++ b/src/KekRozsak/FrontBundle/Entity/ForumPost.php @@ -2,12 +2,13 @@ namespace KekRozsak\FrontBundle\Entity; -use Doctrine\Orm\Mapping as ORM; +use Doctrine\ORM\Mapping as ORM; use KekRozsak\FrontBundle\Entity\ForumTopic; /** * @ORM\Entity + * @ORM\HasLifecycleCallbacks * @ORM\Table(name="forum_posts") */ class ForumPost @@ -128,7 +129,7 @@ class ForumPost public function setTopic(ForumTopic $topic) { $this->topic = $topic; - if ($topic->getLastPost()->getCreatedAt() < $this->createdAt) + if (!$topic->getLastPost() || ($topic->getLastPost()->getCreatedAt() < $this->createdAt)) $topic->setLastPost($this); return $this; } @@ -142,5 +143,16 @@ class ForumPost { return $this->topic; } + + /** + * Set createdAt before persisting + * + * @ORM\PrePersist + */ + public function setCreationTime() + { + if ($this->createdAt === null) + $this->createdAt = new \DateTime('now'); + } } diff --git a/src/KekRozsak/FrontBundle/Form/Type/ForumPostType.php b/src/KekRozsak/FrontBundle/Form/Type/ForumPostType.php index b266f8e..a2cdc12 100644 --- a/src/KekRozsak/FrontBundle/Form/Type/ForumPostType.php +++ b/src/KekRozsak/FrontBundle/Form/Type/ForumPostType.php @@ -3,6 +3,7 @@ namespace KekRozsak\FrontBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; class ForumPostType extends AbstractType { @@ -31,13 +32,11 @@ class ForumPostType extends AbstractType return 'forum_post'; } - public function getDefaultOptions() + public function setDefaultOptions(OptionsResolverInterface $resolver) { - $opts = array( + $resolver->setDefaults(array( 'data_class' => 'KekRozsak\FrontBundle\Entity\ForumPost', - ); - - return $opts; + )); } } diff --git a/src/KekRozsak/FrontBundle/Form/Type/UserDataType.php b/src/KekRozsak/FrontBundle/Form/Type/UserDataType.php index e0f7889..763c346 100644 --- a/src/KekRozsak/FrontBundle/Form/Type/UserDataType.php +++ b/src/KekRozsak/FrontBundle/Form/Type/UserDataType.php @@ -3,6 +3,7 @@ namespace KekRozsak\FrontBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; class UserDataType extends AbstractType { @@ -69,11 +70,11 @@ class UserDataType extends AbstractType return 'user_data'; } - public function getDefaultOptions() + public function setDefaultOptions(OptionsResolverInterface $resolver) { - return array( + $resolver->setDefaults(array( 'data_class' => 'KekRozsak\FrontBundle\Entity\UserData' - ); + )); } } diff --git a/src/KekRozsak/FrontBundle/Resources/views/Forum/post_list.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Forum/post_list.html.twig index d45d214..612d835 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Forum/post_list.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Forum/post_list.html.twig @@ -3,7 +3,7 @@ {% extends '::main_template.html.twig' %} {% block title %} - Fórum - {{ topicGroup.title }} - {{ topic.title }}{% endblock %} {% block content %} -

Fórum - {{ topicGroup.title }} - {{ topic.title }}

+

Fórum - {{ topicGroup.title }} - {{ topic.title }}

diff --git a/src/KekRozsak/FrontBundle/Resources/views/Forum/topic_group_list.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Forum/topic_group_list.html.twig index b14f90d..67864f4 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Forum/topic_group_list.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Forum/topic_group_list.html.twig @@ -8,7 +8,7 @@
- + diff --git a/src/KekRozsak/FrontBundle/Resources/views/Forum/topic_list.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Forum/topic_list.html.twig index b26ded9..2d3c14a 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Forum/topic_list.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Forum/topic_list.html.twig @@ -19,8 +19,12 @@ {% endfor %} diff --git a/src/KekRozsak/SecurityBundle/Form/Type/UserType.php b/src/KekRozsak/SecurityBundle/Form/Type/UserType.php index 7bf396a..f2cf812 100644 --- a/src/KekRozsak/SecurityBundle/Form/Type/UserType.php +++ b/src/KekRozsak/SecurityBundle/Form/Type/UserType.php @@ -3,6 +3,7 @@ namespace KekRozsak\SecurityBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; use KekRozsak\FrontBundle\Form\Type\UserDataType; @@ -61,7 +62,7 @@ class UserType extends AbstractType return 'user'; } - public function getDefaultOptions() + public function setDefaultOptions(OptionsResolverInterface $resolver) { $opts = array( 'data_class' => 'KekRozsak\SecurityBundle\Entity\User', @@ -69,7 +70,7 @@ class UserType extends AbstractType if ($this->_registration) $opts['validation_groups'] = array('registration'); - return $opts; + $resolver->setDefaults($opts); } }
{{ topicGroup.title }}{{ topicGroup.title }} Hozzászólások száma Utolsó hozzászólás
{{ topic.title }} +{% if topic.lastPost %} {{ topic.lastPost.createdBy.displayName }}
{{ topic.lastPost.createdAt|date('Y-m-d H:i') }} +{% else %} +  
  +{% endif %}