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 Json route. |
14
|
|
|
* |
15
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
16
|
|
|
*/ |
17
|
|
|
class WeatherJsonController 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\WeatherJsonModel; |
34
|
2 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Front page for the weather application |
38
|
|
|
* |
39
|
|
|
* @return object index page |
40
|
|
|
*/ |
41
|
1 |
|
public function indexAction() |
42
|
|
|
{ |
43
|
1 |
|
$page = $this->di->get("page"); |
44
|
1 |
|
$page->add( |
45
|
1 |
|
"view/weather/explainJson", // anax/v2/weather/explainJson |
46
|
|
|
[ |
47
|
1 |
|
"title" => "Väder app", |
48
|
|
|
] |
49
|
|
|
); |
50
|
|
|
|
51
|
1 |
|
return $page->render([ |
52
|
1 |
|
"title" => "Väder app", |
53
|
|
|
]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Returns a Json response with the weather data. |
58
|
|
|
* |
59
|
|
|
* @param string $pos forecase/[pos], can be zip, adress and so on. |
60
|
|
|
* |
61
|
|
|
* @return array with the weather data. |
62
|
|
|
*/ |
63
|
1 |
|
public function forecastActionGet(string $pos = "") : array |
64
|
|
|
{ |
65
|
1 |
|
$request = $this->di->get("request"); |
66
|
1 |
|
$days = $request->getGet('days') ?? "30"; |
67
|
1 |
|
$apiRes = $this->model->getAllData($pos, $days); |
68
|
|
|
|
69
|
1 |
|
return [$apiRes]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|