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