jespernyhlen /
weather-module
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Anax\Weather; |
||
| 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 | * |
||
| 14 | * @SuppressWarnings(PHPMD.TooManyPublicMethods) |
||
| 15 | */ |
||
| 16 | class WeatherController implements ContainerInjectableInterface |
||
| 17 | { |
||
| 18 | use ContainerInjectableTrait; |
||
| 19 | |||
| 20 | |||
| 21 | /** |
||
| 22 | * This is the index method action, it handles: |
||
| 23 | * ANY METHOD mountpoint |
||
| 24 | * ANY METHOD mountpoint/ |
||
| 25 | * ANY METHOD mountpoint/index |
||
| 26 | * |
||
| 27 | * @return string |
||
| 28 | */ |
||
| 29 | 3 | public function indexAction() |
|
| 30 | { |
||
| 31 | 3 | $title = "Weather info"; |
|
| 32 | 3 | $page = $this->di->get("page"); |
|
| 33 | |||
| 34 | 3 | $CurlModel = $this->di->get("curl"); |
|
| 35 | 3 | $WeatherModel = $this->di->get("weather"); |
|
| 36 | 3 | $WeatherModel->setCurl($CurlModel); |
|
| 37 | |||
| 38 | 3 | $request = $this->di->get("request"); |
|
| 39 | |||
| 40 | 3 | $page->add("weather/form-text-weather", []); |
|
| 41 | 3 | $page->add("weather/clear", []); |
|
| 42 | |||
| 43 | 3 | if ($this->di->get("request")->hasGet("location")) { |
|
| 44 | 2 | $convertedLocation = $WeatherModel->convertLocation($request->getGet("location")); |
|
| 45 | 2 | if ($convertedLocation["match"]) { |
|
| 46 | 1 | $weatherInfo["location"] = $convertedLocation; |
|
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 47 | 1 | $weatherInfo["weather"] = $WeatherModel->getWeather($convertedLocation["latitude"], $convertedLocation["longitude"]); |
|
| 48 | 1 | $weatherInfoPast = $WeatherModel->getWeatherMulti($convertedLocation["latitude"], $convertedLocation["longitude"], 30); |
|
| 49 | 1 | $page->add("weather/location", ["location" => $weatherInfo["location"]]); |
|
| 50 | 1 | $page->add("weather/result", ["weatherinfo" => $weatherInfo]); |
|
| 51 | 1 | $page->add("weather/resultpast", ["weatherinfo" => $weatherInfoPast["data"]]); |
|
| 52 | } else { |
||
| 53 | 1 | $page->add("weather/badresult", []); |
|
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | 3 | return $page->render([ |
|
| 58 | 3 | "title" => $title, |
|
| 59 | ]); |
||
| 60 | } |
||
| 61 | } |
||
| 62 |