]> Raphaël G. Git Repositories - airbundle/blob - DataFixtures/AirFixtures.php
Initial import
[airbundle] / DataFixtures / AirFixtures.php
1 <?php
2
3 namespace Rapsys\AirBundle\DataFixtures;
4
5 use Rapsys\AirBundle\Entity\Title;
6 use Rapsys\AirBundle\Entity\Group;
7 use Rapsys\AirBundle\Entity\User;
8 use Rapsys\AirBundle\Entity\Location;
9 use Rapsys\AirBundle\Entity\Slot;
10
11 class AirFixtures extends \Doctrine\Bundle\FixturesBundle\Fixture implements \Symfony\Component\DependencyInjection\ContainerAwareInterface {
12 /**
13 * @var ContainerInterface
14 */
15 private $container;
16
17 public function setContainer(\Symfony\Component\DependencyInjection\ContainerInterface $container = null)
18 {
19 $this->container = $container;
20 }
21
22 /**
23 * {@inheritDoc}
24 */
25 public function load(\Doctrine\Common\Persistence\ObjectManager $manager) {
26 $encoder = $this->container->get('security.password_encoder');
27
28 //Title tree
29 $titleTree = array(
30 'M.' => 'Monsieur',
31 'Mlle' => 'Mademoiselle',
32 'Mme' => 'Madame'
33 );
34
35 //Create titles
36 $titles = array();
37 foreach($titleTree as $shortData => $titleData) {
38 $title = new Title();
39 $title->setShort($shortData);
40 $title->setTitle($titleData);
41 $title->setCreated(new \DateTime('now'));
42 $title->setUpdated(new \DateTime('now'));
43 $manager->persist($title);
44 $titles[$shortData] = $title;
45 unset($title);
46 }
47
48 //Group tree
49 $groupTree = array(
50 'ROLE_USER',
51 'ROLE_ADMIN',
52 'ROLE_SUPER'
53 );
54
55 //Create groups
56 $groups = array();
57 foreach($groupTree as $groupData) {
58 $group = new Group($groupData);
59 $group->setCreated(new \DateTime('now'));
60 $group->setUpdated(new \DateTime('now'));
61 $manager->persist($group);
62 $groups[$groupData] = $group;
63 unset($group);
64 }
65
66 //Flush to get the ids
67 $manager->flush();
68
69 //User tree
70 $userTree = array(
71 array(
72 'short' => 'M.',
73 'group' => 'ROLE_SUPER',
74 'mail' => 'airlibre@rapsys.eu',
75 'pseudonym' => 'Rapsys',
76 'forename' => 'Raphaël',
77 'surname' => 'Gertz',
78 'password' => 'test'
79 ),
80 array(
81 'short' => 'M.',
82 'group' => 'ROLE_ADMIN',
83 'mail' => 'rannou402@orange.fr',
84 'pseudonym' => 'Mitch',
85 'forename' => 'Michel',
86 'surname' => 'Rannou',
87 'password' => 'test'
88 ),
89 array(
90 'short' => 'Mlle',
91 'group' => 'ROLE_ADMIN',
92 'mail' => 'roxmaps@gmail.com',
93 'pseudonym' => 'Roxana',
94 'forename' => 'Roxana',
95 'surname' => 'Prado',
96 'password' => 'test'
97 ),
98 array(
99 'short' => 'M.',
100 'group' => 'ROLE_ADMIN',
101 'mail' => 'majid.ghedjatti@gmail.com',
102 'pseudonym' => 'El Guerrillero',
103 'forename' => 'Majid',
104 'surname' => 'Ghedjatti',
105 'password' => 'test'
106 ),
107 array(
108 'short' => 'M.',
109 'group' => 'ROLE_ADMIN',
110 'mail' => 'denis.courvoisier@wanadoo.fr',
111 'pseudonym' => 'Sined',
112 'forename' => 'Denis',
113 'surname' => 'Courvoisier',
114 'password' => 'test'
115 ),
116 array(
117 'short' => 'M.',
118 'group' => 'ROLE_ADMIN',
119 'mail' => 'kastango13@gmail.com',
120 'pseudonym' => 'Kastrat',
121 'forename' => 'Kastrat',
122 'surname' => 'Hasaj',
123 'password' => 'test'
124 ),
125 );
126
127 //Create users
128 $users = array();
129 foreach($userTree as $userData) {
130 $user = new User();
131 $user->setMail($userData['mail']);
132 $user->setPseudonym($userData['pseudonym']);
133 $user->setForename($userData['forename']);
134 $user->setSurname($userData['surname']);
135 $user->setPassword($encoder->encodePassword($user, $userData['password']));
136 $user->setActive(true);
137 $user->setTitle($titles[$userData['short']]);
138 $user->addGroup($groups[$userData['group']]);
139 $user->setCreated(new \DateTime('now'));
140 $user->setUpdated(new \DateTime('now'));
141 $manager->persist($user);
142 $users[] = $user;
143 unset($user);
144 }
145
146 //Flush to get the ids
147 $manager->flush();
148
149 //Location tree
150 $locationTree = [
151 [
152 'title' => 'Esplanade du Trocadéro',
153 'address' => '1 Avenue Hussein 1er de Jordanie',
154 #75016 pour meteo-france, accuweather supporte 75116
155 'zipcode' => '75116',
156 'city' => 'Paris',
157 'latitude' => 48.8619,
158 'longitude' => 2.2888
159 ],
160 [
161 'title' => 'Opéra Garnier',
162 'address' => 'Place de l\'Opéra',
163 'zipcode' => '75009',
164 'city' => 'Paris',
165 'latitude' => 48.871365,
166 'longitude' => 2.332026
167 ],
168 [
169 'title' => 'Marché Saint Honoré',
170 'address' => '1 Passage des Jacobins',
171 'zipcode' => '75001',
172 'city' => 'Paris',
173 'latitude' => 48.8668,
174 'longitude' => 2.331659
175 ],
176 [
177 'title' => 'Jardin Tino-Rossi',
178 'address' => '2 Quai Saint-Bernard',
179 'zipcode' => '75005',
180 'city' => 'Paris',
181 'latitude' => 48.847736,
182 'longitude' => 2.360953
183 ],
184 [
185 'title' => 'Palais de Tokyo',
186 'address' => '13 Avenue du Président Wilson',
187 'zipcode' => '75116',
188 'city' => 'Paris',
189 'latitude' => 48.864567,
190 'longitude' => 2.296892
191 ]
192 ];
193
194 //Create locations
195 $locations = array();
196 foreach($locationTree as $locationData) {
197 $location = new Location();
198 $location->setTitle($locationData['title']);
199 $location->setAddress($locationData['address']);
200 $location->setZipcode($locationData['zipcode']);
201 $location->setCity($locationData['city']);
202 $location->setLatitude($locationData['latitude']);
203 $location->setLongitude($locationData['longitude']);
204 $location->setCreated(new \DateTime('now'));
205 $location->setUpdated(new \DateTime('now'));
206 $manager->persist($location);
207 $locations[$locationData['title']] = $location;
208 unset($location);
209 }
210
211 //Flush to get the ids
212 $manager->flush();
213
214 //Slot tree
215 $slotTree = [
216 [
217 'begin' => '14:00:00 UTC',
218 'end' => '19:00:00 UTC'
219 ],
220 [
221 'begin' => '19:00:00 UTC',
222 'end' => '23:00:00 UTC'
223 ],
224 [
225 'begin' => '23:00:00 UTC',
226 'end' => '02:00:00 UTC'
227 ]
228 ];
229
230 //Create slots
231 $slots = array();
232 foreach($slotTree as $slotData) {
233 $slot = new Slot();
234 $slot->setBegin(new \DateTime($slotData['begin']));
235 $slot->setEnd(new \DateTime($slotData['end']));
236 $slot->setCreated(new \DateTime('now'));
237 $slot->setUpdated(new \DateTime('now'));
238 $manager->persist($slot);
239 $slots[$slot->getId()] = $slot;
240 unset($slot);
241 }
242
243 //Flush to get the ids
244 $manager->flush();
245 }
246 }