|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Anax\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
|
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
|
7
|
|
|
|
|
8
|
|
|
// use Anax\Route\Exception\ForbiddenException; |
|
9
|
|
|
// use Anax\Route\Exception\NotFoundException; |
|
10
|
|
|
// use Anax\Route\Exception\InternalErrorException; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* A controller for the Weather route. |
|
14
|
|
|
* |
|
15
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
|
16
|
|
|
*/ |
|
17
|
|
|
class WeatherController implements ContainerInjectableInterface |
|
18
|
|
|
{ |
|
19
|
|
|
use ContainerInjectableTrait; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var object $model initializes to the main model class |
|
23
|
|
|
*/ |
|
24
|
|
|
public $model; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Init method for /v-json route |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
30
|
|
|
*/ |
|
31
|
2 |
|
public function initialize() |
|
32
|
|
|
{ |
|
33
|
2 |
|
$this->model = new \Anax\Weather\WeatherModel; |
|
34
|
2 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Front page for the weather application |
|
38
|
|
|
* |
|
39
|
|
|
* @return object the index page |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function indexAction() |
|
42
|
|
|
{ |
|
43
|
1 |
|
$session = $this->di->get("session"); |
|
44
|
1 |
|
$page = $this->di->get("page"); |
|
45
|
1 |
|
$apiRes = ($session->has('apiRes')) ? $session->get("apiRes") : ""; |
|
46
|
1 |
|
$weather = $this->di->get("weather"); |
|
47
|
1 |
|
$test = $session->get('test'); |
|
48
|
1 |
|
$page->add( |
|
49
|
1 |
|
ANAX_INSTALL_PATH . "/view/weather/index", // "anax/v2/weather/index" |
|
50
|
|
|
[ |
|
51
|
1 |
|
"jsonData" => $session->get('jsonData'), |
|
52
|
1 |
|
"locationData" => $session->get('locationData'), |
|
53
|
1 |
|
"weather" => $weather->hello(), |
|
54
|
1 |
|
"apiRes" => $apiRes, |
|
55
|
1 |
|
"search" => $session->get('search'), |
|
56
|
1 |
|
"test" => $test, |
|
57
|
|
|
] |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
1 |
|
return $page->render([ |
|
61
|
1 |
|
"title" => "Väder app", |
|
62
|
|
|
]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Handles and parses Post data then redirect the user back to the routes |
|
67
|
|
|
* index page. |
|
68
|
|
|
* |
|
69
|
|
|
* @return object redirect to the routes index. |
|
70
|
|
|
*/ |
|
71
|
1 |
|
public function locationActionPost() |
|
72
|
|
|
{ |
|
73
|
1 |
|
$search = $this->di->get("request")->getPost('location') ?? ""; |
|
74
|
1 |
|
$location = $this->di->get("weather")->geocode($search); |
|
75
|
1 |
|
$jsonData = $this->model->getData($location); |
|
76
|
1 |
|
$test = $this->model->multiCurl(30, $search); |
|
77
|
|
|
|
|
78
|
1 |
|
$this->di->get("session")->set('jsonData', $jsonData); |
|
79
|
1 |
|
$this->di->get("session")->set('locationData', $location); |
|
80
|
1 |
|
$this->di->get("session")->set('search', $search); |
|
81
|
1 |
|
$this->di->get("session")->set('test', $test); |
|
82
|
|
|
|
|
83
|
1 |
|
return $this->di->get("response")->redirect("vader"); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|