public function rules() { $video = ApartmentVideo::model(); $panorama = ApartmentPanorama::model(); $rules = array(array('price', 'priceValidator', 'except' => 'video_file, video_html, panorama'), array('location_id', 'locationRequired', 'except' => 'video_file, video_html, panorama'), array('title', 'i18nRequired', 'except' => 'video_file, video_html, panorama'), array('price, price_to, floor, floor_total, window_to, type, price_type, obj_type_id, city_id, activity_always', 'numerical', 'integerOnly' => true), array('square, land_square', 'numerical'), array('type', 'numerical', 'min' => 1), array('price_to', 'priceToValidator'), array('berths', 'length', 'max' => 255), array('title', 'i18nLength', 'max' => 255), array('lat, lng', 'length', 'max' => 25), array('phone', 'length', 'max' => 15), array('id', 'safe', 'on' => 'search'), array('floor', 'myFloorValidator'), array('is_price_poa', 'boolean'), array('in_currency, owner_active, num_of_rooms, is_special_offer, is_free_from, is_free_to, active, metroStations, note, period_activity, sublocation_id, region_id', 'safe'), array($this->getI18nFieldSafe(), 'safe'), array('city_id, owner_active, active, type, obj_type_id, ownerEmail, ownerUsername, popularity', 'safe', 'on' => 'search'), array('video_html', 'checkHtmlCode'), array('video_file', 'file', 'types' => $video->supportExt, 'maxSize' => $video->fileMaxSize, 'allowEmpty' => true), array('panoramaFile', 'file', 'types' => $panorama->supportedExt, 'maxSize' => $panorama->maxSize, 'tooLarge' => Yii::t('module_apartments', 'The file was larger than {size}MB. Please upload a smaller file.', array('{size}' => $panorama->maxSizeMb)), 'allowEmpty' => true)); if (issetModule('formeditor')) { Yii::import('application.modules.formeditor.models.HFormEditor'); $addRules = HFormEditor::getRulesForModel(); $rules = CMap::mergeArray($rules, $addRules); } if (issetModule('location') && param('useLocation', 1)) { $rules[] = array('loc_city, loc_region, loc_country', 'safe', 'on' => 'search'); $rules[] = array('loc_city, loc_region, loc_country', 'numerical', 'integerOnly' => true); } return $rules; }
public function actionUpdate($id) { $this->_model = $this->loadModel($id); if (!$this->_model) { throw404(); } $oldStatus = $this->_model->active; if (issetModule('bookingcalendar')) { $this->_model = $this->_model->with(array('bookingCalendar')); } if (isset($_GET['type'])) { $this->_model->type = HApartment::getRequestType(); } if (isset($_POST[$this->modelName])) { $this->_model->attributes = $_POST[$this->modelName]; if ($this->_model->type != Apartment::TYPE_BUY && $this->_model->type != Apartment::TYPE_RENTING) { // video, panorama, lat, lon HApartment::saveOther($this->_model); } $this->_model->scenario = 'savecat'; $isUpdate = Yii::app()->request->getPost('is_update'); $this->_model->isAjaxLoadOnUpdate = $isUpdate; if ($isUpdate) { $this->_model->active = $oldStatus; $this->_model->save(false); } elseif ($this->_model->validate()) { $this->_model->save(false); Yii::app()->user->setFlash('success', tc('Success')); $this->redirect(array('update', 'id' => $this->_model->id)); } } HApartment::getCategoriesForUpdate($this->_model); if ($this->_model->active == Apartment::STATUS_DRAFT) { Yii::app()->user->setState('menu_active', 'apartments.create'); $this->render('create', array('model' => $this->_model, 'supportvideoext' => ApartmentVideo::model()->supportExt, 'supportvideomaxsize' => ApartmentVideo::model()->fileMaxSize)); return; } $this->render('update', array('model' => $this->_model, 'supportvideoext' => ApartmentVideo::model()->supportExt, 'supportvideomaxsize' => ApartmentVideo::model()->fileMaxSize)); }
public function actionUpdate($id) { $this->setActiveMenu('add_ad'); $model = $this->loadModelUserAd($id); if (issetModule('bookingcalendar')) { $model = $model->with(array('bookingCalendar')); } $this->performAjaxValidation($model); if (isset($_GET['type'])) { $model->type = HApartment::getRequestType(); } 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, panorama, lat, lon HApartment::saveOther($model); } $model->scenario = 'savecat'; $model->owner_active = Apartment::STATUS_ACTIVE; if (issetModule('tariffPlans') && issetModule('paidservices')) { $return = TariffPlans::checkAllowUserActivateAd(Yii::app()->user->id, true, '>='); if ($return === false) { $model->owner_active = Apartment::STATUS_INACTIVE; } } $isUpdate = Yii::app()->request->getPost('is_update'); $model->isAjaxLoadOnUpdate = $isUpdate; 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)) { if ($model->owner_active == Apartment::STATUS_INACTIVE) { $this->redirect(array('/usercpanel/main/index')); } else { $this->redirect(array('/apartments/main/view', 'id' => $model->id)); } } } else { $model->active = $originalActive; } } HApartment::getCategoriesForUpdate($model); 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)); }
public function actionDeleteVideo($id = null, $apId = null) { if (Yii::app()->user->isGuest) { throw404(); } if (!$id && !$apId) { throw404(); } if (Yii::app()->user->checkAccess('backend_access')) { $modelVideo = ApartmentVideo::model()->findByPk($id); $modelVideo->delete(); $this->redirect(array('/apartments/backend/main/update', 'id' => $apId)); } else { $modelApartment = Apartment::model()->findByPk($apId); if ($modelApartment->owner_id != Yii::app()->user->id) { throw404(); } $modelVideo = ApartmentVideo::model()->findByPk($id); $modelVideo->delete(); $this->redirect(array('/userads/main/update', 'id' => $apId)); } }
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)); }