|
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}/reset_authentication_code", name="administration_organisation_reset_authentication_code") |
|
101
|
|
|
* |
|
102
|
|
|
* @throws \Exception |
|
103
|
|
|
* |
|
104
|
|
|
* @return Response |
|
105
|
|
|
*/ |
|
106
|
|
|
public function resetAuthenticationCodeAction(Organisation $organisation, TranslatorInterface $translator) |
|
107
|
|
|
{ |
|
108
|
|
|
$organisation->generateAuthenticationCode(); |
|
109
|
|
|
$this->fastSave($organisation); |
|
110
|
|
|
|
|
111
|
|
|
$this->displaySuccess($translator->trans('reset_authentication_code.success', [], 'administration_organisation')); |
|
112
|
|
|
|
|
113
|
|
|
return $this->redirectToRoute('administration_organisations'); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** * |
|
117
|
|
|
* @Route("/{organisation}/hide", name="administration_organisation_hide") |
|
118
|
|
|
* |
|
119
|
|
|
* @throws \Exception |
|
120
|
|
|
* |
|
121
|
|
|
* @return Response |
|
122
|
|
|
*/ |
|
123
|
|
|
public function hideAction(Organisation $organisation, TranslatorInterface $translator) |
|
124
|
|
|
{ |
|
125
|
|
|
if ($organisation->getHiddenAt() === null) { |
|
126
|
|
|
$organisation->hide(); |
|
127
|
|
|
$this->fastSave($organisation); |
|
128
|
|
|
|
|
129
|
|
|
$this->displaySuccess($translator->trans('hide.success', [], 'administration_organisation')); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
return $this->redirectToRoute('administration_organisations'); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** * |
|
136
|
|
|
* @Route("/{organisation}/unhide", name="administration_organisation_unhide") |
|
137
|
|
|
* |
|
138
|
|
|
* @throws \Exception |
|
139
|
|
|
* |
|
140
|
|
|
* @return Response |
|
141
|
|
|
*/ |
|
142
|
|
|
public function unhideAction(Organisation $organisation, TranslatorInterface $translator) |
|
143
|
|
|
{ |
|
144
|
|
|
if ($organisation->getHiddenAt() !== null) { |
|
145
|
|
|
$organisation->unhide(); |
|
146
|
|
|
$this->fastSave($organisation); |
|
147
|
|
|
|
|
148
|
|
|
$this->displaySuccess($translator->trans('unhide.success', [], 'administration_organisation')); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
return $this->redirectToRoute('administration_organisations'); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* get the breadcrumbs leading to this controller. |
|
156
|
|
|
* |
|
157
|
|
|
* @return Breadcrumb[] |
|
158
|
|
|
*/ |
|
159
|
|
|
protected function getIndexBreadcrumbs() |
|
160
|
|
|
{ |
|
161
|
|
|
return array_merge(parent::getIndexBreadcrumbs(), [ |
|
162
|
|
|
new Breadcrumb( |
|
163
|
|
|
$this->generateUrl('administration_organisations'), |
|
164
|
|
|
$this->getTranslator()->trans('index.title', [], 'administration_organisation') |
|
165
|
|
|
), |
|
166
|
|
|
]); |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|