1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright 2014-2018 Arnaud Bienvenu |
4
|
|
|
* |
5
|
|
|
* This file is part of Kyela. |
6
|
|
|
|
7
|
|
|
* Kyela is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
|
12
|
|
|
* Kyela is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with Kyela. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Abienvenu\KyelaBundle\Controller; |
23
|
|
|
|
24
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
25
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
26
|
|
|
use Symfony\Component\HttpFoundation\Request; |
27
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
28
|
|
|
use Symfony\Component\Yaml\Yaml; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Static content controller. |
32
|
|
|
* |
33
|
|
|
* @Route("/static") |
34
|
|
|
*/ |
35
|
|
|
class StaticController extends PollSetterController |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* Load additionnal translations |
39
|
|
|
* |
40
|
|
|
* @param string $domain |
41
|
|
|
* @param string $locale |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
protected function loadTranslations($domain, $locale) |
45
|
|
|
{ |
46
|
|
|
$r = new \ReflectionClass($this); |
47
|
|
|
$dirName = dirname($r->getFileName()); |
48
|
|
|
$fullFileName = "$dirName/../Resources/translations/$domain.$locale.yml"; |
49
|
|
|
return Yaml::parse(file_get_contents($fullFileName)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Displays the FAQ |
54
|
|
|
* |
55
|
|
|
* @Route("/faq", name="kyela_faq", methods="GET") |
56
|
|
|
* @Template() |
57
|
|
|
*/ |
58
|
|
|
public function faqAction(Request $request) |
59
|
|
|
{ |
60
|
|
|
return ["poll" => $this->poll, "faq" => $this->loadTranslations("faq", $request->getLocale())]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Displays the About page |
65
|
|
|
* |
66
|
|
|
* @Route("/about", name="kyela_about", methods="GET") |
67
|
|
|
* @Template() |
68
|
|
|
*/ |
69
|
|
|
public function aboutAction(Request $request) |
70
|
|
|
{ |
71
|
|
|
return ["poll" => $this->poll, "about" => $this->loadTranslations("about", $request->getLocale())]; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Displays the Tips page |
76
|
|
|
* |
77
|
|
|
* @Route("/tips", name="kyela_tips", methods="GET") |
78
|
|
|
* @Template() |
79
|
|
|
*/ |
80
|
|
|
public function tipsAction(Request $request) |
81
|
|
|
{ |
82
|
|
|
return ["poll" => $this->poll, "tips" => $this->loadTranslations("tips", $request->getLocale())]; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Displays the Thanks page |
87
|
|
|
* |
88
|
|
|
* @Route("/thanks", name="kyela_thanks", methods="GET") |
89
|
|
|
* @Template() |
90
|
|
|
*/ |
91
|
|
|
public function thanksAction() |
92
|
|
|
{ |
93
|
|
|
return ["poll" => $this->poll]; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Switch locale |
98
|
|
|
* |
99
|
|
|
* @Route("/switch/{_locale}", name="kyela_switch", methods="GET") |
100
|
|
|
*/ |
101
|
|
|
public function switchAction(Request $request) |
102
|
|
|
{ |
103
|
|
|
if ($request->headers->has('referer')) |
104
|
|
|
{ |
105
|
|
|
$returnUrl = $request->headers->get('referer'); |
106
|
|
|
} |
107
|
|
|
else |
108
|
|
|
{ |
109
|
|
|
$returnUrl = $this->generateUrl("poll_new"); |
110
|
|
|
} |
111
|
|
|
return new RedirectResponse($returnUrl, 302); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|