|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the feedback 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\Semester; |
|
17
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
|
19
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
|
20
|
|
|
|
|
21
|
|
|
class LoadEvent extends BaseFixture |
|
22
|
|
|
{ |
|
23
|
|
|
const ORDER = LoadSemester::ORDER + 1; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var SerializerInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $serializer; |
|
29
|
|
|
|
|
30
|
|
|
private $publicDir; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* LoadEvent constructor. |
|
34
|
|
|
* |
|
35
|
|
|
* @param SerializerInterface $serializer |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(SerializerInterface $serializer, ParameterBagInterface $parameterBag) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->serializer = $serializer; |
|
40
|
|
|
$this->publicDir = $parameterBag->get('PUBLIC_DIR'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Load data fixtures with the passed EntityManager. |
|
45
|
|
|
* |
|
46
|
|
|
* @param ObjectManager $manager |
|
47
|
|
|
*/ |
|
48
|
|
|
public function load(ObjectManager $manager) |
|
49
|
|
|
{ |
|
50
|
|
|
$templateName = 'default.json'; |
|
51
|
|
|
$template = file_get_contents($this->publicDir . '/templates/' . $templateName); |
|
52
|
|
|
$semesters = $manager->getRepository(Semester::class)->findAll(); |
|
53
|
|
|
foreach ($semesters as $semester) { |
|
54
|
|
|
/** @var Event[] $events */ |
|
55
|
|
|
$events = $this->serializer->deserialize(file_get_contents(__DIR__ . '/Resources/events.json'), Event::class, 'json'); |
|
56
|
|
|
foreach ($events as $event) { |
|
57
|
|
|
$event->setSemester($semester); |
|
58
|
|
|
$event->setTemplateName($templateName); |
|
59
|
|
|
$event->setTemplate($template); |
|
60
|
|
|
$manager->persist($event); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$manager->flush(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get the order of this fixture. |
|
69
|
|
|
* |
|
70
|
|
|
* @return int |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getOrder() |
|
73
|
|
|
{ |
|
74
|
|
|
return static::ORDER; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|