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