]> Raphaël G. Git Repositories - airbundle/blob - DataFixtures/AirFixtures.php
Switch to tableless
[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' => 'denis.courvoisier@wanadoo.fr',
88 'pseudonym' => 'Sined',
89 'forename' => 'Denis',
90 'surname' => 'Courvoisier',
91 'phone' => '+33600000000',
92 'password' => 'test'
93 ),
94 array(
95 'short' => 'Mr.',
96 'group' => 'Senior',
97 'mail' => 'rannou402@orange.fr',
98 'pseudonym' => 'Mitch',
99 'forename' => 'Michel',
100 'surname' => 'Rannou',
101 'phone' => '+33600000000',
102 'password' => 'test'
103 ),
104 array(
105 'short' => 'Ms.',
106 'group' => 'Regular',
107 'mail' => 'roxmaps@gmail.com',
108 'pseudonym' => 'Roxana',
109 'forename' => 'Roxana',
110 'surname' => 'Prado',
111 'phone' => '+33600000000',
112 'password' => 'test'
113 ),
114 );
115
116 //Create users
117 $users = array();
118 foreach($userTree as $userData) {
119 $user = new User();
120 $user->setMail($userData['mail']);
121 $user->setPseudonym($userData['pseudonym']);
122 $user->setForename($userData['forename']);
123 $user->setSurname($userData['surname']);
124 $user->setPhone($userData['phone']);
125 $user->setPassword($encoder->encodePassword($user, $userData['password']));
126 $user->setActive(true);
127 $user->setTitle($titles[$userData['short']]);
128 $user->addGroup($groups[$userData['group']]);
129 $user->setCreated(new \DateTime('now'));
130 $user->setUpdated(new \DateTime('now'));
131 $manager->persist($user);
132 $users[] = $user;
133 unset($user);
134 }
135
136 //Flush to get the ids
137 $manager->flush();
138
139 //Location tree
140 $locationTree = [
141 [
142 'title' => 'Trocadero esplanade',
143 'short' => 'Trocadero',
144 'address' => '1 Avenue Hussein 1er de Jordanie',
145 #75016 pour meteo-france, accuweather supporte 75116
146 'zipcode' => '75116',
147 'city' => 'Paris',
148 'latitude' => 48.861888,
149 'longitude' => 2.288853
150 ],
151 [
152 'title' => 'Orleans gallery',
153 'short' => 'Orleans',
154 'address' => '8 Galerie du Jardin',
155 'zipcode' => '75001',
156 'city' => 'Paris',
157 'latitude' => 48.863885,
158 'longitude' => 2.337387
159 ],
160 [
161 'title' => 'Colette square',
162 'short' => 'Colette',
163 'address' => 'Galerie du Théâtre Français',
164 'zipcode' => '75001',
165 'city' => 'Paris',
166 'latitude' => 48.863219,
167 'longitude' => 2.335847
168 ],
169 [
170 'title' => 'Tino-Rossi garden',
171 'short' => 'Docks',
172 'address' => '2 Quai Saint-Bernard',
173 'zipcode' => '75005',
174 'city' => 'Paris',
175 'latitude' => 48.847736,
176 'longitude' => 2.360953
177 ],
178 [
179 'title' => 'Drawings\' garden',
180 'short' => 'Villette',
181 'address' => 'Allée du Belvédère',
182 'zipcode' => '75019',
183 'city' => 'Paris',
184 'latitude' => 48.892503,
185 'longitude' => 2.389300
186 ],
187 [
188 'title' => 'Saint-Honore market',
189 'short' => 'St-Honore',
190 'address' => '1 Passage des Jacobins',
191 'zipcode' => '75001',
192 'city' => 'Paris',
193 'latitude' => 48.866992,
194 'longitude' => 2.331752
195 ],
196 [
197 'title' => 'Orsay museum',
198 'short' => 'Orsay',
199 'address' => '1 rue de la Légion d\'Honneur',
200 'zipcode' => '75007',
201 'city' => 'Paris',
202 'latitude' => 48.860418,
203 'longitude' => 2.325815
204 ],
205 [
206 'title' => 'Opera Garnier',
207 'short' => 'Opera',
208 'address' => '10 Place de l\'Opéra',
209 'zipcode' => '75009',
210 'city' => 'Paris',
211 'latitude' => 48.871268,
212 'longitude' => 2.331832
213 ],
214 [
215 'title' => 'Tokyo palace',
216 'short' => 'Tokyo',
217 'address' => '14 Avenue de New York',
218 'zipcode' => '75116',
219 'city' => 'Paris',
220 'latitude' => 48.863827,
221 'longitude' => 2.297339
222 ]
223 ];
224
225 //Create locations
226 $locations = array();
227 foreach($locationTree as $locationData) {
228 $location = new Location();
229 $location->setTitle($locationData['title']);
230 $location->setShort($locationData['short']);
231 $location->setAddress($locationData['address']);
232 $location->setZipcode($locationData['zipcode']);
233 $location->setCity($locationData['city']);
234 $location->setLatitude($locationData['latitude']);
235 $location->setLongitude($locationData['longitude']);
236 $location->setCreated(new \DateTime('now'));
237 $location->setUpdated(new \DateTime('now'));
238 $manager->persist($location);
239 $locations[$locationData['title']] = $location;
240 unset($location);
241 }
242
243 //Flush to get the ids
244 $manager->flush();
245
246 //Slot tree
247 $slotTree = [
248 'Morning',
249 'Afternoon',
250 'Evening',
251 'After'
252 ];
253
254 //Create slots
255 $slots = array();
256 foreach($slotTree as $slotData) {
257 $slot = new Slot();
258 $slot->setTitle($slotData);
259 $slot->setCreated(new \DateTime('now'));
260 $slot->setUpdated(new \DateTime('now'));
261 $manager->persist($slot);
262 $slots[$slot->getId()] = $slot;
263 unset($slot);
264 }
265
266 //Flush to get the ids
267 $manager->flush();
268 }
269 }