Passed
Pull Request — master (#26)
by Florian
02:07
created

OrganisationController::eventsAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the vseth-semesterly-reports project.
5
 *
6
 * (c) Florian Moser <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\Controller\Administration;
13
14
use App\Controller\Administration\Base\BaseController;
15
use App\Entity\Organisation;
16
use App\Form\Type\SemesterType;
17
use App\Model\Breadcrumb;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\HttpFoundation\Response;
20
use Symfony\Component\Routing\Annotation\Route;
21
use Symfony\Contracts\Translation\TranslatorInterface;
22
23
/**
24
 * @Route("/organisation")
25
 */
26
class OrganisationController extends BaseController
27
{
28
    /**
29
     * @Route("", name="administration_organisations")
30
     *
31
     * @return Response
32
     */
33
    public function indexAction()
34
    {
35
        //get all existing semesters
36
        $organisations = $this->getDoctrine()->getRepository(Organisation::class)->findActive();
37
38
        return $this->render('administration/organisations.twig', ['organisations' => $organisations]);
39
    }
40
41
    /**
42
     * @Route("/hidden", name="administration_organisations_hidden")
43
     *
44
     * @return Response
45
     */
46
    public function hiddenAction()
47
    {
48
        //get all existing semesters
49
        /** @var Organisation[] $organisations */
50
        $organisations = $this->getDoctrine()->getRepository(Organisation::class)->findHidden();
51
52
        return $this->render('administration/organisations_hidden.twig', ['organisations' => $organisations]);
53
    }
54
55
    /**
56
     * @Route("/new", name="administration_organisation_new")
57
     *
58
     * @return Response
59
     */
60
    public function newAction(Request $request)
61
    {
62
        //create the event
63
        $organisation = new Organisation();
64
        $organisation->setName('');
65
        $organisation->setEmail('');
66
        $organisation->setRelationSinceSemester(SemesterType::getCurrentSemester());
67
68
        //process form
69
        $myForm = $this->handleCreateForm(
70
            $request,
71
            $organisation,
72
            function () use ($organisation) {
73
                $organisation->generateAuthenticationCode();
74
            }
75
        );
76
        if ($myForm instanceof Response) {
77
            return $myForm;
78
        }
79
80
        return $this->render('administration/organisation/new.html.twig', ['form' => $myForm->createView()]);
81
    }
82
83
    /**
84
     * @Route("/{organisation}/edit", name="administration_organisation_edit")
85
     *
86
     * @return Response
87
     */
88
    public function editAction(Request $request, Organisation $organisation)
89
    {
90
        //process form
91
        $myForm = $this->handleUpdateForm($request, $organisation);
92
        if ($myForm instanceof Response) {
93
            return $myForm;
94
        }
95
96
        return $this->render('administration/organisation/edit.html.twig', ['form' => $myForm->createView(), 'organisation' => $organisation]);
97
    }
98
99
    /**     *
100
     * @Route("/{organisation}/hide", name="administration_organisation_hide")
101
     *
102
     * @throws \Exception
103
     *
104
     * @return Response
105
     */
106
    public function hideAction(Organisation $organisation, TranslatorInterface $translator)
107
    {
108
        if ($organisation->getHiddenAt() === null) {
109
            $organisation->hide();
110
            $this->fastSave($organisation);
111
112
            $this->displaySuccess($translator->trans('hide.success', [], 'administration_organisation'));
113
        }
114
115
        return $this->redirectToRoute('administration_organisations');
116
    }
117
118
    /**     *
119
     * @Route("/{organisation}/unhide", name="administration_organisation_unhide")
120
     *
121
     * @throws \Exception
122
     *
123
     * @return Response
124
     */
125
    public function unhideAction(Organisation $organisation, TranslatorInterface $translator)
126
    {
127
        if ($organisation->getHiddenAt() !== null) {
128
            $organisation->unhide();
129
            $this->fastSave($organisation);
130
131
            $this->displaySuccess($translator->trans('unhide.success', [], 'administration_organisation'));
132
        }
133
134
        return $this->redirectToRoute('administration_organisations');
135
    }
136
137
    /**
138
     * get the breadcrumbs leading to this controller.
139
     *
140
     * @return Breadcrumb[]
141
     */
142
    protected function getIndexBreadcrumbs()
143
    {
144
        return array_merge(parent::getIndexBreadcrumbs(), [
145
            new Breadcrumb(
146
                $this->generateUrl('administration_organisations'),
147
                $this->getTranslator()->trans('index.title', [], 'administration_organisation')
148
            ),
149
        ]);
150
    }
151
}
152