1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace KW\KWcontroller; |
4
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
7
|
|
|
|
8
|
|
|
class WeatherController implements ContainerInjectableInterface |
9
|
|
|
{ |
10
|
|
|
use ContainerInjectableTrait; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* This is the index method action, it handles: |
15
|
|
|
* GET METHOD mountpoint |
16
|
|
|
* GET METHOD mountpoint/ |
17
|
|
|
* GET METHOD mountpoint/index |
18
|
|
|
* |
19
|
|
|
* @return object |
20
|
|
|
*/ |
21
|
|
|
public function indexActionGet() |
22
|
|
|
{ |
23
|
|
|
$page = $this->di->get("page"); |
24
|
|
|
$page->add("anax/v2/weather/formular"); |
25
|
|
|
return $page->render([ |
26
|
|
|
"title"=>"Väder" |
27
|
|
|
]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/* |
31
|
|
|
* @return object |
32
|
|
|
*/ |
33
|
|
|
public function restinfoActionGet() |
34
|
|
|
{ |
35
|
|
|
$page = $this->di->get("page"); |
36
|
|
|
$page->add("anax/v2/weather/restinfo"); |
37
|
|
|
|
38
|
|
|
return $page->render([ |
39
|
|
|
"title"=>"Väder" |
40
|
|
|
]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Return weather from darkSky |
46
|
|
|
* |
47
|
|
|
* @return object |
48
|
|
|
*/ |
49
|
|
|
public function resultActionGet() |
50
|
|
|
{ |
51
|
|
|
$longitude = null; |
|
|
|
|
52
|
|
|
$latitude = null; |
|
|
|
|
53
|
|
|
$ipn = ""; |
|
|
|
|
54
|
|
|
$longitude = $this->di->get("request")->getGet("longitude"); |
55
|
|
|
$latitude = $this->di->get("request")->getGet("latitude"); |
56
|
|
|
$type = $this->di->get("request")->getGet("type"); |
57
|
|
|
$ipn = $this->di->get("request")->getGet("ipnummer"); |
58
|
|
|
|
59
|
|
|
$darkSkyUmbrella = new \KW\Models\DarkSkyUmbrella($this->di); |
60
|
|
|
|
61
|
|
|
$res = $darkSkyUmbrella->input($longitude, $latitude, $type, $ipn); |
62
|
|
|
|
63
|
|
|
$page = $this->di->get("page"); |
64
|
|
|
$page->add("anax/v2/weather/result", [ |
65
|
|
|
"res" => $res, |
66
|
|
|
"longitude" => $longitude, |
67
|
|
|
"latitude" => $latitude, |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
return $page->render([ |
71
|
|
|
"title" => "Väderresultat" |
72
|
|
|
]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Return weather from restfully |
78
|
|
|
* |
79
|
|
|
* @return object |
80
|
|
|
*/ |
81
|
1 |
|
public function restActionGet() : array |
82
|
|
|
{ |
83
|
1 |
|
$longitude = null; |
|
|
|
|
84
|
1 |
|
$latitude = null; |
|
|
|
|
85
|
1 |
|
$ipn = ""; |
|
|
|
|
86
|
1 |
|
$longitude = $this->di->get("request")->getGet("lon"); |
87
|
1 |
|
$latitude = $this->di->get("request")->getGet("lat"); |
88
|
1 |
|
$type = $this->di->get("request")->getGet("type"); |
89
|
1 |
|
$ipn = $this->di->get("request")->getGet("ipn"); |
90
|
|
|
|
91
|
1 |
|
$darkSkyUmbrella = new \KW\Models\DarkSkyUmbrella($this->di); |
92
|
|
|
//$jsonWeather = new \KW\Models\JsonWeather; |
93
|
1 |
|
$jsonWeather = $this->di->get("jsonWeather"); |
94
|
|
|
|
95
|
1 |
|
$res1 = $darkSkyUmbrella->input($longitude, $latitude, $type, $ipn); |
96
|
1 |
|
$res = $jsonWeather->jsonify($res1); |
97
|
|
|
|
98
|
1 |
|
return $res; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|