Forum topic group creation possibility

Solves first half of issue #26.

Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Gergely Polonkai (W00d5t0ck) 2012-08-23 16:56:26 +02:00
parent bcb199e0de
commit 9457373710
4 changed files with 94 additions and 1 deletions

View File

@ -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(),
);
}

View File

@ -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;

View 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 ForumTopicGroupType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->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';
}
}

View File

@ -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 %}
<h3>Fórum</h3>
{% if is_granted('ROLE_ADMIN') %}
<span class="gomb" id="new-topic-group-button">[Új témakör]</span><br />
<div id="new-topic-group">
{# TODO: make this an AJAX form #}
<form method="post" action="{{ path('KekRozsakFrontBundle_forumTopicGroupList') }}">
<table>
{{ form_widget(newTopicGroupForm) }}
</table>
<button type="submit">Mentés</button>
</form>
</div>
{#
{% else %}
<span class="gomb">[Új témakör kérése]</span>
#}
{% endif %}
{% for topicGroup in topicGroups %}
<table class="forum-lista">
<thead>
@ -39,3 +58,13 @@
</table>
{% endfor %}
{% endblock content %}
{% block bottomscripts %}
<script type="text/javascript">
$(document).ready(function() {
$('#new-topic-group-button').click(function() {
alert('Juj!');
});
});
</script>
{% endblock bottomscripts %}