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:
parent
bcb199e0de
commit
9457373710
@ -10,7 +10,9 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
|||||||
use KekRozsak\FrontBundle\Entity\ForumTopicGroup;
|
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\ForumPostType;
|
use KekRozsak\FrontBundle\Form\Type\ForumPostType;
|
||||||
|
use KekRozsak\FrontBundle\Extensions\Slugifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/forum")
|
* @Route("/forum")
|
||||||
@ -24,12 +26,37 @@ class ForumController extends Controller
|
|||||||
public function topicGroupListAction()
|
public function topicGroupListAction()
|
||||||
{
|
{
|
||||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumTopicGroup');
|
$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
|
// TODO: ORDER the topic list by last post date
|
||||||
$topicGroups = $groupRepo->findAll();
|
$topicGroups = $groupRepo->findAll();
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'topicGroups' => $topicGroups,
|
'topicGroups' => $topicGroups,
|
||||||
|
'newTopicGroupForm' => $newTopicGroupForm->createView(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ 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;
|
||||||
|
|
||||||
@ -11,6 +13,8 @@ use KekRozsak\SecurityBundle\Entity\User;
|
|||||||
* KekRozsak\FrontBundle\Entity\ForumTopicGroup
|
* KekRozsak\FrontBundle\Entity\ForumTopicGroup
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table(name="forum_topic_groups")
|
* @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
|
class ForumTopicGroup
|
||||||
{
|
{
|
||||||
@ -146,6 +150,7 @@ class ForumTopicGroup
|
|||||||
* @var string $title
|
* @var string $title
|
||||||
*
|
*
|
||||||
* @ORM\Column(type="string", length=100, nullable=false, unique=true)
|
* @ORM\Column(type="string", length=100, nullable=false, unique=true)
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $title;
|
protected $title;
|
||||||
|
|
||||||
|
32
src/KekRozsak/FrontBundle/Form/Type/ForumTopicGroupType.php
Normal file
32
src/KekRozsak/FrontBundle/Form/Type/ForumTopicGroupType.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 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';
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,28 @@
|
|||||||
{# vim: ft=htmljinja
|
{# vim: ft=htmljinja
|
||||||
#}
|
#}
|
||||||
{% extends 'KekRozsakFrontBundle:Default:main_template.html.twig' %}
|
{% extends 'KekRozsakFrontBundle:Default:main_template.html.twig' %}
|
||||||
|
{% form_theme newTopicGroupForm 'KekRozsakFrontBundle:Form:user_form.html.twig' %}
|
||||||
|
|
||||||
{% block title %} - Fórum{% endblock %}
|
{% block title %} - Fórum{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h3>Fórum</h3>
|
<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 %}
|
{% for topicGroup in topicGroups %}
|
||||||
<table class="forum-lista">
|
<table class="forum-lista">
|
||||||
<thead>
|
<thead>
|
||||||
@ -39,3 +58,13 @@
|
|||||||
</table>
|
</table>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
|
{% block bottomscripts %}
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('#new-topic-group-button').click(function() {
|
||||||
|
alert('Juj!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock bottomscripts %}
|
||||||
|
Loading…
Reference in New Issue
Block a user