|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the feedback 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\Base\BaseFormController; |
|
15
|
|
|
use App\Entity\Semester; |
|
16
|
|
|
use App\Model\Breadcrumb; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
19
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @Route("/semester") |
|
23
|
|
|
*/ |
|
24
|
|
|
class SemesterController extends BaseFormController |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @Route("", name="administration_semesters") |
|
28
|
|
|
* |
|
29
|
|
|
* @return Response |
|
30
|
|
|
*/ |
|
31
|
|
|
public function indexAction(Request $request) |
|
32
|
|
|
{ |
|
33
|
|
|
//allow semester creation |
|
34
|
|
|
$semester = new Semester(); |
|
35
|
|
|
$semester->setCreationDate(new \DateTime()); |
|
36
|
|
|
$form = $this->handleCreateForm($request, $semester); |
|
37
|
|
|
|
|
38
|
|
|
//get all existing semesters |
|
39
|
|
|
$semesters = $this->getDoctrine()->getRepository(Semester::class)->findBy([], ['creationDate' => 'DESC']); |
|
40
|
|
|
|
|
41
|
|
|
return $this->render('administration/semesters.html.twig', ['semesters' => $semesters, 'form' => $form->createView()]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** * |
|
45
|
|
|
* @Route("/{semester}/remove", name="administration_semester_remove") |
|
46
|
|
|
* |
|
47
|
|
|
* @param Semester $semester |
|
48
|
|
|
* |
|
49
|
|
|
* @return Response |
|
50
|
|
|
*/ |
|
51
|
|
|
public function removeAction(Semester $semester) |
|
52
|
|
|
{ |
|
53
|
|
|
//only allow to remove if no more entites attached |
|
54
|
|
|
if ($semester->getEvents()->count() > 0) { |
|
55
|
|
|
$this->displayError($this->getTranslator()->trans('remove.still_events_attached', [], 'administration_semester')); |
|
56
|
|
|
} else { |
|
57
|
|
|
$this->fastRemove($semester); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $this->redirectToRoute('administration_semesters'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* get the breadcrumbs leading to this controller. |
|
65
|
|
|
* |
|
66
|
|
|
* @return Breadcrumb[] |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function getIndexBreadcrumbs() |
|
69
|
|
|
{ |
|
70
|
|
|
return array_merge(parent::getIndexBreadcrumbs(), [ |
|
71
|
|
|
new Breadcrumb( |
|
72
|
|
|
$this->generateUrl('administration_semesters'), |
|
73
|
|
|
$this->getTranslator()->trans('index.title', [], 'administration_semester') |
|
74
|
|
|
), |
|
75
|
|
|
]); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|