diff --git a/src/KekRozsak/FrontBundle/Controller/ForumController.php b/src/KekRozsak/FrontBundle/Controller/ForumController.php index db69cb1..dfad186 100644 --- a/src/KekRozsak/FrontBundle/Controller/ForumController.php +++ b/src/KekRozsak/FrontBundle/Controller/ForumController.php @@ -10,7 +10,9 @@ 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\ForumTopicGroupType; use KekRozsak\FrontBundle\Form\Type\ForumPostType; +use KekRozsak\FrontBundle\Extensions\Slugifier; /** * @Route("/forum") @@ -24,12 +26,37 @@ class ForumController extends Controller public function topicGroupListAction() { $groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumTopicGroup'); + $request = $this->getRequest(); + $newTopicGroup = new ForumTopicGroup(); + $newTopicGroupForm = $this->createForm(new ForumTopicGroupType(), $newTopicGroup); + + if ($request->getMethod() == 'POST') { + $newTopicGroupForm->bind($request); + + if ($newTopicGroupForm->isValid()) { + $slugifier = new \KekRozsak\FrontBundle\Extensions\Slugifier(); + $newTopicGroup->setSlug($slugifier->slugify($newTopicGroup->getTitle())); + $newTopicGroup->setCreatedAt(new \DateTime('now')); + $newTopicGroup->setCreatedBy($this->get('security.context')->getToken()->getUser()); + + $em = $this->getDoctrine()->getEntityManager(); + $em->persist($newTopicGroup); + $em->flush(); + + return $this->redirect( + $this->generateUrl( + 'KekRozsakFrontBundle_forumTopicGroupList' + ) + ); + } + } // TODO: ORDER the topic list by last post date $topicGroups = $groupRepo->findAll(); return array( - 'topicGroups' => $topicGroups, + 'topicGroups' => $topicGroups, + 'newTopicGroupForm' => $newTopicGroupForm->createView(), ); } diff --git a/src/KekRozsak/FrontBundle/Entity/ForumTopicGroup.php b/src/KekRozsak/FrontBundle/Entity/ForumTopicGroup.php index 556c71d..d18476e 100644 --- a/src/KekRozsak/FrontBundle/Entity/ForumTopicGroup.php +++ b/src/KekRozsak/FrontBundle/Entity/ForumTopicGroup.php @@ -4,6 +4,8 @@ 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; @@ -11,6 +13,8 @@ use KekRozsak\SecurityBundle\Entity\User; * KekRozsak\FrontBundle\Entity\ForumTopicGroup * @ORM\Entity * @ORM\Table(name="forum_topic_groups") + * @DoctrineAssert\UniqueEntity(fields={"title"}, message="Ilyen nevű témakör már létezik. Kérlek válassz másikat!") + * @DoctrineAssert\UniqueEntity(fields={"slug"}, message="Ilyen nevű témakör már létezik. Kérlek válassz másikat!") */ class ForumTopicGroup { @@ -146,6 +150,7 @@ class ForumTopicGroup * @var string $title * * @ORM\Column(type="string", length=100, nullable=false, unique=true) + * @Assert\NotBlank() */ protected $title; diff --git a/src/KekRozsak/FrontBundle/Form/Type/ForumTopicGroupType.php b/src/KekRozsak/FrontBundle/Form/Type/ForumTopicGroupType.php new file mode 100644 index 0000000..35eff2d --- /dev/null +++ b/src/KekRozsak/FrontBundle/Form/Type/ForumTopicGroupType.php @@ -0,0 +1,32 @@ +add('title', null, array( + 'label' => 'Témakör neve', + 'help' => 'Az új fórum témakör neve', + )) + ; + } + + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'KekRozsak\FrontBundle\Entity\ForumTopicGroup' + )); + } + + public function getName() + { + return 'kekrozsak_frontbundle_forumtopicgrouptype'; + } +} diff --git a/src/KekRozsak/FrontBundle/Resources/views/Forum/topicGroupList.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Forum/topicGroupList.html.twig index e8b0c04..b91fa22 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Forum/topicGroupList.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Forum/topicGroupList.html.twig @@ -1,9 +1,28 @@ {# vim: ft=htmljinja #} {% extends 'KekRozsakFrontBundle:Default:main_template.html.twig' %} +{% form_theme newTopicGroupForm 'KekRozsakFrontBundle:Form:user_form.html.twig' %} + {% block title %} - Fórum{% endblock %} + {% block content %}

Fórum

+{% if is_granted('ROLE_ADMIN') %} +[Új témakör]
+
+{# TODO: make this an AJAX form #} +
+ + {{ form_widget(newTopicGroupForm) }} +
+ +
+
+{# +{% else %} +[Új témakör kérése] +#} +{% endif %} {% for topicGroup in topicGroups %} @@ -39,3 +58,13 @@
{% endfor %} {% endblock content %} + +{% block bottomscripts %} + +{% endblock bottomscripts %}