1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* @author Xavier Chopin <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace App\Controller; |
11
|
|
|
|
12
|
|
|
use Slim\Http\Request; |
13
|
|
|
use Slim\Http\Response; |
14
|
|
|
Use App\Model\User; |
15
|
|
|
|
16
|
|
|
class AppController extends Controller |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Redirects the user to the home page with the appropriated language following the parameters given |
21
|
|
|
* |
22
|
|
|
* @param Request $request |
23
|
|
|
* @param Response $response |
24
|
|
|
* @return Response |
25
|
|
|
*/ |
26
|
|
|
public function redirectHome(Request $request, Response $response) |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
$clientLanguage = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); |
30
|
|
|
|
31
|
|
|
if (isset($_COOKIE['country']) && $this->checkCountry($_COOKIE['country'])) { // First if the client has a preference |
32
|
|
|
$country_id = $_COOKIE['country']; |
33
|
|
|
}else if ($this->checkCountry($clientLanguage)) { // Not a preference? Let's check its browser! |
34
|
|
|
$country_id = $clientLanguage; |
35
|
|
|
} else { // Nevermind let's move to the french language |
36
|
|
|
$country_id = 'fr'; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return $response->withRedirect($this->router->pathFor('home', ['country' => $country_id])); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Renders the home page |
44
|
|
|
* |
45
|
|
|
* @param Request $request |
46
|
|
|
* @param Response $response |
47
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
48
|
|
|
*/ |
49
|
|
|
public function home(Request $request, Response $response) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
return $this->view->render($response, 'App/home.twig'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Checks for a country id given if a dictionary is associated. |
57
|
|
|
* |
58
|
|
|
* @param string $country_id |
59
|
|
|
* @return bool |
60
|
|
|
*/ |
61
|
|
|
private function checkCountry($country_id) |
62
|
|
|
{ |
63
|
|
|
return file_exists(dirname(__FILE__) . '/../Resources/' . DICTIONARY_PATH . $country_id . '.json'); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.