Passed
Push — master ( 2daeaa...eba4a8 )
by Marcel
16:01
created

DisplayController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 33
c 1
b 0
f 0
dl 0
loc 50
rs 10
ccs 0
cts 27
cp 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B show() 0 47 6
1
<?php
2
3
namespace App\Controller;
4
5
use App\Repository\TeacherRepositoryInterface;
6
use App\Repository\TimetableWeekRepositoryInterface;
7
use Symfony\Component\HttpFoundation\Response;
8
use App\Display\DisplayHelper;
9
use App\Entity\Display;
10
use App\Entity\DisplayTargetUserType;
11
use App\Entity\Substitution;
12
use App\Grouping\Grouper;
13
use App\Repository\AbsenceRepositoryInterface;
14
use App\Repository\AppointmentRepositoryInterface;
15
use App\Repository\ImportDateTypeRepositoryInterface;
16
use App\Repository\InfotextRepositoryInterface;
17
use App\Repository\SubstitutionRepositoryInterface;
18
use App\Sorting\AppointmentStrategy;
19
use App\Sorting\Sorter;
20
use DateTime;
21
use SchulIT\CommonBundle\Helper\DateHelper;
22
use Symfony\Component\Routing\Annotation\Route;
23
24
#[Route(path: '/display')]
25
class DisplayController extends AbstractController {
26
27
    #[Route(path: '/{uuid}', name: 'show_display')]
28
    public function show(Display $display, InfotextRepositoryInterface $infotextRepository, AbsenceRepositoryInterface $absenceRepository,
29
                         TimetableWeekRepositoryInterface $timetableWeekRepository, AppointmentRepositoryInterface $appointmentRepository,
30
                         DateHelper $dateHelper, Grouper $grouper, Sorter $sorter, DisplayHelper $displayHelper,
0 ignored issues
show
Unused Code introduced by
The parameter $grouper is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
                         DateHelper $dateHelper, /** @scrutinizer ignore-unused */ Grouper $grouper, Sorter $sorter, DisplayHelper $displayHelper,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
                         ImportDateTypeRepositoryInterface  $importDateTymeRepository, TeacherRepositoryInterface $teacherRepository): Response {
32
        $today = $dateHelper->getToday();
33
        $appointments = [ ];
34
        $groups = [ ];
35
36
        if($display->getTargetUserType() === DisplayTargetUserType::Students) {
37
            $groups = $displayHelper->getStudentsItems($today);
38
39
            $appointments = $appointmentRepository->findAllForAllStudents($today);
40
        } else if($display->getTargetUserType() === DisplayTargetUserType::Teachers) {
41
            $groups = $displayHelper->getTeachersItems($today);
42
43
            $appointments = $appointmentRepository->findAll([], null, $today);
44
        }
45
46
        $sorter->sort($appointments, AppointmentStrategy::class);
47
48
        $itemsCount = 0;
49
50
        foreach($groups as $group) {
51
            $itemsCount += is_countable($group->getItems()) ? count($group->getItems()) : 0;
52
        }
53
54
        $week = $timetableWeekRepository->findOneByWeekNumber((int)$today->format('W'));
55
56
        $birthdays = [ ];
57
        if($display->getTargetUserType() === DisplayTargetUserType::Teachers) {
58
            $birthdays = $teacherRepository->findAllByBirthday($today);
59
        }
60
61
        return $this->render('display/two_column_bottom.html.twig', [
62
            'display' => $display,
63
            'infotexts' => $infotextRepository->findAllByDate($today),
64
            'absent_studygroups' => $absenceRepository->findAllStudyGroups($today),
65
            'absent_teachers' => $absenceRepository->findAllTeachers($today),
66
            'groups' => $groups,
67
            'appointments' => $appointments,
68
            'count' => $itemsCount,
69
            'last_update' => $importDateTymeRepository->findOneByEntityClass(Substitution::class),
70
            'day' => $today,
71
            'week' => $week,
72
            'is_teachersview' => $display->getTargetUserType() === DisplayTargetUserType::Teachers,
73
            'teacher_birthdays' => $birthdays
74
        ]);
75
    }
76
}