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