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

EventController::showAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
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\Event;
29
use Abienvenu\KyelaBundle\Form\Type\EventType;
30
31
/**
32
 * Event controller.
33
 *
34
 * @Route("/{pollUrl}/event")
35
 */
36
class EventController extends CRUDController
37
{
38
    protected $entityName = 'KyelaBundle:Event';
39
    protected $cancelRoute = 'poll_show';
40
    protected $successRoute = 'poll_show';
41
    protected $deleteRoute = 'event_delete';
42
    protected $deleteSuccessRoute = 'poll_show';
43
44
    /**
45
     * Displays poll events
46
     *
47
     * @Method("GET")
48
     * @Template()
49
     */
50
    public function showAction($isFuture)
51
    {
52
        $em = $this->getDoctrine()->getManager();
53
        $events = $em->getRepository('KyelaBundle:Event')->getFutureOrPastEvents($this->poll, $isFuture);
54
        return [
55
            'poll' => $this->poll,
56
            'events' => $events,
57
        ];
58
    }
59
60
    /**
61
     * Displays a form to create a new Event entity.
62
     *
63
     * @Route("/new", name="event_new")
64
     * @Method({"GET", "POST"})
65
     * @Template()
66
     */
67
    public function newAction(Request $request)
68
    {
69
        return $this->doNewAction(EventType::class, new Event(), $request);
70
    }
71
72
    /**
73
     * Displays a form to edit an existing Event entity.
74
     *
75
     * @Route("/{id}/edit", name="event_edit")
76
     * @Method({"GET", "PUT"})
77
     * @Template()
78
     */
79
    public function editAction(Request $request, $id)
80
    {
81
        return $this->doEditAction(EventType::class, $id, $request);
82
    }
83
84
    /**
85
     * Deletes a Event entity.
86
     *
87
     * @Route("/{id}", name="event_delete")
88
     * @Method("DELETE")
89
     */
90
    public function deleteAction(Request $request, $id)
91
    {
92
        return $this->doDeleteAction($request, $id);
93
    }
94
}
95