mirror of
https://github.com/danielbrendel/hortusfox-web.git
synced 2026-01-01 02:10:28 -06:00
58 lines
1.1 KiB
PHP
58 lines
1.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Class WeatherController
|
|
*
|
|
* Gateway to weather forecast actions
|
|
*/
|
|
class WeatherController extends BaseController {
|
|
const INDEX_LAYOUT = 'layout';
|
|
|
|
/**
|
|
* Perform base initialization
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct(self::INDEX_LAYOUT);
|
|
|
|
if (!app('owm_enable')) {
|
|
throw new \Exception(403);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handles URL: /weather
|
|
*
|
|
* @param Asatru\Controller\ControllerArg $request
|
|
* @return Asatru\View\ViewHandler
|
|
*/
|
|
public function view_forecast($request)
|
|
{
|
|
try {
|
|
$user = UserModel::getAuthUser();
|
|
$forecast = WeatherModule::forecast();
|
|
|
|
$weekdays = [];
|
|
for ($i = 0; $i < 5; $i++) {
|
|
$curtime = strtotime('+' . strval($i) . ' days');
|
|
|
|
$weekdays[] = [
|
|
'date' => date('Y-m-d', $curtime),
|
|
'day' => date('l', $curtime)
|
|
];
|
|
}
|
|
|
|
return parent::view(['content', 'weather'], [
|
|
'user' => $user,
|
|
'forecast' => $forecast,
|
|
'weekdays' => $weekdays
|
|
]);
|
|
} catch (\Exception $e) {
|
|
FlashMessage::setMsg('error', $e->getMessage());
|
|
return redirect('/');
|
|
}
|
|
}
|
|
}
|