public static function saveOther(Apartment $ad) { if (ApartmentVideo::saveVideo($ad)) { $ad->panoramaFile = CUploadedFile::getInstance($ad, 'panoramaFile'); $ad->scenario = 'panorama'; if (!$ad->validate()) { return false; } } $city = ""; if (issetModule('location')) { $city .= $ad->locCountry ? $ad->locCountry->getStrByLang('name') : ""; $city .= $city && $ad->locCity ? ", " : ""; $city .= $ad->locCity ? $ad->locCity->getStrByLang('name') : ""; } else { $city = $ad->city ? $ad->city->getStrByLang('name') : ""; } // data if ($ad->address && $city && (param('useGoogleMap', 1) || param('useYandexMap', 1) || param('useOSMMap', 1))) { if (!$ad->lat && !$ad->lng) { # уже есть $coords = Geocoding::getCoordsByAddress($ad->address, $city); if (isset($coords['lat']) && isset($coords['lng'])) { $ad->lat = $coords['lat']; $ad->lng = $coords['lng']; } } } return true; }
{ public $province; public $city; public $district; public $street; public $address; } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } $longitude = test_input($_GET["long"]); $latitude = test_input($_GET["lat"]); $result = Geocoding::getAddressComponent($ak, $longitude, $latitude, Geocoding::NO_POIS); $locat = new Location(); $address = $result["result"]["addressComponent"]; if ($address["province"] != $address["city"]) { $location = $address["province"] . $address["city"] . $address["district"] . $address["street"]; } else { $location = $address["city"] . $address["district"] . $address["street"]; } $locat->province = $address["province"]; $locat->city = $address["city"]; $locat->district = $address["district"]; $locat->street = $address["street"]; $locat->address = $location; $json = json_encode($locat); echo "{$json}";
foreach ($address as $index => $val) { // とりあえず無視 if (strcmp($val['region'], '以下に掲載がない場合') === 0) { continue; } $address_name = $value['pref'] . $val['city'] . $val['region']; $api = 'http://www.geocoding.jp/api/?q=' . $address_name; try { $contents = file_get_contents($api); // APIエラーが良く発生する //@todo APIがXMLで返すからXMLパース //@todo APIエラー時のリトライ処理 //@todo 正常なデータが返却された時のデータ投入 $xml = simplexml_load_string($contents); $lng = $xml->coordinate->lng[0]; $lat = $xml->coordinate->lat[0]; echo $lng; echo $lat; exit; } catch (Exception $e) { var_dump($e); exit; } echo "\n"; } exit; } } } $class = new Geocoding(); $class->main();
public function actionUpdate($id) { $this->setActiveMenu('my_listings'); $model = $this->loadModelUserAd($id); if (issetModule('bookingcalendar')) { $model = $model->with(array('bookingCalendar')); } $this->performAjaxValidation($model); if (isset($_GET['type'])) { $type = self::getReqType(); $model->type = $type; } if (isset($_POST[$this->modelName])) { $originalActive = $model->active; $model->attributes = $_POST[$this->modelName]; if ($model->type != Apartment::TYPE_BUY && $model->type != Apartment::TYPE_RENTING) { // video $videoFileValidate = true; if (isset($_FILES[$this->modelName]['name']['video_file']) && $_FILES[$this->modelName]['name']['video_file']) { $model->scenario = 'video_file'; if ($model->validate()) { $model->videoUpload = CUploadedFile::getInstance($model, 'video_file'); $videoFile = md5(uniqid()) . '.' . $model->videoUpload->extensionName; $pathVideo = Yii::getPathOfAlias('webroot.uploads.video') . DIRECTORY_SEPARATOR . $id; if (newFolder($pathVideo)) { $model->videoUpload->saveAs($pathVideo . '/' . $videoFile); $sql = 'INSERT INTO {{apartment_video}} (apartment_id, video_file, video_html, date_updated) VALUES ("' . $id . '", "' . $videoFile . '", "", NOW())'; Yii::app()->db->createCommand($sql)->execute(); } else { Yii::app()->user->setFlash('error', tt('not_create_folder_to_save.', 'apartments')); $this->redirect(array('update', 'id' => $id)); } } else { $videoFileValidate = false; } } if ($videoFileValidate) { // html code $videoHtmlValidate = true; if (isset($_POST[$this->modelName]['video_html']) && $_POST[$this->modelName]['video_html']) { $model->video_html = $_POST[$this->modelName]['video_html']; $model->scenario = 'video_html'; if ($model->validate()) { $sql = 'INSERT INTO {{apartment_video}} (apartment_id, video_file, video_html, date_updated) VALUES ("' . $id . '", "", "' . CHtml::encode($model->video_html) . '", NOW())'; Yii::app()->db->createCommand($sql)->execute(); } else { $videoHtmlValidate = false; } } } if ($videoFileValidate && $videoHtmlValidate) { $panoramaValidate = true; $model->panoramaFile = CUploadedFile::getInstance($model, 'panoramaFile'); $model->scenario = 'panorama'; if (!$model->validate()) { $panoramaValidate = false; } } $city = ""; if (issetModule('location') && param('useLocation', 1)) { $city .= $model->locCountry ? $model->locCountry->getStrByLang('name') : ""; $city .= $city && $model->locCity ? ", " : ""; $city .= $model->locCity ? $model->locCity->getStrByLang('name') : ""; } else { $city = $model->city ? $model->city->getStrByLang('name') : ""; } // data if ($videoFileValidate && $videoHtmlValidate && $panoramaValidate) { if ($model->address && $city && (param('useGoogleMap', 1) || param('useYandexMap', 1) || param('useOSMMap', 1))) { if (!$model->lat && !$model->lng) { # уже есть $coords = Geocoding::getCoordsByAddress($model->address, $city); if (isset($coords['lat']) && isset($coords['lng'])) { $model->lat = $coords['lat']; $model->lng = $coords['lng']; } } } } } $model->scenario = 'savecat'; $model->owner_active = Apartment::STATUS_ACTIVE; $isUpdate = Yii::app()->request->getPost('is_update'); if ($isUpdate) { $model->save(false); } elseif ($model->validate()) { if (param('useUseradsModeration', 1)) { $model->active = Apartment::STATUS_MODERATION; } else { $model->active = Apartment::STATUS_ACTIVE; } if ($model->save(false)) { $this->redirect(array('/apartments/main/view', 'id' => $model->id)); } } else { $model->active = $originalActive; } } $model->getCategoriesForUpdate(); if ($model->active == Apartment::STATUS_DRAFT) { Yii::app()->user->setState('menu_active', 'apartments.create'); $this->render('create', array('model' => $model, 'supportvideoext' => ApartmentVideo::model()->supportExt, 'supportvideomaxsize' => ApartmentVideo::model()->fileMaxSize)); return; } $this->render('update', array('model' => $model, 'supportvideoext' => ApartmentVideo::model()->supportExt, 'supportvideomaxsize' => ApartmentVideo::model()->fileMaxSize)); }