Refactored code to comply with PSR-*
Signed-off-by: Gergely POLONKAI <polesz@w00d5t0ck.info>
This commit is contained in:
@@ -17,77 +17,90 @@ use KekRozsak\FrontBundle\Form\Type\ForumPostType;
|
||||
*/
|
||||
class ForumController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("", name="KekRozsakFrontBundle_forumTopicGroupList")
|
||||
* @Template()
|
||||
*/
|
||||
public function topicGroupListAction()
|
||||
{
|
||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumTopicGroup');
|
||||
/**
|
||||
* @Route("", name="KekRozsakFrontBundle_forumTopicGroupList")
|
||||
* @Template()
|
||||
*/
|
||||
public function topicGroupListAction()
|
||||
{
|
||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:ForumTopicGroup');
|
||||
|
||||
// TODO: ORDER the topic list by last post date
|
||||
$topicGroups = $groupRepo->findAll();
|
||||
// TODO: ORDER the topic list by last post date
|
||||
$topicGroups = $groupRepo->findAll();
|
||||
|
||||
return array(
|
||||
'topicGroups' => $topicGroups,
|
||||
);
|
||||
}
|
||||
return array(
|
||||
'topicGroups' => $topicGroups,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{slug}", name="KekRozsakFrontBundle_forumTopicList")
|
||||
* @Template()
|
||||
* @ParamConverter("topicGroup")
|
||||
*/
|
||||
public function topicListAction(ForumTopicgRoup $topicGroup)
|
||||
{
|
||||
return array(
|
||||
'topicGroup' => $topicGroup,
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @Route("/{slug}", name="KekRozsakFrontBundle_forumTopicList")
|
||||
* @Template()
|
||||
* @ParamConverter("topicGroup")
|
||||
*/
|
||||
public function topicListAction(ForumTopicgRoup $topicGroup)
|
||||
{
|
||||
return array(
|
||||
'topicGroup' => $topicGroup,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{topicGroupSlug}/{topicSlug}", name="KekRozsakFrontBundle_forumPostList")
|
||||
* @Template()
|
||||
* @ParamConverter("topic", options={"mapping"={"topicGroup"="topicGroup", "topicSlug"="slug"}})
|
||||
* @ParamConverter("topicGroup", options={"mapping"={"topicGroupSlug"="slug"}})
|
||||
*/
|
||||
public function postListAction(ForumTopicGroup $topicGroup, ForumTopic $topic)
|
||||
{
|
||||
// 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 */);
|
||||
/**
|
||||
* @Route("/{topicGroupSlug}/{topicSlug}", name="KekRozsakFrontBundle_forumPostList")
|
||||
* @Template()
|
||||
* @ParamConverter("topic", options={"mapping"={"topicGroup"="topicGroup", "topicSlug"="slug"}})
|
||||
* @ParamConverter("topicGroup", options={"mapping"={"topicGroupSlug"="slug"}})
|
||||
*/
|
||||
public function postListAction(ForumTopicGroup $topicGroup, ForumTopic $topic)
|
||||
{
|
||||
// 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 */
|
||||
);
|
||||
|
||||
// Create an empty post object for posting
|
||||
$post = new ForumPost();
|
||||
$form = $this->createForm(new ForumPostType($topicGroup->getId(), $topic->getId()), $post);
|
||||
// Create an empty post object for posting
|
||||
$post = new ForumPost();
|
||||
$form = $this->createForm(
|
||||
new ForumPostType(
|
||||
$topicGroup->getId(),
|
||||
$topic->getId()
|
||||
),
|
||||
$post
|
||||
);
|
||||
|
||||
$request = $this->getRequest();
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->bind($request);
|
||||
if ($form->isValid())
|
||||
{
|
||||
$post->setCreatedAt(new \DateTime('now'));
|
||||
$post->setCreatedBy($this->get('security.context')->getToken()->getUser());
|
||||
$post->setTopic($topic);
|
||||
$request = $this->getRequest();
|
||||
if ($request->getMethod() == 'POST') {
|
||||
$form->bind($request);
|
||||
if ($form->isValid()) {
|
||||
$post->setCreatedAt(new \DateTime('now'));
|
||||
$post->setCreatedBy($this->get('security.context')->getToken()->getUser());
|
||||
$post->setTopic($topic);
|
||||
|
||||
$em = $this->getDoctrine()->getEntityManager();
|
||||
$em->persist($post);
|
||||
$em->persist($topic);
|
||||
$em->flush();
|
||||
$em = $this->getDoctrine()->getEntityManager();
|
||||
$em->persist($post);
|
||||
$em->persist($topic);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('KekRozsakFrontBundle_forumPostList', array(
|
||||
return $this->redirect(
|
||||
$this->generateUrl(
|
||||
'KekRozsakFrontBundle_forumPostList',
|
||||
array(
|
||||
'topicGroupSlug' => $topicGroup->getSlug(),
|
||||
'topicSlug' => $topic->getSlug(),
|
||||
)));
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'topicGroup' => $topicGroup,
|
||||
'topic' => $topic,
|
||||
'posts' => $posts,
|
||||
'form' => $form->createView(),
|
||||
);
|
||||
}
|
||||
return array(
|
||||
'topicGroup' => $topicGroup,
|
||||
'topic' => $topic,
|
||||
'posts' => $posts,
|
||||
'form' => $form->createView(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user