Exemplo n.º 1
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));
 }
Exemplo n.º 2
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));
 }