]> Raphaël G. Git Repositories - airbundle/blob - DataFixtures/AirFixtures.php
Fix map coordinates
[airbundle] / DataFixtures / AirFixtures.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys AirBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
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 Rapsys\AirBundle\DataFixtures;
13
14 use Doctrine\Bundle\FixturesBundle\Fixture;
15 use Doctrine\Persistence\ObjectManager;
16 use Symfony\Component\DependencyInjection\ContainerInterface;
17 use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
18
19 use Rapsys\AirBundle\Entity\Civility;
20 use Rapsys\AirBundle\Entity\Group;
21 use Rapsys\AirBundle\Entity\User;
22 use Rapsys\AirBundle\Entity\Location;
23 use Rapsys\AirBundle\Entity\Slot;
24
25 /**
26 * {@inheritdoc}
27 */
28 class AirFixtures extends Fixture {
29 /**
30 * Air fixtures constructor
31 */
32 public function __construct(protected ContainerInterface $container, protected UserPasswordHasherInterface $hasher) {
33 }
34
35 /**
36 * {@inheritDoc}
37 */
38 public function load(ObjectManager $manager) {
39 //Civility tree
40 $civilityTree = [
41 'Mister',
42 'Madam',
43 'Miss'
44 ];
45
46 //Create titles
47 $civilitys = [];
48 foreach($civilityTree as $civilityData) {
49 $civility = new Civility($civilityData);
50 $manager->persist($civility);
51 $civilitys[$civilityData] = $civility;
52 unset($civility);
53 }
54
55 //TODO: insert countries from https://raw.githubusercontent.com/raramuridesign/mysql-country-list/master/country-lists/mysql-country-list-detailed-info.sql
56 #CREATE TABLE `countries` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `code` varchar(2) NOT NULL, `alpha` varchar(3) NOT NULL, `title` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, `created` datetime NOT NULL, `updated` datetime NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`), UNIQUE KEY `alpha` (`alpha`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
57 #insert into countries (code, alpha, title, created, updated) select countryCode, isoAlpha3, countryName, NOW(), NOW() FROM apps_countries_detailed ORDER BY countryCode ASC, isoAlpha3 ASC;
58
59 //Dance tree
60 $danceTree = [
61 'Argentine Tango' => [
62 'Ball',
63 'Ball and class',
64 'Ball and concert',
65 'Public class',
66 'Private class'
67 ]
68 ];
69
70 //Create titles
71 $dances = [];
72 foreach($danceTree as $danceTitle => $danceData) {
73 foreach($danceData as $danceType) {
74 $dance = new Dance($danceTitle, $danceType);
75 $manager->persist($dance);
76 unset($dance);
77 }
78 }
79
80 //Letter tree
81 $letterTree = [
82 'Ball',
83 'Ball and class',
84 'Ball and concert',
85 'Public class',
86 'Private class'
87 ];
88
89 //Create letters
90 $letters = [];
91 foreach($letterTree as $letterTitle) {
92 $letter = new Letter($letterTitle);
93 $manager->persist($letter);
94 unset($letter);
95 }
96
97 //Group tree
98 //XXX: ROLE_XXX is required by
99 $groupTree = [
100 'User',
101 'Guest',
102 'Regular',
103 'Senior',
104 'Admin'
105 ];
106
107 //Create groups
108 $groups = [];
109 foreach($groupTree as $groupData) {
110 $group = new Group($groupData);
111 $manager->persist($group);
112 $groups[$groupData] = $group;
113 unset($group);
114 }
115
116 //Flush to get the ids
117 $manager->flush();
118
119 //User tree
120 $userTree = [
121 [
122 'short' => 'Mr.',
123 'group' => 'Admin',
124 'mail' => 'tango@rapsys.eu',
125 'pseudonym' => 'Milonga Raphaël',
126 'forename' => 'Raphaël',
127 'surname' => 'Gertz',
128 'phone' => '+33677952829',
129 'password' => 'test'
130 ],
131 /*[
132 'short' => 'Mr.',
133 'group' => 'Senior',
134 'mail' => 'denis.courvoisier@wanadoo.fr',
135 'pseudonym' => 'DJ Sined',
136 'forename' => 'Denis',
137 'surname' => 'Courvoisier',
138 'phone' => '+33600000000',
139 'password' => 'test'
140 ],*/
141 [
142 'short' => 'Mr.',
143 'group' => 'Senior',
144 'mail' => 'rannou402@orange.fr',
145 'pseudonym' => 'Trio Tango',
146 'forename' => 'Michel',
147 'surname' => 'Rannou',
148 'phone' => '+33600000000',
149 'password' => 'test'
150 ],
151 /*[
152 'short' => 'Ms.',
153 'group' => 'Regular',
154 'mail' => 'roxmaps@gmail.com',
155 'pseudonym' => 'Roxana',
156 'forename' => 'Roxana',
157 'surname' => 'Prado',
158 'phone' => '+33600000000',
159 'password' => 'test'
160 ],*/
161 ];
162
163 //Create users
164 $users = [];
165 foreach($userTree as $userData) {
166 $user = new User($userData['mail'], $userData['password'], $civilitys[$userData['short']], $userData['forename'], $userData['surname']);
167 #TODO: check that password is hashed correctly !!!
168 #$user->setPassword($this->hasher->hashPassword($user, $userData['password']));
169 $user->setPseudonym($userData['pseudonym']);
170 $user->setPhone($userData['phone']);
171 $user->addGroup($groups[$userData['group']]);
172 $manager->persist($user);
173 $users[] = $user;
174 unset($user);
175 }
176
177 //Flush to get the ids
178 $manager->flush();
179
180 //Location tree
181 //XXX: adding a new zipcode here requires matching accuweather uris in Command/WeatherCommand.php
182 //TODO: add descriptions as well
183 $locationTree = [
184 [
185 'title' => 'Garnier opera',
186 'short' => 'Garnier',
187 'address' => '10 Place de l\'Opéra',
188 'zipcode' => '75009',
189 'city' => 'Paris',
190 'latitude' => 48.871268,
191 'longitude' => 2.331832,
192 'hotspot' => true,
193 'indoor' => false
194 ],
195 [
196 'title' => 'Tino-Rossi garden',
197 'short' => 'Docks',
198 'address' => '2 Quai Saint-Bernard',
199 'zipcode' => '75005',
200 'city' => 'Paris',
201 'latitude' => 48.847736,
202 'longitude' => 2.360953,
203 'hotspot' => true,
204 'indoor' => false
205 ],
206 [
207 'title' => 'Trocadero esplanade',
208 'short' => 'Trocadero',
209 'address' => '1 Avenue Hussein 1er de Jordanie',
210 #75016 pour meteo-france, accuweather supporte 75116
211 'zipcode' => '75116',
212 'city' => 'Paris',
213 'latitude' => 48.861888,
214 'longitude' => 2.288853,
215 'hotspot' => false,
216 'indoor' => false
217 ],
218 [
219 'title' => 'Colette place',
220 'short' => 'Colette',
221 'address' => 'Galerie du Théâtre Français',
222 'zipcode' => '75001',
223 'city' => 'Paris',
224 'latitude' => 48.863219,
225 'longitude' => 2.335847,
226 'hotspot' => false,
227 'indoor' => false
228 ],
229 [
230 'title' => 'Swan island',
231 'short' => 'Swan',
232 'address' => 'Allée des Cygnes',
233 'zipcode' => '75015',
234 'city' => 'Paris',
235 'latitude' => 48.849976, #48.849976
236 'longitude' => 2.279603, #2.2796029,
237 'hotspot' => false,
238 'indoor' => false
239 ],
240 [
241 'title' => 'Jussieu esplanade',
242 'short' => 'Jussieu',
243 'address' => '25 rue des Fossés Saint-Bernard',
244 'zipcode' => '75005',
245 'city' => 'Paris',
246 'latitude' => 48.847955, #48.8479548
247 'longitude' => 2.353291, #2.3532907,
248 'hotspot' => false,
249 'indoor' => false
250 ],
251 [
252 'title' => 'Orleans gallery',
253 'short' => 'Orleans',
254 'address' => '8 Galerie du Jardin',
255 'zipcode' => '75001',
256 'city' => 'Paris',
257 'latitude' => 48.863885,
258 'longitude' => 2.337387,
259 'hotspot' => false,
260 'indoor' => false
261 ],
262 [
263 'title' => 'Orsay museum',
264 'short' => 'Orsay',
265 'address' => '1 rue de la Légion d\'Honneur',
266 'zipcode' => '75007',
267 'city' => 'Paris',
268 'latitude' => 48.860418,
269 'longitude' => 2.325815,
270 'hotspot' => false,
271 'indoor' => false
272 ],
273 [
274 'title' => 'Saint-Honore market',
275 'short' => 'Honore',
276 'address' => '1 Passage des Jacobins',
277 'zipcode' => '75001',
278 'city' => 'Paris',
279 'latitude' => 48.866992,
280 'longitude' => 2.331752,
281 'hotspot' => false,
282 'indoor' => false
283 ],
284 [
285 'title' => 'Igor Stravinsky place',
286 'short' => 'Stravinsky',
287 'address' => '2 rue Brisemiche',
288 'zipcode' => '75004',
289 'city' => 'Paris',
290 'latitude' => 48.859244,
291 'longitude' => 2.351289,
292 'hotspot' => false,
293 'indoor' => false
294 ],
295 [
296 'title' => 'Tokyo palace',
297 'short' => 'Tokyo',
298 'address' => '14 Avenue de New York',
299 'zipcode' => '75116',
300 'city' => 'Paris',
301 'latitude' => 48.863827,
302 'longitude' => 2.297339,
303 'hotspot' => false,
304 'indoor' => false
305 ],
306 [
307 'title' => 'Drawings\' garden',
308 'short' => 'Villette',
309 'address' => 'Allée du Belvédère',
310 'zipcode' => '75019',
311 'city' => 'Paris',
312 'latitude' => 48.892503,
313 'longitude' => 2.389300,
314 'hotspot' => false,
315 'indoor' => false
316 ],
317 [
318 'title' => 'Louvre palace',
319 'short' => 'Louvre',
320 'address' => 'Quai François Mitterrand',
321 'zipcode' => '75001',
322 'city' => 'Paris',
323 'latitude' => 48.860386,
324 'longitude' => 2.332611,
325 'hotspot' => false,
326 'indoor' => false
327 ],
328 [
329 'title' => 'Monde garden',
330 'address' => '63 avenue Pierre Mendès-France',
331 'zipcode' => '75013',
332 'city' => 'Paris',
333 'latitude' => 48.840451,
334 'longitude' => 2.367638,
335 'hotspot' => false,
336 'indoor' => false
337 ]
338 ];
339
340 //Create locations
341 $locations = [];
342 foreach($locationTree as $locationData) {
343 $location = new Location($locationData['title'], $locationData['address'], $locationData['zipcode'], $locationData['city'], $locationData['latitude'], $locationData['longitude'], $locationData['hotspot'], $locationData['indoor']);
344 $manager->persist($location);
345 $locations[$locationData['title']] = $location;
346 unset($location);
347 }
348
349 //Flush to get the ids
350 $manager->flush();
351
352 //Slot tree
353 $slotTree = [
354 'Morning',
355 'Afternoon',
356 'Evening',
357 'After'
358 ];
359
360 //Create slots
361 $slots = [];
362 foreach($slotTree as $slotData) {
363 $slot = new Slot($slotData);
364 $manager->persist($slot);
365 $slots[$slot->getId()] = $slot;
366 unset($slot);
367 }
368
369 //Flush to get the ids
370 $manager->flush();
371 }
372 }