1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\DataFixtures; |
4
|
|
|
|
5
|
|
|
use App\Entity\Guild; |
6
|
|
|
use App\Entity\Setting; |
7
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
8
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class LoadSettings |
12
|
|
|
* @package App\DataFixtures |
13
|
|
|
*/ |
14
|
|
|
class LoadSettings extends Fixture |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @param ObjectManager $manager |
18
|
|
|
*/ |
19
|
|
|
public function load(ObjectManager $manager) |
20
|
|
|
{ |
21
|
|
|
$this->loadSettings($manager); |
22
|
|
|
$this->loadGuild($manager); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return array |
27
|
|
|
*/ |
28
|
|
|
private function getData(): array |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
|
|
['SWGOH', 'swgoh', 'https://swgoh.gg', '/u', '/g'] |
32
|
|
|
]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
private function getGuildData(): array |
39
|
|
|
{ |
40
|
|
|
return [ |
41
|
|
|
['Tears of Wrath', '20375', 'tears-of-wrath'] |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param ObjectManager $manager |
47
|
|
|
*/ |
48
|
|
|
private function loadSettings(ObjectManager $manager): void |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
foreach ($this->getData() as [$title, $code, $api, $user, $guild]) { |
51
|
|
|
$setting = new Setting(); |
52
|
|
|
$setting->setTitle($title) |
|
|
|
|
53
|
|
|
->setCode($code) |
|
|
|
|
54
|
|
|
->setApi($api) |
|
|
|
|
55
|
|
|
->setUserSuffix($user) |
|
|
|
|
56
|
|
|
->setGuildSuffix($guild); |
|
|
|
|
57
|
|
|
|
58
|
|
|
$manager->persist($setting); |
59
|
|
|
$this->addReference(sprintf("%s-api", $title), $setting); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$manager->flush(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param ObjectManager $manager |
67
|
|
|
*/ |
68
|
|
|
private function loadGuild(ObjectManager $manager): void |
69
|
|
|
{ |
70
|
|
|
foreach ($this->getGuildData() as [$title, $uuid, $code]) { |
71
|
|
|
$setting = new Guild(); |
72
|
|
|
$setting->setUuid($title) |
|
|
|
|
73
|
|
|
->setUuid($uuid) |
|
|
|
|
74
|
|
|
->setCode($code) |
|
|
|
|
75
|
|
|
->setTitle($title); |
76
|
|
|
|
77
|
|
|
$manager->persist($setting); |
78
|
|
|
$this->addReference(sprintf("%s-guild", $code), $setting); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$manager->flush(); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|