1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the TheAlternativeZurich/events 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\Entity\Event; |
15
|
|
|
use App\Entity\Registration; |
16
|
|
|
use App\Entity\User; |
17
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture; |
18
|
|
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; |
19
|
|
|
use Doctrine\Persistence\ObjectManager; |
20
|
|
|
|
21
|
|
|
class EventFixtures extends Fixture implements OrderedFixtureInterface |
22
|
|
|
{ |
23
|
|
|
const ORDER = UserFixtures::ORDER + 1; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @throws \Exception |
27
|
|
|
*/ |
28
|
|
|
public function load(ObjectManager $manager) |
29
|
|
|
{ |
30
|
|
|
/** @var User $user */ |
31
|
|
|
$user = $this->getReference(UserFixtures::TESTER_REFERENCE); |
32
|
|
|
|
33
|
|
|
$entries = [ |
34
|
|
|
['TheAlternative', 'Console Toolkit', 'Learn how to master the console!', '2020-12-22T18:00:00'], |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
foreach ($entries as $entry) { |
38
|
|
|
$event = new Event(); |
39
|
|
|
$event->setOrganizer($entry[0]); |
40
|
|
|
$event->setName($entry[1]); |
41
|
|
|
$event->setDescription($entry[2]); |
42
|
|
|
$event->setStartDate(new \DateTime($entry[3])); |
43
|
|
|
$manager->getRepository(Event::class)->save($event); |
44
|
|
|
|
45
|
|
|
$registration = Registration::createFromUser($event, $user, true); |
46
|
|
|
$registrationRepository = $manager->getRepository(Registration::class); |
47
|
|
|
$registrationRepository->save($registration); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$manager->flush(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getOrder() |
54
|
|
|
{ |
55
|
|
|
return self::ORDER; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|