|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\DataFixtures; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\Room; |
|
6
|
|
|
use App\Entity\StudyGroup; |
|
7
|
|
|
use App\Entity\Substitution; |
|
8
|
|
|
use App\Entity\Teacher; |
|
9
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture; |
|
10
|
|
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface; |
|
11
|
|
|
use Doctrine\Persistence\ObjectManager; |
|
12
|
|
|
use Faker\Generator; |
|
13
|
|
|
use SchulIT\CommonBundle\Helper\DateHelper; |
|
14
|
|
|
|
|
15
|
|
|
class SubstitutionFixtures extends Fixture implements DependentFixtureInterface { |
|
16
|
|
|
|
|
17
|
|
|
public function __construct(private RoomGenerator $roomGenerator, private Generator $generator, private DateHelper $dateHelper) |
|
18
|
|
|
{ |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function load(ObjectManager $manager) { |
|
22
|
|
|
$subjects = [ 'M', 'D', 'E', 'IF', 'MU', 'F0', 'PH' ]; |
|
23
|
|
|
$rooms = $manager->getRepository(Room::class)->findAll(); |
|
24
|
|
|
$types = [ 'Raumvertretung', 'Entfall', 'Vertretung', null ]; |
|
25
|
|
|
$studyGroups = $manager->getRepository(StudyGroup::class)->findAll(); |
|
26
|
|
|
$teachers = $manager->getRepository(Teacher::class)->findAll(); |
|
27
|
|
|
$dates = $this->dateHelper->getListOfNextDays(7); |
|
28
|
|
|
$id = 1; |
|
29
|
|
|
|
|
30
|
|
|
foreach($studyGroups as $studyGroup) { |
|
31
|
|
|
if($this->generator->boolean) { |
|
32
|
|
|
$start = $this->generator->numberBetween(1, 8); |
|
33
|
|
|
$end = $this->generator->numberBetween($start, 8); |
|
34
|
|
|
|
|
35
|
|
|
$substitution = (new Substitution()) |
|
36
|
|
|
->setLessonStart($start) |
|
37
|
|
|
->setLessonEnd($end) |
|
38
|
|
|
->setDate($this->generator->randomElement($dates)) |
|
|
|
|
|
|
39
|
|
|
->setSubject($this->generator->randomElement($subjects)) |
|
40
|
|
|
->setType($this->generator->randomElement($types)) |
|
41
|
|
|
->setExternalId(sprintf('substitution-%d', $id)); |
|
42
|
|
|
|
|
43
|
|
|
$substitution->addTeacher($this->generator->randomElement($teachers)); |
|
44
|
|
|
|
|
45
|
|
|
if($this->generator->boolean) { |
|
46
|
|
|
$teacher = $this->generator->randomElement($teachers); |
|
47
|
|
|
|
|
48
|
|
|
if(!$substitution->getTeachers()->contains($teacher)) { |
|
49
|
|
|
$substitution->addTeacher($teacher); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if($this->generator->boolean) { |
|
54
|
|
|
$substitution->setRoom($this->generator->randomElement($rooms)); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if($this->generator->boolean) { |
|
58
|
|
|
$substitution->setReplacementRoom($this->generator->randomElement($rooms)); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if($this->generator->boolean) { |
|
62
|
|
|
$substitution->setReplacementSubject($this->generator->randomElement($subjects)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if($this->generator->boolean(70)) { |
|
66
|
|
|
$substitution->addReplacementTeacher($this->generator->randomElement($teachers)); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if($this->generator->boolean) { |
|
70
|
|
|
$substitution->setRemark($this->generator->text(100)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$substitution->addStudyGroup($studyGroup); |
|
74
|
|
|
|
|
75
|
|
|
if($this->generator->boolean) { |
|
76
|
|
|
$additionalStudyGroup = $this->generator->randomElement($studyGroups); |
|
77
|
|
|
|
|
78
|
|
|
if($additionalStudyGroup->getId() !== $studyGroup->getId()) { |
|
79
|
|
|
$substitution->addStudyGroup($additionalStudyGroup); |
|
80
|
|
|
} |
|
81
|
|
|
$substitution->addReplacementStudyGroup($this->generator->randomElement($studyGroups)); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$manager->persist($substitution); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$id++; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
for($i = 0; $i < 100; $i++) { |
|
91
|
|
|
$start = $this->generator->numberBetween(1, 8); |
|
92
|
|
|
|
|
93
|
|
|
$substitution = (new Substitution()) |
|
94
|
|
|
->setStartsBefore(true) |
|
95
|
|
|
->setLessonStart($start) |
|
96
|
|
|
->setLessonEnd($start) |
|
97
|
|
|
->setDate($this->generator->randomElement($dates)) |
|
98
|
|
|
->setType("Aufsicht") |
|
99
|
|
|
->setExternalId(sprintf('substitution-%d', $id)); |
|
100
|
|
|
|
|
101
|
|
|
$substitution->addTeacher($this->generator->randomElement($teachers)); |
|
102
|
|
|
|
|
103
|
|
|
$manager->persist($substitution); |
|
104
|
|
|
$id++; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$manager->flush(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getDependencies() { |
|
111
|
|
|
return [ |
|
112
|
|
|
StudyGroupFixtures::class, |
|
113
|
|
|
TeacherFixtures::class, |
|
114
|
|
|
RoomFixtures::class |
|
115
|
|
|
]; |
|
116
|
|
|
} |
|
117
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.