PageRenderTime 4ms CodeModel.GetById 11ms app.highlight 36ms RepoModel.GetById 1ms app.codeStats 1ms

/index.php

https://bitbucket.org/hermescarretero/simon-iniesta
PHP | 519 lines | 450 code | 61 blank | 8 comment | 18 complexity | a5c913ec09a8d86d079d1566e0fed719 MD5 | raw file
  1<?php
  2
  3require_once __DIR__ . '/vendor/autoload.php';
  4
  5use Symfony\Component\HttpFoundation\Request;
  6use Symfony\Component\HttpFoundation\Response;
  7use Undf\Repository\RepositoryFactory;
  8use Undf\Controller\Controller;
  9use Undf\Form\CodeType;
 10use Undf\Form\UserType;
 11
 12$app = new Silex\Application();
 13$app['debug'] = true;
 14
 15$app->register(new Silex\Provider\ServiceControllerServiceProvider());
 16
 17//Register the security provider
 18$app->register(new Silex\Provider\SessionServiceProvider());
 19$app->register(new Silex\Provider\SecurityServiceProvider(), array(
 20    'security.firewalls' => array(
 21        'admin' => array(
 22            'pattern' => '^/admin/',
 23            'form' => array('login_path' => '/login', 'check_path' => '/admin/login_check', 'default_target_path' => '/admin/lista.html'),
 24            'logout' => array('logout_path' => '/admin/logout'),
 25            'users' => array(
 26                'simoniniesta' => array('ROLE_ADMIN', 'NNWdTa9JRVAR3f7kHrDm5Uql1EPz5fDogKwL2qA7/vxAW5zeZNemtLkPfHDkhnT9oUPos2gZzR7YQnIcpUGvDw=='),
 27            ),
 28        ),
 29    )
 30));
 31
 32//Register the database
 33$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
 34    'db.options' => array(
 35        'driver' => 'pdo_mysql',
 36        'dbname' => 'simoniniesta',
 37        'host' => 'localhost',
 38        'user' => 'simoniniesta',
 39        'password' => 'EilAcyobEik5',
 40        'charset' => 'utf8',
 41        'driverOptions' => array(
 42            1002 => 'SET NAMES utf8'
 43        )
 44    )
 45));
 46//Register the form service
 47$app->register(new Silex\Provider\ValidatorServiceProvider());
 48$app->register(new Silex\Provider\FormServiceProvider());
 49$app->register(new Silex\Provider\TranslationServiceProvider(), array(
 50    'locale_fallback' => 'es',
 51));
 52
 53//Register the twig service
 54$app->register(new Silex\Provider\TwigServiceProvider(), array(
 55    'twig.path' => __DIR__ . '/src/Undf/Resources/views',
 56));
 57
 58//Register the mailing service
 59$app->register(new Silex\Provider\SwiftmailerServiceProvider(), array(
 60    'swiftmailer.options' => array(
 61        'host' => 'smtp.gmail.com',
 62        'port' => '465',
 63        'username' => 'developer@undefined.es',
 64        'password' => 'd3v3lopm3nt',
 65        'encryption' => 'ssl',
 66        'auth_mode' => 'login'
 67    )
 68));
 69
 70
 71$app['repository.factory'] = $app->share(function() use ($app) {
 72            return new RepositoryFactory($app['db']);
 73        });
 74$app['controller'] = $app->share(function() use ($app) {
 75            return new Controller($app);
 76        });
 77
 78
 79/**
 80 * Routing
 81 */
 82$app->match('/', function() use ($app) {
 83            $codeform = $app["form.factory"]->create(new CodeType());
 84
 85            return $app['twig']->render('home.twig', array(
 86                        'codeForm' => $codeform->createView(),
 87                    ));
 88        });
 89$app->post('/code.json', "controller:postCodeAction");
 90$app->post('/secondcode.json', "controller:postSecondCodeAction");
 91$app->post('/ranking.html', "controller:postRankingAction");
 92
 93$app->post('/cuestionario.html', "controller:postUserAction");
 94$app->get('/cuestionario.html', "controller:getFormAction");
 95
 96$app->get('/cuestionario-tablet.html', function() use ($app) {
 97            $form = $app['form.factory']->create(new Undf\Form\UserType);
 98            return $app['twig']->render('form_tablet.twig', array(
 99                        'userForm' => $form->createView(),
100                        'error' => false
101                    ));
102        });
103$app->post('/cuestionario-tablet.html', "controller:postTabletUserAction");
104
105$app->get('/modal.html', function(Request $request) use ($app) {
106            $firstCode = $request->query->get('code');
107            $codeform = $app["form.factory"]->create(new CodeType());
108
109            return $app['twig']->render('modal-content.twig', array(
110                        'codeForm' => $codeform->createView(),
111                        'firstCode' => $firstCode,
112                        'error' => false
113                    ));
114        });
115
116$app->get('/bases', function() use ($app) {
117            return $app['twig']->render('bases.twig');
118        });
119
120$app->get('/bases_balon', function() use ($app) {
121            return $app['twig']->render('bases_balon.twig');
122        });
123
124$app->get('/bases_tablet', function() use ($app) {
125            return $app['twig']->render('bases_tablet.twig');
126        });
127
128$app->get('/bases_descubre', function() use ($app) {
129            return $app['twig']->render('bases_descubre.twig');
130        });
131
132$app->get('/packs', function() use ($app) {
133            return $app['twig']->render('packs.twig');
134        });
135
136$app->get('/pack_camiseta', function() use ($app) {
137            return $app['twig']->render('pack_camiseta.twig');
138        });
139
140$app->get('/pack_balon', function() use ($app) {
141            return $app['twig']->render('pack_balon.twig');
142        });
143
144
145$app->get('/ranking.html', function() use ($app) {
146            return $app['twig']->render('ranking.twig');
147        });
148
149$app->get('/login', function(Request $request) use ($app) {
150            return $app['twig']->render('login.twig', array(
151                        'error' => $app['security.last_error']($request),
152                        'last_username' => $app['session']->get('_security.last_username'),
153                    ));
154        });
155
156$app->get('/admin/lista.html', function() use ($app) {
157            if(null !== $activeFilter = $app['request']->get('active')) {
158                $activeFilter = (int)$activeFilter;
159            }
160            $table = $app['repository.factory']->get('User')->findBigCodeParticipants($activeFilter);
161            return $app['twig']->render('admin/list-bigcode.twig', array(
162                        'table' => $table,
163                        'linkToExport' => 'exportar-camiseta-experiencia.php'.(is_null($activeFilter) ? '' : '?active='.$activeFilter),
164                        'title' => 'Listado de personas que han canjeado un codigo grande',
165                        'activeList' => 1,
166                        'activeZone' => 'Todo',
167                        'zones' => Undf\Repository\DelegationsRepository::getZones(),
168                        'activeFilter' => $activeFilter
169                    ));
170        });
171$app->get('/admin/lista.html/{zone}', function($zone) use ($app) {
172            if(null !== $activeFilter = $app['request']->get('active')) {
173                $activeFilter = (int)$activeFilter;
174            }
175            $delegations = array_keys(Undf\Repository\DelegationsRepository::getZoneDelegations($zone));
176            $table = $app['repository.factory']->get('User')->findBigCodeParticipantsByZone($zone, $activeFilter);
177            return $app['twig']->render('admin/list-bigcode.twig', array(
178                        'table' => $table,
179                        'linkToExport' => "/admin/exportar-camiseta-experiencia.php/$zone".(is_null($activeFilter) ? '' : '?active='.$activeFilter),
180                        'title' => 'Listado de personas que han canjeado un codigo grande',
181                        'activeList' => 1,
182                        'activeZone' => $zone,
183                        'zones' => Undf\Repository\DelegationsRepository::getZones(),
184                        'delegations' => $delegations,
185                        'activeDelegation' => 'Todo',
186                        'activeFilter' => $activeFilter
187                    ));
188        });
189
190$app->get('/admin/lista.html/{zone}/{delegation}', function($zone, $delegation) use ($app) {
191            if(null !== $activeFilter = $app['request']->get('active')) {
192                $activeFilter = (int)$activeFilter;
193            }
194            $delegations = array_keys(Undf\Repository\DelegationsRepository::getZoneDelegations($zone));
195            $table = $app['repository.factory']->get('User')->findBigCodeParticipantsByDelegation($delegation, $activeFilter);
196            return $app['twig']->render('admin/list-bigcode.twig', array(
197                        'table' => $table,
198                        'linkToExport' => "/admin/exportar-camiseta-experiencia.php/$zone/$delegation".(is_null($activeFilter) ? '' : '?active='.$activeFilter),
199                        'title' => 'Listado de personas que han canjeado un codigo grande',
200                        'activeList' => 1,
201                        'activeZone' => $zone,
202                        'zones' => Undf\Repository\DelegationsRepository::getZones(),
203                        'delegations' => $delegations,
204                        'activeDelegation' => $delegation,
205                        'activeFilter' => $activeFilter
206                    ));
207        });
208
209$app->get('/admin/lista-camiseta.html', function() use ($app) {
210            if(null !== $activeFilter = $app['request']->get('active')) {
211                $activeFilter = (int)$activeFilter;
212            }
213            $table = $app['repository.factory']->get('User')->findDoubleCodeParticipants($activeFilter);
214            return $app['twig']->render('admin/list-doublecode.twig', array(
215                        'table' => $table,
216                        'linkToExport' => 'exportar-camiseta.php'.(is_null($activeFilter) ? '' : '?active='.$activeFilter),
217                        'title' => 'Listado de personas que han canjeado dos codigos pequeños',
218                        'activeList' => 2,
219                        'activeZone' => 'Todo',
220                        'zones' => Undf\Repository\DelegationsRepository::getZones(),
221                        'activeFilter' => $activeFilter
222                    ));
223        });
224
225$app->get('/admin/lista-camiseta.html/{zone}', function($zone) use ($app) {
226            if(null !== $activeFilter = $app['request']->get('active')) {
227                $activeFilter = (int)$activeFilter;
228            }
229            $delegations = array_keys(Undf\Repository\DelegationsRepository::getZoneDelegations($zone));
230            $table = $app['repository.factory']->get('User')->findDoubleCodeParticipantsByZone($zone, $activeFilter);
231            return $app['twig']->render('admin/list-doublecode.twig', array(
232                        'table' => $table,
233                        'linkToExport' => "/admin/exportar-camiseta.php/$zone".(is_null($activeFilter) ? '' : '?active='.$activeFilter),
234                        'title' => 'Listado de personas que han canjeado un codigo grande',
235                        'activeList' => 2,
236                        'activeZone' => $zone,
237                        'zones' => Undf\Repository\DelegationsRepository::getZones(),
238                        'delegations' => $delegations,
239                        'activeDelegation' => 'Todo',
240                        'activeFilter' => $activeFilter
241                    ));
242        });
243
244$app->get('/admin/lista-camiseta.html/{zone}/{delegation}', function($zone, $delegation) use ($app) {
245            if(null !== $activeFilter = $app['request']->get('active')) {
246                $activeFilter = (int)$activeFilter;
247            }
248            $delegations = array_keys(Undf\Repository\DelegationsRepository::getZoneDelegations($zone));
249            $table = $app['repository.factory']->get('User')->findDoubleCodeParticipantsByDelegation($delegation, $activeFilter);
250            return $app['twig']->render('admin/list-doublecode.twig', array(
251                        'table' => $table,
252                        'linkToExport' => "/admin/exportar-camiseta.php/$zone/$delegation".(is_null($activeFilter) ? '' : '?active='.$activeFilter),
253                        'title' => 'Listado de personas que han canjeado un codigo grande',
254                        'activeList' => 2,
255                        'activeZone' => $zone,
256                        'zones' => Undf\Repository\DelegationsRepository::getZones(),
257                        'delegations' => $delegations,
258                        'activeDelegation' => $delegation,
259                        'activeFilter' => $activeFilter
260                    ));
261        });
262
263$app->get('/admin/lista-balon.html', function() use ($app) {
264            if(null !== $activeFilter = $app['request']->get('active')) {
265                $activeFilter = (int)$activeFilter;
266            }
267            $table = $app['repository.factory']->get('User')->findSmallCodeParticipants($activeFilter);
268            return $app['twig']->render('admin/list-smallcode.twig', array(
269                        'table' => $table,
270                        'linkToExport' => 'exportar-balon.php'.(is_null($activeFilter) ? '' : '?active='.$activeFilter),
271                        'title' => 'Listado de personas que han canjeado un codigo pequeño',
272                        'activeList' => 3,
273                        'activeZone' => 'Todo',
274                        'zones' => Undf\Repository\DelegationsRepository::getZones(),
275                        'activeFilter' => $activeFilter
276                    ));
277        });
278
279$app->get('/admin/lista-balon.html/{zone}', function($zone) use ($app) {
280            if(null !== $activeFilter = $app['request']->get('active')) {
281                $activeFilter = (int)$activeFilter;
282            }
283            $delegations = array_keys(Undf\Repository\DelegationsRepository::getZoneDelegations($zone));
284            $table = $app['repository.factory']->get('User')->findSmallCodeParticipantsByZone($zone, $activeFilter);
285            return $app['twig']->render('admin/list-smallcode.twig', array(
286                        'table' => $table,
287                        'linkToExport' => "/admin/exportar-balon.php/$zone".(is_null($activeFilter) ? '' : '?active='.$activeFilter),
288                        'title' => 'Listado de personas que han canjeado un codigo grande',
289                        'activeList' => 3,
290                        'activeZone' => $zone,
291                        'zones' => Undf\Repository\DelegationsRepository::getZones(),
292                        'delegations' => $delegations,
293                        'activeDelegation' => 'Todo',
294                        'activeFilter' => $activeFilter
295                    ));
296        });
297
298$app->get('/admin/lista-balon.html/{zone}/{delegation}', function($zone, $delegation) use ($app) {
299            if(null !== $activeFilter = $app['request']->get('active')) {
300                $activeFilter = (int)$activeFilter;
301            }
302            $delegations = array_keys(Undf\Repository\DelegationsRepository::getZoneDelegations($zone));
303            $table = $app['repository.factory']->get('User')->findSmallCodeParticipantsByDelegation($delegation, $activeFilter);
304            return $app['twig']->render('admin/list-smallcode.twig', array(
305                        'table' => $table,
306                        'linkToExport' => "/admin/exportar-balon.php/$zone/$delegation".(is_null($activeFilter) ? '' : '?active='.$activeFilter),
307                        'title' => 'Listado de personas que han canjeado un codigo grande',
308                        'activeList' => 3,
309                        'activeZone' => $zone,
310                        'zones' => Undf\Repository\DelegationsRepository::getZones(),
311                        'delegations' => $delegations,
312                        'activeDelegation' => $delegation,
313                        'activeFilter' => $activeFilter
314                    ));
315        });
316
317$app->get('/admin/lista-tablet.html', function() use ($app) {
318            $table = $app['repository.factory']->get('User')->findTabletPromoParticipants();
319            return $app['twig']->render('admin/list-tablet.twig', array(
320                        'table' => $table,
321                        'linkToExport' => 'exportar-tablet.php',
322                        'title' => 'Listado de participantes en la promocion TABLET',
323                        'activeList' => 4,
324                        'activeFilter' => null
325                    ));
326        });
327
328
329
330$app->get('/admin/exportar-camiseta-experiencia.php', function() use ($app) {
331            if(null !== $activeFilter = $app['request']->get('active')) {
332                $activeFilter = (int)$activeFilter;
333            }
334            $table = $app['repository.factory']->get('User')->findBigCodeParticipants($activeFilter);
335            $response = $app['twig']->render('admin/export-bigcode.twig', array(
336                'table' => $table,
337                    ));
338
339            $headers = array(
340                'Content-Encoding' => 'UTF-8',
341                'Content-Type' => 'application/csv; charset=UTF-8',
342                'Expires' => '0',
343                'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
344                'content-disposition' => 'attachment;filename=lista-camiseta-experiencia.csv'
345            );
346            return new Response($response, 200, $headers);
347        });
348
349$app->get('/admin/exportar-camiseta-experiencia.php/{zone}', function($zone) use ($app) {
350            if(null !== $activeFilter = $app['request']->get('active')) {
351                $activeFilter = (int)$activeFilter;
352            }
353            $table = $app['repository.factory']->get('User')->findBigCodeParticipantsByZone($zone, $activeFilter);
354            $response = $app['twig']->render('admin/export-bigcode.twig', array(
355                'table' => $table,
356                    ));
357
358            $headers = array(
359                'Content-Encoding' => 'UTF-8',
360                'Content-Type' => 'application/csv; charset=UTF-8',
361                'Expires' => '0',
362                'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
363                'content-disposition' => 'attachment;filename=lista-camiseta-experiencia.csv'
364            );
365            return new Response($response, 200, $headers);
366        });
367
368$app->get('/admin/exportar-camiseta-experiencia.php/{zone}/{delegation}', function($zone, $delegation) use ($app) {
369            if(null !== $activeFilter = $app['request']->get('active')) {
370                $activeFilter = (int)$activeFilter;
371            }
372            $table = $app['repository.factory']->get('User')->findBigCodeParticipantsByDelegation($delegation, $activeFilter);
373            $response = $app['twig']->render('admin/export-bigcode.twig', array(
374                'table' => $table,
375                    ));
376
377            $headers = array(
378                'Content-Encoding' => 'UTF-8',
379                'Content-Type' => 'application/csv; charset=UTF-8',
380                'Expires' => '0',
381                'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
382                'content-disposition' => 'attachment;filename=lista-camiseta-experiencia.csv'
383            );
384            return new Response($response, 200, $headers);
385        });
386
387$app->get('/admin/exportar-camiseta.php', function() use ($app) {
388            if(null !== $activeFilter = $app['request']->get('active')) {
389                $activeFilter = (int)$activeFilter;
390            }
391            $table = $app['repository.factory']->get('User')->findDoubleCodeParticipants($activeFilter);
392            $response = $app['twig']->render('admin/export-doublecode.twig', array(
393                'table' => $table,
394                    ));
395
396            $headers = array(
397                'Content-Encoding' => 'UTF-8',
398                'Content-Type' => 'application/csv; charset=UTF-8',
399                'Expires' => '0',
400                'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
401                'content-disposition' => 'attachment;filename=lista-camiseta.csv'
402            );
403            return new Response($response, 200, $headers);
404        });
405
406$app->get('/admin/exportar-camiseta.php/{zone}', function($zone) use ($app) {
407            if(null !== $activeFilter = $app['request']->get('active')) {
408                $activeFilter = (int)$activeFilter;
409            }
410            $table = $app['repository.factory']->get('User')->findDoubleCodeParticipantsByZone($zone, $activeFilter);
411            $response = $app['twig']->render('admin/export-doublecode.twig', array(
412                'table' => $table,
413                    ));
414
415            $headers = array(
416                'Content-Encoding' => 'UTF-8',
417                'Content-Type' => 'application/csv; charset=UTF-8',
418                'Expires' => '0',
419                'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
420                'content-disposition' => 'attachment;filename=lista-camiseta-experiencia.csv'
421            );
422            return new Response($response, 200, $headers);
423        });
424
425$app->get('/admin/exportar-camiseta.php/{zone}/{delegation}', function($zone, $delegation) use ($app) {
426            if(null !== $activeFilter = $app['request']->get('active')) {
427                $activeFilter = (int)$activeFilter;
428            }
429            $table = $app['repository.factory']->get('User')->findDoubleCodeParticipantsByDelegation($delegation, $activeFilter);
430            $response = $app['twig']->render('admin/export-doublecode.twig', array(
431                'table' => $table,
432                    ));
433
434            $headers = array(
435                'Content-Encoding' => 'UTF-8',
436                'Content-Type' => 'application/csv; charset=UTF-8',
437                'Expires' => '0',
438                'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
439                'content-disposition' => 'attachment;filename=lista-camiseta-experiencia.csv'
440            );
441            return new Response($response, 200, $headers);
442        });
443
444$app->get('/admin/exportar-balon.php', function() use ($app) {
445            if(null !== $activeFilter = $app['request']->get('active')) {
446                $activeFilter = (int)$activeFilter;
447            }
448            $table = $app['repository.factory']->get('User')->findSmallCodeParticipants($activeFilter);
449            $response = $app['twig']->render('admin/export-smallcode.twig', array(
450                'table' => $table,
451                    ));
452
453            $headers = array(
454                'Content-Encoding' => 'UTF-8',
455                'Content-Type' => 'application/csv; charset=UTF-8',
456                'Expires' => '0',
457                'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
458                'content-disposition' => 'attachment;filename=lista-balon.csv'
459            );
460            return new Response($response, 200, $headers);
461        });
462
463$app->get('/admin/exportar-balon.php/{zone}', function($zone) use ($app) {
464            if(null !== $activeFilter = $app['request']->get('active')) {
465                $activeFilter = (int)$activeFilter;
466            }
467            $table = $app['repository.factory']->get('User')->findSmallCodeParticipantsByZone($zone, $activeFilter);
468            $response = $app['twig']->render('admin/export-smallcode.twig', array(
469                'table' => $table,
470                    ));
471
472            $headers = array(
473                'Content-Encoding' => 'UTF-8',
474                'Content-Type' => 'application/csv; charset=UTF-8',
475                'Expires' => '0',
476                'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
477                'content-disposition' => 'attachment;filename=lista-camiseta-experiencia.csv'
478            );
479            return new Response($response, 200, $headers);
480        });
481
482$app->get('/admin/exportar-balon.php/{zone}/{delegation}', function($zone, $delegation) use ($app) {
483            if(null !== $activeFilter = $app['request']->get('active')) {
484                $activeFilter = (int)$activeFilter;
485            }
486            $table = $app['repository.factory']->get('User')->findSmallCodeParticipantsByDelegation($delegation, $activeFilter);
487            $response = $app['twig']->render('admin/export-smallcode.twig', array(
488                'table' => $table,
489                    ));
490
491            $headers = array(
492                'Content-Encoding' => 'UTF-8',
493                'Content-Type' => 'application/csv; charset=UTF-8',
494                'Expires' => '0',
495                'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
496                'content-disposition' => 'attachment;filename=lista-camiseta-experiencia.csv'
497            );
498            return new Response($response, 200, $headers);
499        });
500
501$app->get('/admin/exportar-tablet.php', function() use ($app) {
502            $table = $app['repository.factory']->get('User')->findTabletPromoParticipants();
503            $response = $app['twig']->render('admin/export-tablet.twig', array(
504                'table' => $table,
505                    ));
506
507            $headers = array(
508                'Content-Encoding' => 'UTF-8',
509                'Content-Type' => 'application/csv; charset=UTF-8',
510                'Expires' => '0',
511                'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
512                'content-disposition' => 'attachment;filename=lista-tablet.csv'
513            );
514            return new Response($response, 200, $headers);
515        });
516
517
518
519$app->run();