|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\Tuition; |
|
6
|
|
|
use App\Entity\TuitionGradeCategory; |
|
7
|
|
|
use App\Form\AssignTuitionGradeCategoryType; |
|
8
|
|
|
use App\Form\TuitionGradeCategoryType; |
|
9
|
|
|
use App\Repository\TuitionGradeCategoryRepositoryInterface; |
|
10
|
|
|
use SchulIT\CommonBundle\Utils\RefererHelper; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
14
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
15
|
|
|
|
|
16
|
|
|
#[Route('/admin/gradebook')] |
|
17
|
|
|
class TuitionGradeCategoryAdminController extends AbstractController { |
|
18
|
|
|
|
|
19
|
|
|
public function __construct(private readonly TuitionGradeCategoryRepositoryInterface $repository, RefererHelper $redirectHelper) { |
|
20
|
|
|
parent::__construct($redirectHelper); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
#[Route('', name: 'admin_tuition_grades')] |
|
24
|
|
|
public function index(): Response { |
|
25
|
|
|
return $this->render('admin/tuition_grades/index.html.twig', [ |
|
26
|
|
|
'categories' => $this->repository->findAll() |
|
27
|
|
|
]); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
#[Route('/assign', name: 'assign_tuition_grades')] |
|
31
|
|
|
public function assign(Request $request): RedirectResponse|Response { |
|
32
|
|
|
$form = $this->createForm(AssignTuitionGradeCategoryType::class); |
|
33
|
|
|
$form->handleRequest($request); |
|
34
|
|
|
|
|
35
|
|
|
if($form->isSubmitted() && $form->isValid()) { |
|
36
|
|
|
/** @var TuitionGradeCategory[] $categories */ |
|
37
|
|
|
$categories = $form->get('categories')->getData(); |
|
38
|
|
|
/** @var Tuition[] $tuitions */ |
|
39
|
|
|
$tuitions = $form->get('tuitions')->getData(); |
|
40
|
|
|
|
|
41
|
|
|
foreach($categories as $category) { |
|
42
|
|
|
foreach($tuitions as $tuition) { |
|
43
|
|
|
if(!$category->getTuitions()->contains($tuition)) { |
|
44
|
|
|
$category->getTuitions()->add($tuition); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$this->repository->persist($category); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$this->addFlash('success', 'admin.tuition_grades.assign.success'); |
|
52
|
|
|
return $this->redirectToRoute('admin_tuition_grades'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $this->render('admin/tuition_grades/assign.html.twig', [ |
|
56
|
|
|
'form' => $form->createView() |
|
57
|
|
|
]); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
#[Route('/add', name: 'add_tuition_grade')] |
|
61
|
|
|
public function add(Request $request): RedirectResponse|Response { |
|
62
|
|
|
$category = new TuitionGradeCategory(); |
|
63
|
|
|
$form = $this->createForm(TuitionGradeCategoryType::class, $category); |
|
64
|
|
|
$form->handleRequest($request); |
|
65
|
|
|
|
|
66
|
|
|
if($form->isSubmitted() && $form->isValid()) { |
|
67
|
|
|
$this->repository->persist($category); |
|
68
|
|
|
$this->addFlash('success', 'admin.grade_tuitions.add.success'); |
|
69
|
|
|
|
|
70
|
|
|
return $this->redirectToRoute('admin_tuition_grades'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $this->render('admin/tuition_grades/add.html.twig', [ |
|
74
|
|
|
'form' => $form->createView() |
|
75
|
|
|
]); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
#[Route('/{uuid}/edit', name: 'edit_tuition_grade')] |
|
79
|
|
|
public function edit(TuitionGradeCategory $category, Request $request): RedirectResponse|Response { |
|
80
|
|
|
$form = $this->createForm(TuitionGradeCategoryType::class, $category); |
|
81
|
|
|
$form->handleRequest($request); |
|
82
|
|
|
|
|
83
|
|
|
if($form->isSubmitted() && $form->isValid()) { |
|
84
|
|
|
$this->repository->persist($category); |
|
85
|
|
|
$this->addFlash('success', 'admin.grade_tuitions.edit.success'); |
|
86
|
|
|
|
|
87
|
|
|
return $this->redirectToRoute('admin_tuition_grades'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $this->render('admin/tuition_grades/edit.html.twig', [ |
|
91
|
|
|
'form' => $form->createView(), |
|
92
|
|
|
'category' => $category |
|
93
|
|
|
]); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
#[Route('/{uuid}/remove', name: 'remove_tuition_grade')] |
|
97
|
|
|
public function remove(): RedirectResponse|Response { |
|
98
|
|
|
|
|
99
|
|
|
} |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
} |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: