]> Raphaël G. Git Repositories - airbundle/blob - DataFixtures/AirFixtures.php
Register google client service and alias
[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 'Milonga', 'Class and milonga', 'Public class', 'Private class'
63 ]
64 ];
65
66 //Create titles
67 $dances = [];
68 foreach($danceTree as $danceTitle => $danceData) {
69 foreach($danceData as $danceType) {
70 $dance = new Dance($danceTitle, $danceType);
71 $manager->persist($dance);
72 unset($dance);
73 }
74 }
75
76 //Group tree
77 //XXX: ROLE_XXX is required by
78 $groupTree = [
79 'User',
80 'Guest',
81 'Regular',
82 'Senior',
83 'Admin'
84 ];
85
86 //Create groups
87 $groups = [];
88 foreach($groupTree as $groupData) {
89 $group = new Group($groupData);
90 $manager->persist($group);
91 $groups[$groupData] = $group;
92 unset($group);
93 }
94
95 //Flush to get the ids
96 $manager->flush();
97
98 //User tree
99 $userTree = [
100 [
101 'short' => 'Mr.',
102 'group' => 'Admin',
103 'mail' => 'tango@rapsys.eu',
104 'pseudonym' => 'Milonga Raphaël',
105 'forename' => 'Raphaël',
106 'surname' => 'Gertz',
107 'phone' => '+33677952829',
108 'password' => 'test'
109 ],
110 /*[
111 'short' => 'Mr.',
112 'group' => 'Senior',
113 'mail' => 'denis.courvoisier@wanadoo.fr',
114 'pseudonym' => 'DJ Sined',
115 'forename' => 'Denis',
116 'surname' => 'Courvoisier',
117 'phone' => '+33600000000',
118 'password' => 'test'
119 ],*/
120 [
121 'short' => 'Mr.',
122 'group' => 'Senior',
123 'mail' => 'rannou402@orange.fr',
124 'pseudonym' => 'Trio Tango',
125 'forename' => 'Michel',
126 'surname' => 'Rannou',
127 'phone' => '+33600000000',
128 'password' => 'test'
129 ],
130 /*[
131 'short' => 'Ms.',
132 'group' => 'Regular',
133 'mail' => 'roxmaps@gmail.com',
134 'pseudonym' => 'Roxana',
135 'forename' => 'Roxana',
136 'surname' => 'Prado',
137 'phone' => '+33600000000',
138 'password' => 'test'
139 ],*/
140 ];
141
142 //Create users
143 $users = [];
144 foreach($userTree as $userData) {
145 $user = new User($userData['mail'], $userData['password'], $civilitys[$userData['short']], $userData['forename'], $userData['surname']);
146 #TODO: check that password is hashed correctly !!!
147 #$user->setPassword($this->hasher->hashPassword($user, $userData['password']));
148 $user->setPseudonym($userData['pseudonym']);
149 $user->setPhone($userData['phone']);
150 $user->addGroup($groups[$userData['group']]);
151 $manager->persist($user);
152 $users[] = $user;
153 unset($user);
154 }
155
156 //Flush to get the ids
157 $manager->flush();
158
159 //Location tree
160 //XXX: adding a new zipcode here requires matching accuweather uris in Command/WeatherCommand.php
161 //TODO: add descriptions as well
162 $locationTree = [
163 [
164 'title' => 'Garnier opera',
165 'short' => 'Garnier',
166 'address' => '10 Place de l\'Opéra',
167 'zipcode' => '75009',
168 'city' => 'Paris',
169 'latitude' => 48.871268,
170 'longitude' => 2.331832,
171 'hotspot' => true,
172 'indoor' => false
173 ],
174 [
175 'title' => 'Tino-Rossi garden',
176 'short' => 'Docks',
177 'address' => '2 Quai Saint-Bernard',
178 'zipcode' => '75005',
179 'city' => 'Paris',
180 'latitude' => 48.847736,
181 'longitude' => 2.360953,
182 'hotspot' => true,
183 'indoor' => false
184 ],
185 [
186 'title' => 'Trocadero esplanade',
187 'short' => 'Trocadero',
188 'address' => '1 Avenue Hussein 1er de Jordanie',
189 #75016 pour meteo-france, accuweather supporte 75116
190 'zipcode' => '75116',
191 'city' => 'Paris',
192 'latitude' => 48.861888,
193 'longitude' => 2.288853,
194 'hotspot' => false,
195 'indoor' => false
196 ],
197 [
198 'title' => 'Colette place',
199 'short' => 'Colette',
200 'address' => 'Galerie du Théâtre Français',
201 'zipcode' => '75001',
202 'city' => 'Paris',
203 'latitude' => 48.863219,
204 'longitude' => 2.335847,
205 'hotspot' => false,
206 'indoor' => false
207 ],
208 [
209 'title' => 'Swan island',
210 'short' => 'Swan',
211 'address' => 'Allée des Cygnes',
212 'zipcode' => '75015',
213 'city' => 'Paris',
214 'latitude' => 48.849976, #48.849976
215 'longitude' => 2.279603, #2.2796029,
216 'hotspot' => false,
217 'indoor' => false
218 ],
219 [
220 'title' => 'Jussieu esplanade',
221 'short' => 'Jussieu',
222 'address' => '25 rue des Fossés Saint-Bernard',
223 'zipcode' => '75005',
224 'city' => 'Paris',
225 'latitude' => 48.847955, #48.8479548
226 'longitude' => 2.353291, #2.3532907,
227 'hotspot' => false,
228 'indoor' => false
229 ],
230 [
231 'title' => 'Orleans gallery',
232 'short' => 'Orleans',
233 'address' => '8 Galerie du Jardin',
234 'zipcode' => '75001',
235 'city' => 'Paris',
236 'latitude' => 48.863885,
237 'longitude' => 2.337387,
238 'hotspot' => false,
239 'indoor' => false
240 ],
241 [
242 'title' => 'Orsay museum',
243 'short' => 'Orsay',
244 'address' => '1 rue de la Légion d\'Honneur',
245 'zipcode' => '75007',
246 'city' => 'Paris',
247 'latitude' => 48.860418,
248 'longitude' => 2.325815,
249 'hotspot' => false,
250 'indoor' => false
251 ],
252 [
253 'title' => 'Saint-Honore market',
254 'short' => 'Honore',
255 'address' => '1 Passage des Jacobins',
256 'zipcode' => '75001',
257 'city' => 'Paris',
258 'latitude' => 48.866992,
259 'longitude' => 2.331752,
260 'hotspot' => false,
261 'indoor' => false
262 ],
263 [
264 'title' => 'Igor Stravinsky place',
265 'short' => 'Stravinsky',
266 'address' => '2 rue Brisemiche',
267 'zipcode' => '75004',
268 'city' => 'Paris',
269 'latitude' => 48.859244,
270 'longitude' => 2.351289,
271 'hotspot' => false,
272 'indoor' => false
273 ],
274 [
275 'title' => 'Tokyo palace',
276 'short' => 'Tokyo',
277 'address' => '14 Avenue de New York',
278 'zipcode' => '75116',
279 'city' => 'Paris',
280 'latitude' => 48.863827,
281 'longitude' => 2.297339,
282 'hotspot' => false,
283 'indoor' => false
284 ],
285 [
286 'title' => 'Drawings\' garden',
287 'short' => 'Villette',
288 'address' => 'Allée du Belvédère',
289 'zipcode' => '75019',
290 'city' => 'Paris',
291 'latitude' => 48.892503,
292 'longitude' => 2.389300,
293 'hotspot' => false,
294 'indoor' => false
295 ],
296 [
297 'title' => 'Louvre palace',
298 'short' => 'Louvre',
299 'address' => 'Quai François Mitterrand',
300 'zipcode' => '75001',
301 'city' => 'Paris',
302 'latitude' => 48.860386,
303 'longitude' => 2.332611,
304 'hotspot' => false,
305 'indoor' => false
306 ],
307 [
308 'title' => 'Monde garden',
309 'address' => '63 avenue Pierre Mendès-France',
310 'zipcode' => '75013',
311 'city' => 'Paris',
312 'latitude' => 48.840451,
313 'longitude' => 2.367638,
314 'hotspot' => false,
315 'indoor' => false
316 ]
317 ];
318
319 //Create locations
320 $locations = [];
321 foreach($locationTree as $locationData) {
322 $location = new Location($locationData['title'], $locationData['address'], $locationData['zipcode'], $locationData['city'], $locationData['latitude'], $locationData['longitude'], $locationData['hotspot'], $locationData['indoor']);
323 $manager->persist($location);
324 $locations[$locationData['title']] = $location;
325 unset($location);
326 }
327
328 //Flush to get the ids
329 $manager->flush();
330
331 //Slot tree
332 $slotTree = [
333 'Morning',
334 'Afternoon',
335 'Evening',
336 'After'
337 ];
338
339 //Create slots
340 $slots = [];
341 foreach($slotTree as $slotData) {
342 $slot = new Slot($slotData);
343 $manager->persist($slot);
344 $slots[$slot->getId()] = $slot;
345 unset($slot);
346 }
347
348 //Flush to get the ids
349 $manager->flush();
350 }
351 }