gurrabergh /
weather
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Anax\Weather; |
||
| 4 | |||
| 5 | use Anax\Commons\ContainerInjectableInterface; |
||
| 6 | use Anax\Commons\ContainerInjectableTrait; |
||
| 7 | use Anax\Ip2\IpStack; |
||
| 8 | |||
| 9 | // use Anax\Route\Exception\ForbiddenException; |
||
| 10 | // use Anax\Route\Exception\NotFoundException; |
||
| 11 | // use Anax\Route\Exception\InternalErrorException; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * A sample controller to show how a controller class can be implemented. |
||
| 15 | * The controller will be injected with $app if implementing the interface |
||
| 16 | * AppInjectableInterface, like this sample class does. |
||
| 17 | * The controller is mounted on a particular route and can then handle all |
||
| 18 | * requests for that mount point. |
||
| 19 | * |
||
| 20 | * @SuppressWarnings(PHPMD.TooManyPublicMethods) |
||
| 21 | */ |
||
| 22 | |||
| 23 | class WeatherController implements ContainerInjectableInterface |
||
| 24 | { |
||
| 25 | use ContainerInjectableTrait; |
||
| 26 | |||
| 27 | // /** |
||
| 28 | // * This is the index method action, it handles: |
||
| 29 | // * ANY METHOD mountpoint |
||
| 30 | // * ANY METHOD mountpoint/ |
||
| 31 | // * ANY METHOD mountpoint/index |
||
| 32 | // * |
||
| 33 | // * @return string |
||
| 34 | // */ |
||
| 35 | // public function initAction() : object |
||
| 36 | // { |
||
| 37 | // // init session for game start |
||
| 38 | |||
| 39 | // $this->app->session->set("game", new DiceGame()); |
||
| 40 | |||
| 41 | // return $this->app->response->redirect("diceC/play"); |
||
| 42 | // } |
||
| 43 | |||
| 44 | // /** |
||
| 45 | // * This is the index method action, it handles: |
||
| 46 | // * ANY METHOD mountpoint |
||
| 47 | // * ANY METHOD mountpoint/ |
||
| 48 | // * ANY METHOD mountpoint/index |
||
| 49 | // * |
||
| 50 | // * @return string |
||
| 51 | // */ |
||
| 52 | 1 | public function indexAction(): object |
|
| 53 | { |
||
| 54 | 1 | $title = "IP-validate"; |
|
| 55 | 1 | $page = $this->di->get("page"); |
|
| 56 | 1 | $data["ip"] = ""; |
|
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 57 | 1 | $page->add('weather/index', $data); |
|
| 58 | |||
| 59 | |||
| 60 | 1 | return $page->render([ |
|
| 61 | 1 | "title" => $title, |
|
| 62 | ]); |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * |
||
| 67 | * |
||
| 68 | * |
||
| 69 | * |
||
| 70 | * |
||
| 71 | * @return object |
||
| 72 | */ |
||
| 73 | 2 | public function searchCordActionPost(): object |
|
| 74 | { |
||
| 75 | 2 | $request = $this->di->request; |
|
|
0 ignored issues
–
show
|
|||
| 76 | 2 | $wcL = $this->di->weather; |
|
|
0 ignored issues
–
show
|
|||
| 77 | 2 | $lat = $request->getPost("lat"); |
|
| 78 | 2 | $long = $request->getPost("long"); |
|
| 79 | |||
| 80 | 2 | $data["lat"] = $lat; |
|
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 81 | 2 | $data["long"] = $long; |
|
| 82 | 2 | $data["lat1"] = floatval($lat) - 1; |
|
| 83 | 2 | $data["long1"] = floatval($long) - 2; |
|
| 84 | 2 | $data["lat2"] = floatval($lat) + 1; |
|
| 85 | 2 | $data["long2"] = floatval($long) + 2; |
|
| 86 | 2 | $weather = $wcL->getWeather($lat, $long); |
|
| 87 | 2 | $today = $weather[0]; |
|
| 88 | 2 | \array_splice($weather, 0, 1); |
|
| 89 | |||
| 90 | 2 | $data["weather"] = $weather; |
|
| 91 | 2 | $data["today"] = $today; |
|
| 92 | |||
| 93 | 2 | $page = $this->di->get("page"); |
|
| 94 | 2 | $page->add('weather/index', $data); |
|
| 95 | 2 | if (count($weather[0]) > 2) { |
|
| 96 | 1 | $page->add('weather/result', $data); |
|
| 97 | } else { |
||
| 98 | 1 | $page->add('weather/fail'); |
|
| 99 | } |
||
| 100 | 2 | $title = "IP-validate"; |
|
| 101 | |||
| 102 | 2 | return $page->render([ |
|
| 103 | 2 | "title" => $title, |
|
| 104 | ]); |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * |
||
| 109 | * |
||
| 110 | * |
||
| 111 | * |
||
| 112 | * |
||
| 113 | * @return object |
||
| 114 | */ |
||
| 115 | 3 | public function searchIpActionPost(): object |
|
| 116 | { |
||
| 117 | 3 | $ipStack = new IpStack(); |
|
| 118 | 3 | $request = $this->di->request; |
|
|
0 ignored issues
–
show
|
|||
| 119 | 3 | $ipAd = $request->getPost("ip"); |
|
| 120 | 3 | $ipW = $ipStack->getInfo($ipAd); |
|
| 121 | 3 | $lat = $ipW["lat"]; |
|
| 122 | 3 | $long = $ipW["long"]; |
|
| 123 | 3 | $wcL = $this->di->weather; |
|
|
0 ignored issues
–
show
|
|||
| 124 | |||
| 125 | 3 | $data["lat"] = $lat; |
|
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 126 | 3 | $data["long"] = $long; |
|
| 127 | 3 | $data["lat1"] = floatval($lat) - 1; |
|
| 128 | 3 | $data["long1"] = floatval($long) - 2; |
|
| 129 | 3 | $data["lat2"] = floatval($lat) + 1; |
|
| 130 | 3 | $data["long2"] = floatval($long) + 2; |
|
| 131 | 3 | $weather = $wcL->getWeather($lat, $long); |
|
| 132 | 3 | $today = $weather[0]; |
|
| 133 | 3 | \array_splice($weather, 0, 1); |
|
| 134 | |||
| 135 | 3 | $data["weather"] = $weather; |
|
| 136 | 3 | $data["today"] = $today; |
|
| 137 | |||
| 138 | 3 | $page = $this->di->get("page"); |
|
| 139 | 3 | $page->add('weather/index', $data); |
|
| 140 | 3 | if (count($weather[0]) > 2) { |
|
| 141 | 2 | $page->add('weather/result', $data); |
|
| 142 | } else { |
||
| 143 | 1 | $page->add('weather/fail'); |
|
| 144 | } |
||
| 145 | 3 | $title = "IP-validate"; |
|
| 146 | |||
| 147 | 3 | return $page->render([ |
|
| 148 | 3 | "title" => $title, |
|
| 149 | ]); |
||
| 150 | } |
||
| 151 | } |
||
| 152 |