|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the vseth-semesterly-reports 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\DataFixtures; |
|
13
|
|
|
|
|
14
|
|
|
use App\DataFixtures\Base\BaseFixture; |
|
15
|
|
|
use App\Entity\Event; |
|
16
|
|
|
use App\Entity\Organisation; |
|
17
|
|
|
use App\Entity\SemesterReport; |
|
18
|
|
|
use App\Form\Type\SemesterType; |
|
19
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
20
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
|
21
|
|
|
|
|
22
|
|
|
class LoadSemesterReport extends BaseFixture |
|
23
|
|
|
{ |
|
24
|
|
|
const ORDER = LoadOrganisations::ORDER + 1; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var SerializerInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private $serializer; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* LoadEvent constructor. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(SerializerInterface $serializer) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->serializer = $serializer; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Load data fixtures with the passed EntityManager. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function load(ObjectManager $manager) |
|
43
|
|
|
{ |
|
44
|
|
|
//fill semester with events |
|
45
|
|
|
/** @var Organisation[] $organisations */ |
|
46
|
|
|
$organisations = $manager->getRepository(Organisation::class)->findAll(); |
|
47
|
|
|
|
|
48
|
|
|
$organisationCount = \count($organisations); |
|
49
|
|
|
for ($i = 0; $i < $organisationCount; ++$i) { |
|
50
|
|
|
if ($i % 3 === 0) { |
|
51
|
|
|
continue; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$semesterReport = $this->getRandomInstance(); |
|
55
|
|
|
$semesterReport->setOrganisation($organisations[$i]); |
|
56
|
|
|
$manager->persist($semesterReport); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$manager->flush(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
protected function getRandomInstance() |
|
63
|
|
|
{ |
|
64
|
|
|
$faker = $this->getFaker(); |
|
65
|
|
|
|
|
66
|
|
|
$semesterReport = new SemesterReport(); |
|
67
|
|
|
$semesterReport->setSemester(SemesterType::getCurrentSemester()); |
|
68
|
|
|
$semesterReport->setComments($faker->text(200)); |
|
69
|
|
|
$semesterReport->setPoliticalEventsDescription($faker->text(200)); |
|
70
|
|
|
$semesterReport->setSubmittedDateTime($faker->dateTimeInInterval('-1 years', '1 years')); |
|
71
|
|
|
|
|
72
|
|
|
return $semesterReport; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
private function fillWithPremadeEvents(ObjectManager $manager, Organisation $organisation) |
|
|
|
|
|
|
76
|
|
|
{ |
|
77
|
|
|
//prepare resources |
|
78
|
|
|
$json = file_get_contents(__DIR__ . '/Resources/events.json'); |
|
79
|
|
|
/** @var Event[] $events */ |
|
80
|
|
|
$events = $this->serializer->deserialize($json, Event::class . '[]', 'json'); |
|
81
|
|
|
|
|
82
|
|
|
$startDate = new \DateTime('today 18:00'); |
|
83
|
|
|
$endDate = new \DateTime('today 20:00'); |
|
84
|
|
|
foreach ($events as $event) { |
|
85
|
|
|
$event->setOrganisation($organisation); |
|
86
|
|
|
$event->setSemester(SemesterType::getCurrentSemester()); |
|
87
|
|
|
$event->setStartDate($startDate); |
|
88
|
|
|
$event->setEndDate($endDate); |
|
89
|
|
|
$manager->persist($event); |
|
90
|
|
|
|
|
91
|
|
|
$startDate = $startDate->add(new \DateInterval('P10D')); |
|
92
|
|
|
$endDate = $endDate->add(new \DateInterval('P10D')); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$manager->flush(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Get the order of this fixture. |
|
100
|
|
|
* |
|
101
|
|
|
* @return int |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getOrder() |
|
104
|
|
|
{ |
|
105
|
|
|
return static::ORDER; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
This check looks for private methods that have been defined, but are not used inside the class.