public function setGeocode($code_list, $foreignTable, $foreignId, $memberId)
 {
     $newcode_list = array();
     foreach ($code_list as $code) {
         $newcode_list[$code] = $code;
     }
     foreach ($this->getCodeList($foreignTable, $foreignId) as $geocode) {
         if (!in_array($geocode->getGeocode(), $code_list)) {
             $geocode->delete();
         } else {
             unset($newcode_list[$geocode->getGeocode()]);
         }
     }
     foreach ($newcode_list as $code) {
         $code = explode(',', $code);
         if (count($code) == 2) {
             $obj = new Geocode();
             $obj->setForeignId($foreignId);
             $obj->setForeignTable($foreignTable);
             $obj->setLat($code[0]);
             $obj->setLng($code[1]);
             $obj->setMemberId($memberId);
             $obj->save();
             $obj->free(true);
             unset($obj);
         }
     }
 }
Esempio n. 2
0
 /**
  * Сохранение новых данных в локальной БД
  *
  * @param float $latitude
  * @param dloat $longitude
  * @param string $lang
  * @param string $address
  */
 public function setToBase($latitude, $longitude, $lang = 'ru', $address)
 {
     if (empty($address)) {
         return false;
     }
     $_ = new Geocode();
     $_->latitude = $latitude;
     $_->longitude = $longitude;
     $_->lng = strtoupper($lang);
     $_->address = $address;
     return $_->save();
 }
Esempio n. 3
0
 /**
  * Displays the map with the availiable screens
  */
 public function actionMap()
 {
     $model = Screen::model()->with('geocodes', 'yeshuv', 'commercials')->findAll();
     $array = array();
     date_default_timezone_set('Asia/Jerusalem');
     $now = new DateTime();
     $now = $now->modify("-10 minutes");
     $id = 0;
     $green = 0;
     foreach ($model as $m) {
         $color = "red";
         $screenAjax = ScreenAjax::model()->findByPk($m->id);
         if ($screenAjax) {
             $last = strtotime($screenAjax->last_date);
             if ($last > $now->getTimestamp()) {
                 $color = "green";
                 $green++;
             }
         }
         if (count($m->geocodes) < 1) {
             $geocode = new Geocode();
             $location = Screen::model()->geocodeLookup($m->name . ',' . $m->yeshuv->name_heb);
             $geocode->lat = $location['lat'];
             $geocode->lng = $location['lng'];
             if ($geocode->save()) {
                 $screenGeocode = new ScreenGeocodeAssignment();
                 $screenGeocode->screen_id = $m->id;
                 $screenGeocode->geocode_id = $geocode->id;
                 $screenGeocode->save();
             }
             $marker = array('id' => $id++, 'name' => $m->name . ', ' . $m->yeshuv->name_heb, 'url' => $m->webkey_nickname, 'lat' => $geocode->lat, 'lng' => $geocode->lng, 'commercial' => $m->commercials[0]->name, 'color' => $color);
             array_push($array, $marker);
         } else {
             $marker = array('id' => $id++, 'name' => $m->name . ', ' . $m->yeshuv->name_heb, 'url' => $m->webkey_nickname, 'lat' => $m->geocodes[0]->lat, 'lng' => $m->geocodes[0]->lng, 'commercial' => $m->commercials[0]->name, 'color' => $color);
             array_push($array, $marker);
         }
     }
     $this->render('map', array('markers' => $array, 'green' => $green));
 }
Esempio n. 4
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Screen();
     $weather = new Weather();
     $commercial = new Commercial();
     $theme = new Theme();
     $geocode = new Geocode();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Screen'])) {
         $model->attributes = $_POST['Screen'];
         if ($model->save()) {
             if (isset($_POST['Weather'])) {
                 $weather->attributes = $_POST['Weather'];
                 $screenWeather = new ScreenWeather();
                 $screenWeather->code = $weather->code;
                 $screenWeather->screen_id = $model->id;
                 if ($screenWeather->save()) {
                     Yii::app()->user->setFlash('success', Yii::t('screen', 'Weather code assigned successfully.'));
                 } else {
                     Yii::app()->user->setFlash('error', Yii::t('screen', 'Could not assign the Weather Code to the Screen.'));
                 }
             }
             if (isset($_POST['Commercial'])) {
                 $commercial->attributes = $_POST['Commercial'];
                 $screenCommercial = new ScreenCommercialAssignment();
                 $screenCommercial->commercial_id = $commercial->id;
                 $screenCommercial->screen_id = $model->id;
                 if ($screenCommercial->save()) {
                     Yii::app()->user->setFlash('success', Yii::t('screen', 'Commercial Area assigned successfully.'));
                 } else {
                     Yii::app()->user->setFlash('error', Yii::t('screen', 'Could not assign the Commercial Area to the Screen.'));
                 }
             }
             if (isset($_POST['Theme'])) {
                 $theme->attributes = $_POST['Theme'];
                 $screenTheme = new ScreenThemeAssignment();
                 $screenTheme->theme_id = $theme->id;
                 $screenTheme->screen_id = $model->id;
                 if ($screenTheme->save()) {
                     Yii::app()->user->setFlash('success', Yii::t('screen', 'Theme assigned successfully.'));
                 } else {
                     Yii::app()->user->setFlash('error', Yii::t('screen', 'Could not assign the theme to the Screen.'));
                 }
             }
             // Create geocode and insert the lng and lat and assign it to the screen
             $location = $model->geocodeLookup($model->name . ',' . $model->yeshuv->name_heb);
             $geocode->lat = $location['lat'];
             $geocode->lng = $location['lng'];
             if ($geocode->save()) {
                 $screenGeocode = new ScreenGeocodeAssignment();
                 $screenGeocode->screen_id = $model->id;
                 $screenGeocode->geocode_id = $geocode->id;
                 if ($screenGeocode->save()) {
                     Yii::app()->user->setFlash('success', Yii::t('screen', 'Geocode assigned successfully.'));
                 }
             } else {
                 Yii::app()->user->setFlash('error', Yii::t('screen', 'Could not assign the Geocode to the Screen.'));
             }
             Yii::app()->user->setFlash('success', Yii::t('screen', 'Screen created successfully.'));
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model, 'weather' => $weather, 'commercial' => $commercial, 'theme' => $theme));
 }