1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Anax\Weather; |
4
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
7
|
|
|
use Anax\Route\Exception\NotFoundException; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* A controller to ease with development and debugging information. |
11
|
|
|
*/ |
12
|
|
|
class WeatherController implements ContainerInjectableInterface |
13
|
|
|
{ |
14
|
|
|
use ContainerInjectableTrait; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
// private $ipHelper; |
18
|
|
|
|
19
|
3 |
|
public function initialize() |
20
|
|
|
{ |
21
|
3 |
|
$this->GetLocation = new Weatherhelper(); |
|
|
|
|
22
|
3 |
|
} |
23
|
|
|
|
24
|
|
|
|
25
|
1 |
|
public function indexAction() : object |
26
|
|
|
{ |
27
|
1 |
|
$title = "Weather"; |
28
|
1 |
|
$page = $this->di->get("page"); |
29
|
|
|
|
30
|
1 |
|
$weatherModel = $this->di->get("weatherhelper"); |
31
|
|
|
|
32
|
|
|
|
33
|
1 |
|
if ($this->di->get("request")->hasGet("ipaddress")) { |
34
|
|
|
$session = $this->di->get("session"); |
35
|
|
|
$session->set("ipaddress", $this->di->get("request")->getGet("ipaddress")); |
36
|
|
|
// $userContainer = new Weatherhelper(); |
37
|
|
|
|
38
|
|
|
$data = $weatherModel->getUsersThroughMultiCurl([30], $this->getQuery()); |
39
|
|
|
|
40
|
|
|
$ipInfo = $this->getInfo(); |
41
|
|
|
$page->add("weather/weather-result", $ipInfo); |
42
|
|
|
$page->add("weather/weather-past", $data); |
43
|
|
|
} |
44
|
1 |
|
$page->add("weather/weather-form", []); |
45
|
1 |
|
return $page->render([ |
46
|
1 |
|
"title" => $title, |
47
|
|
|
]); |
48
|
|
|
} |
49
|
|
|
|
50
|
2 |
|
public function getInfo() |
51
|
|
|
{ |
52
|
2 |
|
$session = $this->di->get("session"); |
53
|
|
|
|
54
|
2 |
|
$weatherModel = $this->di->get("weatherhelper"); |
|
|
|
|
55
|
2 |
|
$ipInfo = []; |
|
|
|
|
56
|
2 |
|
$ipAddress = $session->get("ipaddress"); |
57
|
|
|
|
58
|
2 |
|
$weatherModel = $this->di->get("weatherhelper"); |
59
|
2 |
|
$ipInfo = $weatherModel->getLocation($ipAddress); |
60
|
|
|
|
61
|
2 |
|
return $ipInfo; |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
public function getQuery() |
65
|
|
|
{ |
66
|
1 |
|
$session = $this->di->get("session"); |
67
|
1 |
|
$ipAddress = $session->get("ipaddress"); |
68
|
|
|
|
69
|
1 |
|
return $ipAddress; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|