1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the thealternativezurich/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\Administration\Base\BaseController; |
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 BaseController |
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
|
|
|
$semester->setName(''); |
37
|
|
|
$form = $this->handleCreateForm($request, $semester); |
38
|
|
|
|
39
|
|
|
//get all existing semesters |
40
|
|
|
$semesters = $this->getDoctrine()->getRepository(Semester::class)->findBy([], ['creationDate' => 'DESC']); |
41
|
|
|
|
42
|
|
|
return $this->render('administration/semesters.html.twig', ['semesters' => $semesters, 'form' => $form->createView()]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** * |
46
|
|
|
* @Route("/{semester}/remove", name="administration_semester_remove") |
47
|
|
|
* |
48
|
|
|
* @return Response |
49
|
|
|
*/ |
50
|
|
|
public function removeAction(Semester $semester) |
51
|
|
|
{ |
52
|
|
|
//only allow to remove if no more entites attached |
53
|
|
|
if ($semester->getEvents()->count() > 0) { |
54
|
|
|
$this->displayError($this->getTranslator()->trans('remove.still_events_attached', [], 'administration_semester')); |
55
|
|
|
} else { |
56
|
|
|
$this->fastRemove($semester); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $this->redirectToRoute('administration_semesters'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* get the breadcrumbs leading to this controller. |
64
|
|
|
* |
65
|
|
|
* @return Breadcrumb[] |
66
|
|
|
*/ |
67
|
|
|
protected function getIndexBreadcrumbs() |
68
|
|
|
{ |
69
|
|
|
return array_merge(parent::getIndexBreadcrumbs(), [ |
70
|
|
|
new Breadcrumb( |
71
|
|
|
$this->generateUrl('administration_semesters'), |
72
|
|
|
$this->getTranslator()->trans('index.title', [], 'administration_semester') |
73
|
|
|
), |
74
|
|
|
]); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|