Пример #1
0
 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;
 }
Пример #2
0
 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));
 }
Пример #3
0
 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));
 }
Пример #4
0
 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));
     }
 }
Пример #5
0
 public function checkHtmlCode()
 {
     if ($this->video_html) {
         $apartmentVideoModel = new ApartmentVideo();
         $return = $apartmentVideoModel->parseVideoHTML($this->video_html);
         if (is_array($return) && isset($return[1])) {
             if ($return[1] == 'error') {
                 $this->addError('video_html', tt('incorrect_youtube_code', 'apartments'));
             }
         }
     }
 }
Пример #6
0
    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));
    }