diff --git a/src/KekRozsak/FrontBundle/Controller/ForumController.php b/src/KekRozsak/FrontBundle/Controller/ForumController.php index dfad186..28a18a1 100644 --- a/src/KekRozsak/FrontBundle/Controller/ForumController.php +++ b/src/KekRozsak/FrontBundle/Controller/ForumController.php @@ -11,6 +11,7 @@ use KekRozsak\FrontBundle\Entity\ForumTopicGroup; use KekRozsak\FrontBundle\Entity\ForumTopic; use KekRozsak\FrontBundle\Entity\ForumPost; use KekRozsak\FrontBundle\Form\Type\ForumTopicGroupType; +use KekRozsak\FrontBundle\Form\Type\ForumTopicType; use KekRozsak\FrontBundle\Form\Type\ForumPostType; use KekRozsak\FrontBundle\Extensions\Slugifier; @@ -70,8 +71,38 @@ class ForumController extends Controller */ public function topicListAction(ForumTopicgRoup $topicGroup) { + $request = $this->getRequest(); + $newTopic = new ForumTopic(); + $newTopicForm = $this->createForm(new ForumTopicType(), $newTopic); + + if ($request->getMethod() == 'POST') { + $newTopicForm->bind($request); + + if ($newTopicForm->isValid()) { + $slugifier = new \KekRozsak\FrontBundle\Extensions\Slugifier(); + $newTopic->setSlug($slugifier->slugify($newTopic->getTitle())); + $newTopic->setCreatedAt(new \DateTime('now')); + $newTopic->setCreatedBy($this->get('security.context')->getToken()->getUser()); + $newTopic->setTopicGroup($topicGroup); + + $em = $this->getDoctrine()->getEntityManager(); + $em->persist($newTopic); + $em->flush(); + + return $this->redirect( + $this->generateUrl( + 'KekRozsakFrontBundle_forumTopicList', + array( + 'slug' => $topicGroup->getSlug(), + ) + ) + ); + } + } + return array( - 'topicGroup' => $topicGroup, + 'topicGroup' => $topicGroup, + 'newTopicForm' => $newTopicForm->createView(), ); } diff --git a/src/KekRozsak/FrontBundle/Entity/ForumTopic.php b/src/KekRozsak/FrontBundle/Entity/ForumTopic.php index 244f561..3d84066 100644 --- a/src/KekRozsak/FrontBundle/Entity/ForumTopic.php +++ b/src/KekRozsak/FrontBundle/Entity/ForumTopic.php @@ -4,12 +4,19 @@ namespace KekRozsak\FrontBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; +use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert; use KekRozsak\SecurityBundle\Entity\User; /** * @ORM\Entity - * @ORM\Table(name="forum_topics") + * @ORM\Table(name="forum_topics", uniqueConstraints={ + * @ORM\UniqueConstraint(columns={"topic_group_id", "title"}), + * @ORM\UniqueConstraint(columns={"topic_group_id", "slug"}) + * }) + * @DoctrineAssert\UniqueEntity(fields={"topicGroup", "title"}, message="Ilyen nevű téma már létezik ebben a témakörben. Kérlek válassz másikat!") + * @DoctrineAssert\UniqueEntity(fields={"topicGroup", "slug"}, message="Ilyen nevű téma már létezik ebben a témakörben. Kérlek válassz másikat!") */ class ForumTopic { @@ -112,7 +119,7 @@ class ForumTopic * @var ForumTopicGroup $topicGroup * * @ORM\ManyToOne(targetEntity="ForumTopicGroup", inversedBy="topics") - * @ORM\JoinColumn(name="topic_group_id") + * @ORM\JoinColumn(name="topic_group_id", nullable=false) */ protected $topicGroup; diff --git a/src/KekRozsak/FrontBundle/Form/Type/ForumTopicType.php b/src/KekRozsak/FrontBundle/Form/Type/ForumTopicType.php new file mode 100644 index 0000000..1a612ee --- /dev/null +++ b/src/KekRozsak/FrontBundle/Form/Type/ForumTopicType.php @@ -0,0 +1,32 @@ +add('title', null, array( + 'label' => 'Téma címe', + 'help' => 'Az új fórum téma címe', + )) + ; + } + + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'KekRozsak\FrontBundle\Entity\ForumTopic' + )); + } + + public function getName() + { + return 'kekrozsak_frontbundle_forumtopictype'; + } +} diff --git a/src/KekRozsak/FrontBundle/Resources/views/Forum/topicList.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Forum/topicList.html.twig index be3bc51..0cf55d8 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Forum/topicList.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Forum/topicList.html.twig @@ -1,9 +1,19 @@ {# vim: ft=htmljinja #} {% extends 'KekRozsakFrontBundle:Default:main_template.html.twig' %} +{% form_theme newTopicForm 'KekRozsakFrontBundle:Form:user_form.html.twig' %} + {% block title %} - Fórum - {{ topicGroup.title }}{% endblock %} + {% block content %}

Fórum - {{ topicGroup.title }}

+[Új téma]
+
+ + {{ form_widget(newTopicForm) }} +
+ +
{% if topicGroup.topics|length > 0 %}