Completed
Push — master ( 5e4ebc...f96e76 )
by Florian
13s queued 11s
created

OrganisationController::removeAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 4
c 1
b 1
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 2
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("/{organisation}/events", name="administration_organisations_events")
57
     *
58
     * @return Response
59
     */
60
    public function eventsAction(Organisation $organisation)
61
    {
62
        return $this->render('administration/organisation/events.twig', ['organisation' => $organisation]);
63
    }
64
65
    /**
66
     * @Route("/new", name="administration_organisation_new")
67
     *
68
     * @return Response
69
     */
70
    public function newAction(Request $request)
71
    {
72
        //create the event
73
        $organisation = new Organisation();
74
        $organisation->setName('');
75
        $organisation->setEmail('');
76
        $organisation->setRelationSinceSemester(SemesterType::getCurrentSemester());
77
78
        //process form
79
        $myForm = $this->handleCreateForm(
80
            $request,
81
            $organisation,
82
            function () use ($organisation) {
83
                $organisation->generateAuthenticationCode();
84
            }
85
        );
86
        if ($myForm instanceof Response) {
87
            return $myForm;
88
        }
89
90
        return $this->render('administration/organisation/new.html.twig', ['form' => $myForm->createView()]);
91
    }
92
93
    /**
94
     * @Route("/{organisation}/edit", name="administration_organisation_edit")
95
     *
96
     * @return Response
97
     */
98
    public function editAction(Request $request, Organisation $organisation)
99
    {
100
        //process form
101
        $myForm = $this->handleUpdateForm($request, $organisation);
102
        if ($myForm instanceof Response) {
103
            return $myForm;
104
        }
105
106
        return $this->render('administration/organisation/edit.html.twig', ['form' => $myForm->createView(), 'organisation' => $organisation]);
107
    }
108
109
    /**     *
110
     * @Route("/{organisation}/hide", name="administration_organisation_hide")
111
     *
112
     * @throws \Exception
113
     *
114
     * @return Response
115
     */
116
    public function hideAction(Organisation $organisation, TranslatorInterface $translator)
117
    {
118
        if ($organisation->getHiddenAt() === null) {
119
            $organisation->hide();
120
            $this->fastSave($organisation);
121
122
            $this->displaySuccess($translator->trans('hide.success', [], 'administration_organisation'));
123
        }
124
125
        return $this->redirectToRoute('administration_organisations');
126
    }
127
128
    /**     *
129
     * @Route("/{organisation}/unhide", name="administration_organisation_unhide")
130
     *
131
     * @throws \Exception
132
     *
133
     * @return Response
134
     */
135
    public function unhideAction(Organisation $organisation, TranslatorInterface $translator)
136
    {
137
        if ($organisation->getHiddenAt() !== null) {
138
            $organisation->unhide();
139
            $this->fastSave($organisation);
140
141
            $this->displaySuccess($translator->trans('unhide.success', [], 'administration_organisation'));
142
        }
143
144
        return $this->redirectToRoute('administration_organisations');
145
    }
146
147
    /**
148
     * get the breadcrumbs leading to this controller.
149
     *
150
     * @return Breadcrumb[]
151
     */
152
    protected function getIndexBreadcrumbs()
153
    {
154
        return array_merge(parent::getIndexBreadcrumbs(), [
155
            new Breadcrumb(
156
                $this->generateUrl('administration_organisations'),
157
                $this->getTranslator()->trans('index.title', [], 'administration_organisation')
158
            ),
159
        ]);
160
    }
161
}
162