Bug fixes

Signed-off-by: Polonkai Gergely <polesz@w00d5t0ck.info>
This commit is contained in:
Polonkai Gergely 2012-07-31 10:14:26 +02:00
parent f21d48c6a8
commit b82eb93bf7
8 changed files with 41 additions and 34 deletions

View File

@ -7,6 +7,8 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use KekRozsak\FrontBundle\Entity\ForumTopicGroup;
use KekRozsak\FrontBundle\Entity\ForumTopic;
use KekRozsak\FrontBundle\Entity\ForumPost; use KekRozsak\FrontBundle\Entity\ForumPost;
use KekRozsak\FrontBundle\Form\Type\ForumPostType; use KekRozsak\FrontBundle\Form\Type\ForumPostType;
@ -32,16 +34,12 @@ class ForumController extends Controller
} }
/** /**
* @Route("/{topicGroupSlug}", name="KekRozsakFrontBundle_forum_topic_list") * @Route("/{slug}", name="KekRozsakFrontBundle_forum_topic_list")
* @Template("KekRozsakFrontBundle:Forum:topic_list.html.twig") * @Template("KekRozsakFrontBundle:Forum:topic_list.html.twig")
* @ParamConverter("topicGroup")
*/ */
public function topicListAction($topicGroupSlug) public function topicListAction(ForumTopicgRoup $topicGroup)
{ {
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumTopicGroup');
if (!($topicGroup = $groupRepo->findOneBySlug($topicGroupSlug)))
throw $this->createNotFoundException('A kért témakör nem létezik!');
return array( return array(
'topicGroup' => $topicGroup, 'topicGroup' => $topicGroup,
); );
@ -50,19 +48,11 @@ class ForumController extends Controller
/** /**
* @Route("/{topicGroupSlug}/{topicSlug}", name="KekRozsakFrontBundle_forum_post_list") * @Route("/{topicGroupSlug}/{topicSlug}", name="KekRozsakFrontBundle_forum_post_list")
* @Template("KekRozsakFrontBundle:Forum:post_list.html.twig") * @Template("KekRozsakFrontBundle:Forum:post_list.html.twig")
* @ParamConverter("topic", options={"mapping"={"topicGroup"="topicGroup", "topicSlug"="slug"}})
* @ParamConverter("topicGroup", options={"mapping"={"topicGroupSlug"="slug"}})
*/ */
public function postListAction($topicGroupSlug, $topicSlug) public function postListAction(ForumTopicGroup $topicGroup, ForumTopic $topic)
{ {
// Get the topic group based on slug
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumTopicGroup');
if (!($topicGroup = $groupRepo->findOneBySlug($topicGroupSlug)))
throw $this->createNotFoundException('A kért témakör nem létezik!');
// Get the topic based on slug
$topicRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumTopic');
if (!($topic = $topicRepo->findOneBy(array('topicGroup' => $topicGroup, 'slug' => $topicSlug))))
throw $this->createNotFoundException('A kért téma nem létezik!');
// Get the list of posts in the requested topic // Get the list of posts in the requested topic
$postRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumPost'); $postRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumPost');
$posts = $postRepo->findBy(array('topic' => $topic), array('createdAt' => 'DESC') /* TODO: , limit, offset */); $posts = $postRepo->findBy(array('topic' => $topic), array('createdAt' => 'DESC') /* TODO: , limit, offset */);
@ -87,8 +77,8 @@ class ForumController extends Controller
$em->flush(); $em->flush();
return $this->redirect($this->generateUrl('KekRozsakFrontBundle_forum_post_list', array( return $this->redirect($this->generateUrl('KekRozsakFrontBundle_forum_post_list', array(
'topicGroupSlug' => $topicGroupSlug, 'topicGroupSlug' => $topicGroup->getSlug(),
'topicSlug' => $topicSlug, 'topicSlug' => $topic->getSlug(),
))); )));
} }
} }

View File

@ -2,12 +2,13 @@
namespace KekRozsak\FrontBundle\Entity; namespace KekRozsak\FrontBundle\Entity;
use Doctrine\Orm\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use KekRozsak\FrontBundle\Entity\ForumTopic; use KekRozsak\FrontBundle\Entity\ForumTopic;
/** /**
* @ORM\Entity * @ORM\Entity
* @ORM\HasLifecycleCallbacks
* @ORM\Table(name="forum_posts") * @ORM\Table(name="forum_posts")
*/ */
class ForumPost class ForumPost
@ -128,7 +129,7 @@ class ForumPost
public function setTopic(ForumTopic $topic) public function setTopic(ForumTopic $topic)
{ {
$this->topic = $topic; $this->topic = $topic;
if ($topic->getLastPost()->getCreatedAt() < $this->createdAt) if (!$topic->getLastPost() || ($topic->getLastPost()->getCreatedAt() < $this->createdAt))
$topic->setLastPost($this); $topic->setLastPost($this);
return $this; return $this;
} }
@ -142,5 +143,16 @@ class ForumPost
{ {
return $this->topic; return $this->topic;
} }
/**
* Set createdAt before persisting
*
* @ORM\PrePersist
*/
public function setCreationTime()
{
if ($this->createdAt === null)
$this->createdAt = new \DateTime('now');
}
} }

View File

@ -3,6 +3,7 @@ namespace KekRozsak\FrontBundle\Form\Type;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class ForumPostType extends AbstractType class ForumPostType extends AbstractType
{ {
@ -31,13 +32,11 @@ class ForumPostType extends AbstractType
return 'forum_post'; return 'forum_post';
} }
public function getDefaultOptions() public function setDefaultOptions(OptionsResolverInterface $resolver)
{ {
$opts = array( $resolver->setDefaults(array(
'data_class' => 'KekRozsak\FrontBundle\Entity\ForumPost', 'data_class' => 'KekRozsak\FrontBundle\Entity\ForumPost',
); ));
return $opts;
} }
} }

View File

@ -3,6 +3,7 @@ namespace KekRozsak\FrontBundle\Form\Type;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class UserDataType extends AbstractType class UserDataType extends AbstractType
{ {
@ -69,11 +70,11 @@ class UserDataType extends AbstractType
return 'user_data'; return 'user_data';
} }
public function getDefaultOptions() public function setDefaultOptions(OptionsResolverInterface $resolver)
{ {
return array( $resolver->setDefaults(array(
'data_class' => 'KekRozsak\FrontBundle\Entity\UserData' 'data_class' => 'KekRozsak\FrontBundle\Entity\UserData'
); ));
} }
} }

View File

@ -3,7 +3,7 @@
{% extends '::main_template.html.twig' %} {% extends '::main_template.html.twig' %}
{% block title %} - Fórum - {{ topicGroup.title }} - {{ topic.title }}{% endblock %} {% block title %} - Fórum - {{ topicGroup.title }} - {{ topic.title }}{% endblock %}
{% block content %} {% block content %}
<h3><a href="{{ path('KekRozsakFrontBundle_forum_main') }}">Fórum</a> - <a href="{{ path('KekRozsakFrontBundle_forum_topic_list', { topicGroupSlug: topicGroup.slug }) }}">{{ topicGroup.title }}</a> - {{ topic.title }}</h3> <h3><a href="{{ path('KekRozsakFrontBundle_forum_main') }}">Fórum</a> - <a href="{{ path('KekRozsakFrontBundle_forum_topic_list', {slug: topicGroup.slug}) }}">{{ topicGroup.title }}</a> - {{ topic.title }}</h3>
<table class="post-lista"> <table class="post-lista">
<tbody> <tbody>
<tr> <tr>

View File

@ -8,7 +8,7 @@
<table class="forum-lista"> <table class="forum-lista">
<thead> <thead>
<tr> <tr>
<td colspan="2"><a href="{{ path('KekRozsakFrontBundle_forum_topic_list', {topicGroupSlug: topicGroup.slug}) }}">{{ topicGroup.title }}</a></td> <td colspan="2"><a href="{{ path('KekRozsakFrontBundle_forum_topic_list', {slug: topicGroup.slug}) }}">{{ topicGroup.title }}</a></td>
<td>Hozzászólások száma</td> <td>Hozzászólások száma</td>
<td>Utolsó hozzászólás</td> <td>Utolsó hozzászólás</td>
</tr> </tr>

View File

@ -19,8 +19,12 @@
<td><a href="{{ path('KekRozsakFrontBundle_forum_post_list', { topicGroupSlug: topicGroup.slug, topicSlug: topic.slug }) }}">{{ topic.title }}</a></td> <td><a href="{{ path('KekRozsakFrontBundle_forum_post_list', { topicGroupSlug: topicGroup.slug, topicSlug: topic.slug }) }}">{{ topic.title }}</a></td>
<td></td> <td></td>
<td> <td>
{% if topic.lastPost %}
{{ topic.lastPost.createdBy.displayName }}<br /> {{ topic.lastPost.createdBy.displayName }}<br />
{{ topic.lastPost.createdAt|date('Y-m-d H:i') }} {{ topic.lastPost.createdAt|date('Y-m-d H:i') }}
{% else %}
&nbsp;<br />&nbsp;
{% endif %}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}

View File

@ -3,6 +3,7 @@ namespace KekRozsak\SecurityBundle\Form\Type;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use KekRozsak\FrontBundle\Form\Type\UserDataType; use KekRozsak\FrontBundle\Form\Type\UserDataType;
@ -61,7 +62,7 @@ class UserType extends AbstractType
return 'user'; return 'user';
} }
public function getDefaultOptions() public function setDefaultOptions(OptionsResolverInterface $resolver)
{ {
$opts = array( $opts = array(
'data_class' => 'KekRozsak\SecurityBundle\Entity\User', 'data_class' => 'KekRozsak\SecurityBundle\Entity\User',
@ -69,7 +70,7 @@ class UserType extends AbstractType
if ($this->_registration) if ($this->_registration)
$opts['validation_groups'] = array('registration'); $opts['validation_groups'] = array('registration');
return $opts; $resolver->setDefaults($opts);
} }
} }