Completed
Push — master ( 806dd7...a6321e )
by Arnaud
01:25
created

CommentController::showAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/*
3
 * Copyright 2014-2016 Arnaud Bienvenu
4
 *
5
 * This file is part of Kyela.
6
7
 * Kyela is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
12
 * Kyela is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with Kyela.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 */
21
22
namespace Abienvenu\KyelaBundle\Controller;
23
24
use Symfony\Component\HttpFoundation\Request;
25
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
26
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
27
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
28
use Abienvenu\KyelaBundle\Entity\Comment;
29
use Abienvenu\KyelaBundle\Form\Type\CommentType;
30
31
/**
32
 * Comment controller.
33
 *
34
 * @Route("/{pollUrl}/comment")
35
 */
36
class CommentController extends CRUDController
37
{
38
    protected $entityName = 'KyelaBundle:Comment';
39
    protected $cancelRoute = 'poll_show';
40
    protected $successRoute = 'poll_show';
41
    protected $deleteRoute = 'comment_delete';
42
    protected $deleteSuccessRoute = 'poll_show';
43
44
    /**
45
     * Displays latest comments
46
     *
47
     * @Method("GET")
48
     * @Template()
49
     */
50
    public function showAction()
51
    {
52
        $em = $this->getDoctrine()->getManager();
53
        $comments = $em->getRepository('KyelaBundle:Comment')->getLatestComments($this->poll);
54
        return ['poll' => $this->poll, 'comments' => $comments];
55
    }
56
57
    /**
58
     * Displays a form to create a new Comment entity.
59
     *
60
     * @Route("/new", name="comment_new")
61
     * @Method({"GET", "POST"})
62
     * @Template()
63
     */
64
    public function newAction(Request $request)
65
    {
66
        $comment = new Comment();
67
        if ($request->isMethod('POST'))
68
        {
69
            $comment->setDatetime(new \DateTime());
70
        }
71
        return $this->doNewAction(new CommentType($this->poll->getParticipantsAsArrayOfNames()), $comment, $request);
72
    }
73
74
    /**
75
     * Displays a form to edit an existing Comment entity.
76
     *
77
     * @Route("/{id}/edit", name="comment_edit")
78
     * @Method({"GET", "PUT"})
79
     * @Template()
80
     */
81
    public function editAction(Request $request, $id)
82
    {
83
        return $this->doEditAction(new CommentType($this->poll->getParticipantsAsArrayOfNames()), $id, $request);
84
    }
85
86
    /**
87
     * Deletes a Comment entity.
88
     *
89
     * @Route("/{id}", name="comment_delete")
90
     * @Method("DELETE")
91
     */
92
    public function deleteAction(Request $request, $id)
93
    {
94
        return $this->doDeleteAction($request, $id);
95
    }
96
}
97