]> Raphaël G. Git Repositories - airbundle/blob - DataFixtures/AirFixtures.php
Update index name
[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 ],
173 [
174 'title' => 'Tino-Rossi garden',
175 'short' => 'Docks',
176 'address' => '2 Quai Saint-Bernard',
177 'zipcode' => '75005',
178 'city' => 'Paris',
179 'latitude' => 48.847736,
180 'longitude' => 2.360953,
181 'hotspot' => true
182 ],
183 [
184 'title' => 'Trocadero esplanade',
185 'short' => 'Trocadero',
186 'address' => '1 Avenue Hussein 1er de Jordanie',
187 #75016 pour meteo-france, accuweather supporte 75116
188 'zipcode' => '75116',
189 'city' => 'Paris',
190 'latitude' => 48.861888,
191 'longitude' => 2.288853,
192 'hotspot' => false
193 ],
194 [
195 'title' => 'Colette place',
196 'short' => 'Colette',
197 'address' => 'Galerie du Théâtre Français',
198 'zipcode' => '75001',
199 'city' => 'Paris',
200 'latitude' => 48.863219,
201 'longitude' => 2.335847,
202 'hotspot' => false
203 ],
204 [
205 'title' => 'Swan island',
206 'short' => 'Swan',
207 'address' => 'Allée des Cygnes',
208 'zipcode' => '75015',
209 'city' => 'Paris',
210 'latitude' => 48.849976, #48.849976
211 'longitude' => 2.279603, #2.2796029,
212 'hotspot' => false
213 ],
214 [
215 'title' => 'Jussieu esplanade',
216 'short' => 'Jussieu',
217 'address' => '25 rue des Fossés Saint-Bernard',
218 'zipcode' => '75005',
219 'city' => 'Paris',
220 'latitude' => 48.847955, #48.8479548
221 'longitude' => 2.353291, #2.3532907,
222 'hotspot' => false
223 ],
224 [
225 'title' => 'Orleans gallery',
226 'short' => 'Orleans',
227 'address' => '8 Galerie du Jardin',
228 'zipcode' => '75001',
229 'city' => 'Paris',
230 'latitude' => 48.863885,
231 'longitude' => 2.337387,
232 'hotspot' => false
233 ],
234 [
235 'title' => 'Orsay museum',
236 'short' => 'Orsay',
237 'address' => '1 rue de la Légion d\'Honneur',
238 'zipcode' => '75007',
239 'city' => 'Paris',
240 'latitude' => 48.860418,
241 'longitude' => 2.325815,
242 'hotspot' => false
243 ],
244 [
245 'title' => 'Saint-Honore market',
246 'short' => 'Honore',
247 'address' => '1 Passage des Jacobins',
248 'zipcode' => '75001',
249 'city' => 'Paris',
250 'latitude' => 48.866992,
251 'longitude' => 2.331752,
252 'hotspot' => false
253 ],
254 [
255 'title' => 'Igor Stravinsky place',
256 'short' => 'Stravinsky',
257 'address' => '2 rue Brisemiche',
258 'zipcode' => '75004',
259 'city' => 'Paris',
260 'latitude' => 48.859244,
261 'longitude' => 2.351289,
262 'hotspot' => false
263 ],
264 [
265 'title' => 'Tokyo palace',
266 'short' => 'Tokyo',
267 'address' => '14 Avenue de New York',
268 'zipcode' => '75116',
269 'city' => 'Paris',
270 'latitude' => 48.863827,
271 'longitude' => 2.297339,
272 'hotspot' => false
273 ],
274 [
275 'title' => 'Drawings\' garden',
276 'short' => 'Villette',
277 'address' => 'Allée du Belvédère',
278 'zipcode' => '75019',
279 'city' => 'Paris',
280 'latitude' => 48.892503,
281 'longitude' => 2.389300,
282 'hotspot' => false
283 ],
284 [
285 'title' => 'Louvre palace',
286 'short' => 'Louvre',
287 'address' => 'Quai François Mitterrand',
288 'zipcode' => '75001',
289 'city' => 'Paris',
290 'latitude' => 48.860386,
291 'longitude' => 2.332611,
292 'hotspot' => false
293 ],
294 [
295 'title' => 'Monde garden',
296 'short' => 'Monde',
297 'address' => '63 avenue Pierre Mendès-France',
298 'zipcode' => '75013',
299 'city' => 'Paris',
300 'latitude' => 48.840451,
301 'longitude' => 2.367638,
302 'hotspot' => false
303 ]
304 ];
305
306 //Create locations
307 $locations = [];
308 foreach($locationTree as $locationData) {
309 $location = new Location();
310 $location->setTitle($locationData['title']);
311 $location->setShort($locationData['short']);
312 $location->setAddress($locationData['address']);
313 $location->setZipcode($locationData['zipcode']);
314 $location->setCity($locationData['city']);
315 $location->setLatitude($locationData['latitude']);
316 $location->setLongitude($locationData['longitude']);
317 $location->setHotspot($locationData['hotspot']);
318 $manager->persist($location);
319 $locations[$locationData['title']] = $location;
320 unset($location);
321 }
322
323 //Flush to get the ids
324 $manager->flush();
325
326 //Slot tree
327 $slotTree = [
328 'Morning',
329 'Afternoon',
330 'Evening',
331 'After'
332 ];
333
334 //Create slots
335 $slots = [];
336 foreach($slotTree as $slotData) {
337 $slot = new Slot($slotData);
338 $manager->persist($slot);
339 $slots[$slot->getId()] = $slot;
340 unset($slot);
341 }
342
343 //Flush to get the ids
344 $manager->flush();
345 }
346 }