|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\TuitionGradeType; |
|
6
|
|
|
use App\Form\TuitionGradeTypeType; |
|
7
|
|
|
use App\Repository\TuitionGradeTypeRepositoryInterface; |
|
8
|
|
|
use SchulIT\CommonBundle\Utils\RefererHelper; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
13
|
|
|
|
|
14
|
|
|
#[Route('/admin/gradebook/grades')] |
|
15
|
|
|
class TuitionGradeTypeAdminController extends AbstractController { |
|
16
|
|
|
|
|
17
|
|
|
public function __construct(private readonly TuitionGradeTypeRepositoryInterface $repository, RefererHelper $redirectHelper) { |
|
18
|
|
|
parent::__construct($redirectHelper); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
#[Route('', name: 'admin_tuition_grade_types')] |
|
22
|
|
|
public function index(): Response { |
|
23
|
|
|
return $this->render('admin/tuition_grades/types/index.html.twig', [ |
|
24
|
|
|
'types' => $this->repository->findAll() |
|
25
|
|
|
]); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
#[Route('/add', name: 'add_tuition_grade_type')] |
|
29
|
|
|
public function add(Request $request): RedirectResponse|Response { |
|
30
|
|
|
$preset = $request->query->get('preset'); |
|
31
|
|
|
$presets = [ |
|
32
|
|
|
'onetosix_notrend' => [ 1, 2, 3, 4, 5, 6 ], |
|
33
|
|
|
'onetosix_trend' => ['1+', '1', '1-', '2+', '2', '2-', '3+', '3', '3-', '4+', '4', '4-', '5+', '5', '5-', '6' ], |
|
34
|
|
|
'zerotofiveteen' => [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
$type = new TuitionGradeType(); |
|
38
|
|
|
|
|
39
|
|
|
if($preset !== null && isset($presets[$preset])) { |
|
40
|
|
|
$type->setValues($presets[$preset]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$form = $this->createForm(TuitionGradeTypeType::class, $type); |
|
44
|
|
|
$form->handleRequest($request); |
|
45
|
|
|
|
|
46
|
|
|
if($form->isSubmitted() && $form->isValid()) { |
|
47
|
|
|
$this->repository->persist($type); |
|
48
|
|
|
$this->addFlash('success', 'admin.tuition_grade_types.add.success'); |
|
49
|
|
|
|
|
50
|
|
|
return $this->redirectToRoute('admin_tuition_grade_types'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $this->render('admin/tuition_grades/types/add.html.twig', [ |
|
54
|
|
|
'form' => $form->createView() |
|
55
|
|
|
]); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
#[Route('/{uuid}/edit', name: 'edit_tuition_grade_type')] |
|
59
|
|
|
public function edit(TuitionGradeType $type, Request $request): RedirectResponse|Response { |
|
60
|
|
|
$form = $this->createForm(TuitionGradeTypeType::class, $type); |
|
61
|
|
|
$form->handleRequest($request); |
|
62
|
|
|
|
|
63
|
|
|
if($form->isSubmitted() && $form->isValid()) { |
|
64
|
|
|
$this->repository->persist($type); |
|
65
|
|
|
$this->addFlash('success', 'admin.tuition_grade_types.edit.success'); |
|
66
|
|
|
|
|
67
|
|
|
return $this->redirectToRoute('admin_tuition_grade_types'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $this->render('admin/tuition_grades/types/edit.html.twig', [ |
|
71
|
|
|
'form' => $form->createView() |
|
72
|
|
|
]); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
#[Route('/{uuid}/remove', name: 'remove_tuition_grade_type')] |
|
76
|
|
|
public function remove(): RedirectResponse|Response { |
|
77
|
|
|
|
|
78
|
|
|
} |
|
|
|
|
|
|
79
|
|
|
} |
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: