Example #1
0
 public function indexAction()
 {
     $_request = new Request();
     $title = MetaHelper::setPageTitle('Главная(admin)');
     $login_form = new LoginForm($_request);
     $errors = array();
     if ($_request->isPost()) {
         if ($login_form->validate()) {
             $user = new UserModel();
             $login = $_request->post('login');
             $hash_password = new Password($_request->post('password'));
             $res = $user->getUser($login, $hash_password);
             if (!$res) {
                 $msg = "No such user";
             } else {
                 Session::set('user', $res);
                 $msg = "You have successfully logged in!";
             }
             Session::setFlash($msg);
         } else {
             $errors = $login_form->showErrors();
         }
     }
     $model = new WeatherModel();
     $data = $model->getSourcelist();
     $args = ['errors' => $errors, 'data' => $data, 'page_title' => $title];
     return $this->render('index.phtml', $args, 'admin');
 }
Example #2
0
 public function informerAction()
 {
     $model = new WeatherModel();
     $yandex_xml = $model->getXmlYandexForecast();
     $yandex_default_values = $model->getDefaultYandexValues();
     $default_value = Cookie::get('city_id') ? Cookie::get('city_id') : $yandex_default_values['default_value'];
     $weather = new Weather($yandex_xml['weather_source'], $default_value);
     $data = $weather->xmlProcessing();
     $city_name = array_shift($data);
     $args = ['data' => $data, 'city_name' => $city_name];
     return $this->weatherRender('informer.phtml', $args);
 }
Example #3
0
 public function changeCityAction()
 {
     $request = new Request();
     $model = new WeatherModel();
     $yandex_xml = $model->getXmlYandexForecast();
     $city_id = $request->post('city_id');
     /*
      * Getting weather report for city
      */
     $weather = new Weather($yandex_xml['weather_source'], $city_id);
     $data = $weather->xmlProcessing();
     $city_name = array_shift($data);
     $args = ['data' => $data, 'city_name' => $city_name];
     /*
      * Rendering page with city
      */
     return $this->weatherRender('result.phtml', $args);
 }
 public function saveCitiesFromXmlAction()
 {
     $title = MetaHelper::setPageTitle('Загрузить города');
     $request = new Request();
     $model = new WeatherModel();
     $msg = '';
     if ($request->isPost()) {
         if ($request->post('submit')) {
             $data = Weather::parseXmlCitiesList($request->post('cities_source'));
             ini_set('max_execution_time', 900);
             foreach ($data as $value) {
                 $model->saveCitiesInDb($value['id'], $value, $value['country']);
             }
             if ($model == true) {
                 $msg = 'Загружено';
             } else {
                 $msg = 'Ошибка загрузки';
             }
         }
     }
     $args = ['page_title' => $title, 'msg' => $msg];
     return $this->render('saveCitiesFromXml.phtml', $args, 'admin');
 }