]> Raphaël G. Git Repositories - airbundle/blob - DataFixtures/AirFixtures.php
Cleanup useless __construct and getRoles methods
[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 {
19 $this->container = $container;
20 }
21
22 /**
23 * {@inheritDoc}
24 */
25 public function load(\Doctrine\Common\Persistence\ObjectManager $manager) {
26 $encoder = $this->container->get('security.password_encoder');
27
28 //Title tree
29 $titleTree = array(
30 'Mr.' => 'Mister',
31 'Mrs.' => 'Madam',
32 'Ms.' => 'Miss'
33 );
34
35 //Create titles
36 $titles = array();
37 foreach($titleTree as $shortData => $titleData) {
38 $title = new Title();
39 $title->setShort($shortData);
40 $title->setTitle($titleData);
41 $title->setCreated(new \DateTime('now'));
42 $title->setUpdated(new \DateTime('now'));
43 $manager->persist($title);
44 $titles[$shortData] = $title;
45 unset($title);
46 }
47
48 //Group tree
49 //XXX: ROLE_XXX is required by
50 $groupTree = array(
51 'User',
52 'Guest',
53 'Regular',
54 'Senior',
55 'Admin'
56 );
57
58 //Create groups
59 $groups = array();
60 foreach($groupTree as $groupData) {
61 $group = new Group($groupData);
62 $group->setCreated(new \DateTime('now'));
63 $group->setUpdated(new \DateTime('now'));
64 $manager->persist($group);
65 $groups[$groupData] = $group;
66 unset($group);
67 }
68
69 //Flush to get the ids
70 $manager->flush();
71
72 //User tree
73 $userTree = array(
74 array(
75 'short' => 'Mr.',
76 'group' => 'Admin',
77 'mail' => 'tango@rapsys.eu',
78 'pseudonym' => 'Rapsys',
79 'forename' => 'Raphaël',
80 'surname' => 'Gertz',
81 'phone' => '+33677952829',
82 'password' => 'test'
83 ),
84 array(
85 'short' => 'Mr.',
86 'group' => 'Senior',
87 'mail' => 'rannou402@orange.fr',
88 'pseudonym' => 'Mitch',
89 'forename' => 'Michel',
90 'surname' => 'Rannou',
91 'phone' => '+33600000000',
92 'password' => 'test'
93 ),
94 array(
95 'short' => 'Ms.',
96 'group' => 'Regular',
97 'mail' => 'roxmaps@gmail.com',
98 'pseudonym' => 'Roxana',
99 'forename' => 'Roxana',
100 'surname' => 'Prado',
101 'phone' => '+33600000000',
102 'password' => 'test'
103 ),
104 array(
105 'short' => 'Mr.',
106 'group' => 'Regular',
107 'mail' => 'majid.ghedjatti@gmail.com',
108 'pseudonym' => 'El Guerrillero',
109 'forename' => 'Majid',
110 'surname' => 'Ghedjatti',
111 'phone' => '+33600000000',
112 'password' => 'test'
113 ),
114 array(
115 'short' => 'Mr.',
116 'group' => 'Senior',
117 'mail' => 'denis.courvoisier@wanadoo.fr',
118 'pseudonym' => 'Sined',
119 'forename' => 'Denis',
120 'surname' => 'Courvoisier',
121 'phone' => '+33600000000',
122 'password' => 'test'
123 ),
124 array(
125 'short' => 'Mr.',
126 'group' => 'Regular',
127 'mail' => 'kastango13@gmail.com',
128 'pseudonym' => 'Kastrat',
129 'forename' => 'Kastrat',
130 'surname' => 'Hasaj',
131 'phone' => '+33600000000',
132 'password' => 'test'
133 ),
134 );
135
136 //Create users
137 $users = array();
138 foreach($userTree as $userData) {
139 $user = new User();
140 $user->setMail($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($encoder->encodePassword($user, $userData['password']));
146 $user->setActive(true);
147 $user->setTitle($titles[$userData['short']]);
148 $user->addGroup($groups[$userData['group']]);
149 $user->setCreated(new \DateTime('now'));
150 $user->setUpdated(new \DateTime('now'));
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 $locationTree = [
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 ],
171 [
172 'title' => 'Orleans gallery',
173 'short' => 'Orleans',
174 'address' => '8 Galerie du Jardin',
175 'zipcode' => '75001',
176 'city' => 'Paris',
177 'latitude' => 48.863885,
178 'longitude' => 2.337387
179 ],
180 [
181 'title' => 'Colette square',
182 'short' => 'Colette',
183 'address' => 'Galerie du Théâtre Français',
184 'zipcode' => '75001',
185 'city' => 'Paris',
186 'latitude' => 48.863219,
187 'longitude' => 2.335847
188 ],
189 [
190 'title' => 'Tino-Rossi garden',
191 'short' => 'Docks',
192 'address' => '2 Quai Saint-Bernard',
193 'zipcode' => '75005',
194 'city' => 'Paris',
195 'latitude' => 48.847736,
196 'longitude' => 2.360953
197 ],
198 [
199 'title' => 'Drawings\' garden',
200 'short' => 'Villette',
201 'address' => 'Allée du Belvédère',
202 'zipcode' => '75019',
203 'city' => 'Paris',
204 'latitude' => 48.892503,
205 'longitude' => 2.389300
206 ],
207 [
208 'title' => 'Saint-Honore market',
209 'short' => 'St-Honore',
210 'address' => '1 Passage des Jacobins',
211 'zipcode' => '75001',
212 'city' => 'Paris',
213 'latitude' => 48.866992,
214 'longitude' => 2.331752
215 ],
216 [
217 'title' => 'Orsay museum',
218 'short' => 'Orsay',
219 'address' => '1 rue de la Légion d\'Honneur',
220 'zipcode' => '75007',
221 'city' => 'Paris',
222 'latitude' => 48.860418,
223 'longitude' => 2.325815
224 ],
225 [
226 'title' => 'Opera Garnier',
227 'short' => 'Opera',
228 'address' => '10 Place de l\'Opéra',
229 'zipcode' => '75009',
230 'city' => 'Paris',
231 'latitude' => 48.871268,
232 'longitude' => 2.331832
233 ],
234 [
235 'title' => 'Tokyo palace',
236 'short' => 'Tokyo',
237 'address' => '14 Avenue de New York',
238 'zipcode' => '75116',
239 'city' => 'Paris',
240 'latitude' => 48.863827,
241 'longitude' => 2.297339
242 ]
243 ];
244
245 //Create locations
246 $locations = array();
247 foreach($locationTree as $locationData) {
248 $location = new Location();
249 $location->setTitle($locationData['title']);
250 $location->setShort($locationData['short']);
251 $location->setAddress($locationData['address']);
252 $location->setZipcode($locationData['zipcode']);
253 $location->setCity($locationData['city']);
254 $location->setLatitude($locationData['latitude']);
255 $location->setLongitude($locationData['longitude']);
256 $location->setCreated(new \DateTime('now'));
257 $location->setUpdated(new \DateTime('now'));
258 $manager->persist($location);
259 $locations[$locationData['title']] = $location;
260 unset($location);
261 }
262
263 //Flush to get the ids
264 $manager->flush();
265
266 //Slot tree
267 $slotTree = [
268 'Morning',
269 'Afternoon',
270 'Evening',
271 'After'
272 ];
273
274 //Create slots
275 $slots = array();
276 foreach($slotTree as $slotData) {
277 $slot = new Slot();
278 $slot->setTitle($slotData);
279 $slot->setCreated(new \DateTime('now'));
280 $slot->setUpdated(new \DateTime('now'));
281 $manager->persist($slot);
282 $slots[$slot->getId()] = $slot;
283 unset($slot);
284 }
285
286 //Flush to get the ids
287 $manager->flush();
288 }
289 }