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