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\ParamConverter;
use KekRozsak\FrontBundle\Entity\ForumTopicGroup;
use KekRozsak\FrontBundle\Entity\ForumTopic;
use KekRozsak\FrontBundle\Entity\ForumPost;
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")
* @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(
'topicGroup' => $topicGroup,
);
@ -50,19 +48,11 @@ class ForumController extends Controller
/**
* @Route("/{topicGroupSlug}/{topicSlug}", name="KekRozsakFrontBundle_forum_post_list")
* @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
$postRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumPost');
$posts = $postRepo->findBy(array('topic' => $topic), array('createdAt' => 'DESC') /* TODO: , limit, offset */);
@ -87,8 +77,8 @@ class ForumController extends Controller
$em->flush();
return $this->redirect($this->generateUrl('KekRozsakFrontBundle_forum_post_list', array(
'topicGroupSlug' => $topicGroupSlug,
'topicSlug' => $topicSlug,
'topicGroupSlug' => $topicGroup->getSlug(),
'topicSlug' => $topic->getSlug(),
)));
}
}

View File

@ -2,12 +2,13 @@
namespace KekRozsak\FrontBundle\Entity;
use Doctrine\Orm\Mapping as ORM;
use Doctrine\ORM\Mapping as ORM;
use KekRozsak\FrontBundle\Entity\ForumTopic;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
* @ORM\Table(name="forum_posts")
*/
class ForumPost
@ -128,7 +129,7 @@ class ForumPost
public function setTopic(ForumTopic $topic)
{
$this->topic = $topic;
if ($topic->getLastPost()->getCreatedAt() < $this->createdAt)
if (!$topic->getLastPost() || ($topic->getLastPost()->getCreatedAt() < $this->createdAt))
$topic->setLastPost($this);
return $this;
}
@ -142,5 +143,16 @@ class ForumPost
{
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\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class ForumPostType extends AbstractType
{
@ -31,13 +32,11 @@ class ForumPostType extends AbstractType
return 'forum_post';
}
public function getDefaultOptions()
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$opts = array(
$resolver->setDefaults(array(
'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\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class UserDataType extends AbstractType
{
@ -69,11 +70,11 @@ class UserDataType extends AbstractType
return 'user_data';
}
public function getDefaultOptions()
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
return array(
$resolver->setDefaults(array(
'data_class' => 'KekRozsak\FrontBundle\Entity\UserData'
);
));
}
}

View File

@ -3,7 +3,7 @@
{% extends '::main_template.html.twig' %}
{% block title %} - Fórum - {{ topicGroup.title }} - {{ topic.title }}{% endblock %}
{% 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">
<tbody>
<tr>

View File

@ -8,7 +8,7 @@
<table class="forum-lista">
<thead>
<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>Utolsó hozzászólás</td>
</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></td>
<td>
{% if topic.lastPost %}
{{ topic.lastPost.createdBy.displayName }}<br />
{{ topic.lastPost.createdAt|date('Y-m-d H:i') }}
{% else %}
&nbsp;<br />&nbsp;
{% endif %}
</td>
</tr>
{% endfor %}

View File

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