Added forum topic creation feature
Fixes second half of issue #26 Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
		| @@ -11,6 +11,7 @@ use KekRozsak\FrontBundle\Entity\ForumTopicGroup; | |||||||
| use KekRozsak\FrontBundle\Entity\ForumTopic; | use KekRozsak\FrontBundle\Entity\ForumTopic; | ||||||
| use KekRozsak\FrontBundle\Entity\ForumPost; | use KekRozsak\FrontBundle\Entity\ForumPost; | ||||||
| use KekRozsak\FrontBundle\Form\Type\ForumTopicGroupType; | use KekRozsak\FrontBundle\Form\Type\ForumTopicGroupType; | ||||||
|  | use KekRozsak\FrontBundle\Form\Type\ForumTopicType; | ||||||
| use KekRozsak\FrontBundle\Form\Type\ForumPostType; | use KekRozsak\FrontBundle\Form\Type\ForumPostType; | ||||||
| use KekRozsak\FrontBundle\Extensions\Slugifier; | use KekRozsak\FrontBundle\Extensions\Slugifier; | ||||||
|  |  | ||||||
| @@ -70,8 +71,38 @@ class ForumController extends Controller | |||||||
|      */ |      */ | ||||||
|     public function topicListAction(ForumTopicgRoup $topicGroup) |     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( |         return array( | ||||||
|             'topicGroup' => $topicGroup, |             'topicGroup'   => $topicGroup, | ||||||
|  |             'newTopicForm' => $newTopicForm->createView(), | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,12 +4,19 @@ namespace KekRozsak\FrontBundle\Entity; | |||||||
|  |  | ||||||
| use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||||
| use Doctrine\Common\Collections\ArrayCollection; | 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; | use KekRozsak\SecurityBundle\Entity\User; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * @ORM\Entity |  * @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 | class ForumTopic | ||||||
| { | { | ||||||
| @@ -112,7 +119,7 @@ class ForumTopic | |||||||
|      * @var ForumTopicGroup $topicGroup |      * @var ForumTopicGroup $topicGroup | ||||||
|      * |      * | ||||||
|      * @ORM\ManyToOne(targetEntity="ForumTopicGroup", inversedBy="topics") |      * @ORM\ManyToOne(targetEntity="ForumTopicGroup", inversedBy="topics") | ||||||
|      * @ORM\JoinColumn(name="topic_group_id") |      * @ORM\JoinColumn(name="topic_group_id", nullable=false) | ||||||
|      */ |      */ | ||||||
|     protected $topicGroup; |     protected $topicGroup; | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										32
									
								
								src/KekRozsak/FrontBundle/Form/Type/ForumTopicType.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/KekRozsak/FrontBundle/Form/Type/ForumTopicType.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace KekRozsak\FrontBundle\Form\Type; | ||||||
|  |  | ||||||
|  | use Symfony\Component\Form\AbstractType; | ||||||
|  | use Symfony\Component\Form\FormBuilderInterface; | ||||||
|  | use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||||||
|  |  | ||||||
|  | class ForumTopicType extends AbstractType | ||||||
|  | { | ||||||
|  |     public function buildForm(FormBuilderInterface $builder, array $options) | ||||||
|  |     { | ||||||
|  |         $builder | ||||||
|  |             ->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'; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -1,9 +1,19 @@ | |||||||
| {# vim: ft=htmljinja | {# vim: ft=htmljinja | ||||||
| #} | #} | ||||||
| {% extends 'KekRozsakFrontBundle:Default:main_template.html.twig' %} | {% extends 'KekRozsakFrontBundle:Default:main_template.html.twig' %} | ||||||
|  | {% form_theme newTopicForm 'KekRozsakFrontBundle:Form:user_form.html.twig' %} | ||||||
|  |  | ||||||
| {% block title %} - Fórum - {{ topicGroup.title }}{% endblock %} | {% block title %} - Fórum - {{ topicGroup.title }}{% endblock %} | ||||||
|  |  | ||||||
| {% block content %} | {% block content %} | ||||||
| <h3><a href="{{ path('KekRozsakFrontBundle_forumTopicGroupList') }}">Fórum</a> - {{ topicGroup.title }}</h3> | <h3><a href="{{ path('KekRozsakFrontBundle_forumTopicGroupList') }}">Fórum</a> - {{ topicGroup.title }}</h3> | ||||||
|  | <span class="gomb" id="new-topic-button">[Új téma]</span><br /> | ||||||
|  | <form method="post" action="{{ path('KekRozsakFrontBundle_forumTopicList', { slug: topicGroup.slug }) }}"> | ||||||
|  |     <table> | ||||||
|  |         {{ form_widget(newTopicForm) }} | ||||||
|  |     </table> | ||||||
|  |         <button type="submit">Mentés</button> | ||||||
|  | </form> | ||||||
| {% if topicGroup.topics|length > 0 %} | {% if topicGroup.topics|length > 0 %} | ||||||
| <table class="forum-lista"> | <table class="forum-lista"> | ||||||
|     <thead> |     <thead> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user