]> Raphaël G. Git Repositories - airbundle/blob - DataFixtures/AirFixtures.php
Switch to new base body template
[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 $groupTree = array(
50 'ROLE_USER',
51 'ROLE_GUEST',
52 'ROLE_REGULAR',
53 'ROLE_SENIOR',
54 'ROLE_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' => 'ROLE_ADMIN',
76 'mail' => 'tango@rapsys.eu',
77 'pseudonym' => 'Rapsys',
78 'forename' => 'Raphaël',
79 'surname' => 'Gertz',
80 'phone' => '+33677952829',
81 'password' => 'test'
82 ),
83 array(
84 'short' => 'Mr.',
85 'group' => 'ROLE_SENIOR',
86 'mail' => 'rannou402@orange.fr',
87 'pseudonym' => 'Mitch',
88 'forename' => 'Michel',
89 'surname' => 'Rannou',
90 'phone' => '+33600000000',
91 'password' => 'test'
92 ),
93 array(
94 'short' => 'Ms.',
95 'group' => 'ROLE_REGULAR',
96 'mail' => 'roxmaps@gmail.com',
97 'pseudonym' => 'Roxana',
98 'forename' => 'Roxana',
99 'surname' => 'Prado',
100 'phone' => '+33600000000',
101 'password' => 'test'
102 ),
103 array(
104 'short' => 'Mr.',
105 'group' => 'ROLE_REGULAR',
106 'mail' => 'majid.ghedjatti@gmail.com',
107 'pseudonym' => 'El Guerrillero',
108 'forename' => 'Majid',
109 'surname' => 'Ghedjatti',
110 'phone' => '+33600000000',
111 'password' => 'test'
112 ),
113 array(
114 'short' => 'Mr.',
115 'group' => 'ROLE_SENIOR',
116 'mail' => 'denis.courvoisier@wanadoo.fr',
117 'pseudonym' => 'Sined',
118 'forename' => 'Denis',
119 'surname' => 'Courvoisier',
120 'phone' => '+33600000000',
121 'password' => 'test'
122 ),
123 array(
124 'short' => 'Mr.',
125 'group' => 'ROLE_REGULAR',
126 'mail' => 'kastango13@gmail.com',
127 'pseudonym' => 'Kastrat',
128 'forename' => 'Kastrat',
129 'surname' => 'Hasaj',
130 'phone' => '+33600000000',
131 'password' => 'test'
132 ),
133 );
134
135 //Create users
136 $users = array();
137 foreach($userTree as $userData) {
138 $user = new User();
139 $user->setMail($userData['mail']);
140 $user->setPseudonym($userData['pseudonym']);
141 $user->setForename($userData['forename']);
142 $user->setSurname($userData['surname']);
143 $user->setPhone($userData['phone']);
144 $user->setPassword($encoder->encodePassword($user, $userData['password']));
145 $user->setActive(true);
146 $user->setTitle($titles[$userData['short']]);
147 $user->addGroup($groups[$userData['group']]);
148 $user->setCreated(new \DateTime('now'));
149 $user->setUpdated(new \DateTime('now'));
150 $manager->persist($user);
151 $users[] = $user;
152 unset($user);
153 }
154
155 //Flush to get the ids
156 $manager->flush();
157
158 //Location tree
159 $locationTree = [
160 [
161 'title' => 'Opéra Garnier',
162 'address' => '10 Place de l\'Opéra',
163 'zipcode' => '75009',
164 'city' => 'Paris',
165 'latitude' => 48.871268,
166 'longitude' => 2.331832
167 ],
168 [
169 'title' => 'Jardin Tino-Rossi',
170 'address' => '2 Quai Saint-Bernard',
171 'zipcode' => '75005',
172 'city' => 'Paris',
173 'latitude' => 48.847736,
174 'longitude' => 2.360953
175 ],
176 [
177 'title' => 'Esplanade du Trocadéro',
178 'address' => '1 Avenue Hussein 1er de Jordanie',
179 #75016 pour meteo-france, accuweather supporte 75116
180 'zipcode' => '75116',
181 'city' => 'Paris',
182 'latitude' => 48.861888,
183 'longitude' => 2.288853
184 ],
185 [
186 'title' => 'Marché Saint Honoré',
187 'address' => '1 Passage des Jacobins',
188 'zipcode' => '75001',
189 'city' => 'Paris',
190 'latitude' => 48.866992,
191 'longitude' => 2.331752
192 ],
193 [
194 'title' => 'Palais de Tokyo',
195 'address' => '14 Avenue de New York',
196 'zipcode' => '75116',
197 'city' => 'Paris',
198 'latitude' => 48.863827,
199 'longitude' => 2.297339
200 ]
201 ];
202
203 //Create locations
204 $locations = array();
205 foreach($locationTree as $locationData) {
206 $location = new Location();
207 $location->setTitle($locationData['title']);
208 $location->setAddress($locationData['address']);
209 $location->setZipcode($locationData['zipcode']);
210 $location->setCity($locationData['city']);
211 $location->setLatitude($locationData['latitude']);
212 $location->setLongitude($locationData['longitude']);
213 $location->setCreated(new \DateTime('now'));
214 $location->setUpdated(new \DateTime('now'));
215 $manager->persist($location);
216 $locations[$locationData['title']] = $location;
217 unset($location);
218 }
219
220 //Flush to get the ids
221 $manager->flush();
222
223 //Slot tree
224 $slotTree = [
225 [
226 'begin' => '14:00:00 UTC',
227 'length' => '05:00:00'
228 ],
229 [
230 'begin' => '19:00:00 UTC',
231 'length' => '06:00:00'
232 ],
233 [
234 'begin' => '19:00:00 UTC',
235 'length' => '07:00:00'
236 ]
237 ];
238
239 //Create slots
240 $slots = array();
241 foreach($slotTree as $slotData) {
242 $slot = new Slot();
243 $slot->setBegin(new \DateTime($slotData['begin']));
244 $slot->setLength(new \DateTime($slotData['length']));
245 $slot->setCreated(new \DateTime('now'));
246 $slot->setUpdated(new \DateTime('now'));
247 $manager->persist($slot);
248 $slots[$slot->getId()] = $slot;
249 unset($slot);
250 }
251
252 //Flush to get the ids
253 $manager->flush();
254 }
255 }