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 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)); }