public function editSourceAction() { $title = MetaHelper::setPageTitle('Редактировать источник'); $model = new WeatherModel(); $request = new Request(); $data = $model->getSource($request->get('id')); if ($request->post('editSource')) { $action = $model->updateSource($request->get('id'), $request->post('source_name'), $request->post('source_weather_file'), $request->post('source_cities_file'), $request->post('source_default_value')); if ($action == true) { header("Location: " . Router::getRoute('admin', 'success')); } else { header("Location: " . Router::getRoute('admin', 'fail')); } } $args = ['page_title' => $title, 'data' => $data, 'msg' => isset($msg) ? $msg : null]; return $this->render('editSource.phtml', $args, 'admin'); }
public function indexAction() { $msg = ''; $title = MetaHelper::setPageTitle('Погода'); $request = new Request(); $model = new WeatherModel(); /* * Getting Yandex weather data xml file * Getting default values */ $yandex_xml = $model->getXmlYandexForecast(); $yandex_default_values = $model->getDefaultYandexValues(); if ($request->get('submit')) { $result = $model->searchByCityName($request->get('city_search')); if ($result) { $city_id = $result['city_id']; Cookie::set('city_id', $city_id); } else { $city_id = $yandex_default_values['default_value']; $msg = 'Город не найден в списке'; } } else { $city_id = Cookie::get('city_id') ? Cookie::get('city_id') : $yandex_default_values['default_value']; } /* * Yandex xml data parsing */ $weather = new Weather($yandex_xml['weather_source'], $city_id); $data = $weather->xmlProcessing(); $city_name = array_shift($data); /* * Getting Yandex cities data */ $yandex_cities_xml = $model->getXmlYandexCities(); $countries = simplexml_load_file($yandex_cities_xml['cities_source'] . '.xml'); /* * Getting Yandex data informer */ $informer = $model->getInformerData(); $args = ['page_title' => $title, 'data' => $data, 'countries' => $countries, 'city_name' => $city_name, 'informer' => $informer, 'msg' => $msg]; /* * Rendering starting page */ return $this->render("index.phtml", $args); }