|
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\Form\Type\SemesterType; |
|
18
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
19
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
|
20
|
|
|
|
|
21
|
|
|
class LoadEvent extends BaseFixture |
|
22
|
|
|
{ |
|
23
|
|
|
const ORDER = LoadOrganisations::ORDER + 1; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var SerializerInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $serializer; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* LoadEvent constructor. |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(SerializerInterface $serializer) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->serializer = $serializer; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Load data fixtures with the passed EntityManager. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function load(ObjectManager $manager) |
|
42
|
|
|
{ |
|
43
|
|
|
//fill semester with events |
|
44
|
|
|
/** @var Organisation[] $organisations */ |
|
45
|
|
|
$organisations = $manager->getRepository(Organisation::class)->findAll(); |
|
46
|
|
|
|
|
47
|
|
|
$this->fillWithPremadeEvents($manager, $organisations[0]); |
|
48
|
|
|
|
|
49
|
|
|
$faker = $this->getFaker(); |
|
50
|
|
|
$organisationCount = \count($organisations); |
|
51
|
|
|
for ($i = 1; $i < $organisationCount; ++$i) { |
|
52
|
|
|
/** @var Event[] $randomEvents */ |
|
53
|
|
|
$randomEvents = $this->loadSomeRandoms($manager, $faker->randomFloat(0, 0, 10)); |
|
54
|
|
|
foreach ($randomEvents as $randomEvent) { |
|
55
|
|
|
$randomEvent->setOrganisation($organisations[$i]); |
|
56
|
|
|
$manager->persist($randomEvent); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$manager->flush(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
protected function getRandomInstance() |
|
64
|
|
|
{ |
|
65
|
|
|
$faker = $this->getFaker(); |
|
66
|
|
|
|
|
67
|
|
|
$lang = 'de'; |
|
68
|
|
|
if ($faker->randomDigit < 5) { |
|
69
|
|
|
$lang = 'en'; |
|
70
|
|
|
} elseif ($faker->randomDigit < 5) { |
|
71
|
|
|
$lang = 'both'; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$event = new Event(); |
|
75
|
|
|
$event->setSemester(SemesterType::getCurrentSemester()); |
|
76
|
|
|
|
|
77
|
|
|
if ($lang === 'de' || $lang === 'both') { |
|
78
|
|
|
$event->setNameDe($faker->text(40)); |
|
79
|
|
|
$event->setDescriptionDe($faker->text(100)); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if ($lang === 'en' || $lang === 'both') { |
|
83
|
|
|
$event->setNameEn($faker->text(40)); |
|
84
|
|
|
$event->setDescriptionEn($faker->text(100)); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$event->setStartDate($faker->dateTimeInInterval('-1 years', '1 years')); |
|
88
|
|
|
$event->setEndDate($faker->dateTimeInInterval($event->getStartDate()->format('c'), '+4 hours')); |
|
89
|
|
|
$event->setLocation($faker->text(20)); |
|
90
|
|
|
$event->setShowInCalender($faker->boolean(80)); |
|
91
|
|
|
|
|
92
|
|
|
if ($faker->randomDigit < 5) { |
|
93
|
|
|
$event->setRevenue(0); |
|
94
|
|
|
} else { |
|
95
|
|
|
$event->setRevenue($faker->randomNumber(3)); |
|
96
|
|
|
} |
|
97
|
|
|
$event->setNeedFinancialSupport($event->getRevenue() > 0 && $faker->randomDigit < 3); |
|
98
|
|
|
|
|
99
|
|
|
return $event; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
private function fillWithPremadeEvents(ObjectManager $manager, Organisation $organisation) |
|
103
|
|
|
{ |
|
104
|
|
|
//prepare resources |
|
105
|
|
|
$json = file_get_contents(__DIR__ . '/Resources/events.json'); |
|
106
|
|
|
/** @var Event[] $events */ |
|
107
|
|
|
$events = $this->serializer->deserialize($json, Event::class . '[]', 'json'); |
|
108
|
|
|
|
|
109
|
|
|
$startDate = new \DateTime('today 18:00'); |
|
110
|
|
|
$endDate = new \DateTime('today 20:00'); |
|
111
|
|
|
foreach ($events as $event) { |
|
112
|
|
|
$event->setOrganisation($organisation); |
|
113
|
|
|
$event->setSemester(SemesterType::getCurrentSemester()); |
|
114
|
|
|
$event->setStartDate($startDate); |
|
115
|
|
|
$event->setEndDate($endDate); |
|
116
|
|
|
$manager->persist($event); |
|
117
|
|
|
|
|
118
|
|
|
$startDate = $startDate->add(new \DateInterval('P10D')); |
|
119
|
|
|
$endDate = $endDate->add(new \DateInterval('P10D')); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$manager->flush(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Get the order of this fixture. |
|
127
|
|
|
* |
|
128
|
|
|
* @return int |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getOrder() |
|
131
|
|
|
{ |
|
132
|
|
|
return static::ORDER; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|