|
1 |
| -<?php |
2 |
| - |
3 |
| -/** |
4 |
| - * @file |
5 |
| - * Controller for all pages in prototype. |
6 |
| - */ |
7 |
| - |
8 |
| -namespace Sheffugees\Controllers; |
9 |
| - |
10 |
| -use Silex\Application; |
11 |
| -use Symfony\Component\HttpFoundation\Request; |
12 |
| - |
13 |
| -/** |
14 |
| - * @class |
15 |
| - * All. |
16 |
| - */ |
17 |
| -class All |
18 |
| -{ |
19 |
| - /** |
20 |
| - * Callback: index, trying to choose language. |
21 |
| - */ |
22 |
| - public function index(Request $request, Application $app) |
23 |
| - { |
24 |
| - return $app['twig']->render('index.twig'); |
25 |
| - } |
26 |
| -} |
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @file |
| 5 | + * Controller for all pages in prototype. |
| 6 | + */ |
| 7 | + |
| 8 | +namespace Sheffugees\Controllers; |
| 9 | + |
| 10 | +use Silex\Application; |
| 11 | +use Symfony\Component\HttpFoundation\Request; |
| 12 | + |
| 13 | +/** |
| 14 | + * @class |
| 15 | + * All. |
| 16 | + */ |
| 17 | +class All |
| 18 | +{ |
| 19 | + /** |
| 20 | + * Page callback: welcome and pick language. |
| 21 | + */ |
| 22 | + public function index(Request $request, Application $app) |
| 23 | + { |
| 24 | + return $app['twig']->render('start.twig'); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Page callback: set location. |
| 29 | + */ |
| 30 | + public function location(Request $request, Application $app, $lang) |
| 31 | + { |
| 32 | + if (!preg_match("/^[a-z]{2}\$/", $lang)) { |
| 33 | + return $app->redirect('/'); |
| 34 | + } |
| 35 | + |
| 36 | + return $app['twig']->render("location-$lang.twig"); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Page callback: choose a need. |
| 41 | + */ |
| 42 | + public function choose(Request $request, Application $app, $lang) |
| 43 | + { |
| 44 | + if (!preg_match("/^[a-z]{2}\$/", $lang)) { |
| 45 | + return $app->redirect('/'); |
| 46 | + } |
| 47 | + |
| 48 | + return $app['twig']->render("choose-$lang.twig"); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Page callback: define a need. |
| 53 | + */ |
| 54 | + public function need(Request $request, Application $app, $lang, $need) |
| 55 | + { |
| 56 | + if (!preg_match("/^[a-z]{2}\$/", $lang)) { |
| 57 | + return $app->redirect('/'); |
| 58 | + } |
| 59 | + |
| 60 | + if (!preg_match("/^[a-z]+\$/", $need)) { |
| 61 | + return $app->redirect('/'); |
| 62 | + } |
| 63 | + |
| 64 | + |
| 65 | + return $app['twig']->render("need-$lang-$need.twig"); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Page callback: return some results. |
| 70 | + */ |
| 71 | + public function results(Request $request, Application $app, $lang, $find) |
| 72 | + { |
| 73 | + if (!preg_match("/^[a-z]{2}\$/", $lang)) { |
| 74 | + return $app->redirect('/'); |
| 75 | + } |
| 76 | + |
| 77 | + if (!preg_match("/^[a-z]+\$/", $find)) { |
| 78 | + return $app->redirect('/'); |
| 79 | + } |
| 80 | + |
| 81 | + return $app['twig']->render("results-$lang-$find.twig"); |
| 82 | + } |
| 83 | + |
| 84 | +} |
0 commit comments