Esempio n. 1
0
 public function beforeSave()
 {
     if ($this->ip) {
         $this->ip_long = ip2long($this->ip);
     }
     return parent::beforeSave();
 }
Esempio n. 2
0
 public function beforeSave()
 {
     if ($this->isNewRecord) {
         $maxSorter = Yii::app()->db->createCommand()->select('MAX(sorter) as maxSorter')->from($this->tableName())->queryScalar();
         $this->sorter = $maxSorter + 1;
     }
     return parent::beforeSave();
 }
Esempio n. 3
0
 public function beforeSave()
 {
     if ($this->scenario == 'set_default') {
         $sql = "UPDATE " . $this->tableName() . " SET is_default=0 WHERE id !=" . $this->id;
         Yii::app()->db->createCommand($sql)->execute();
     }
     return parent::beforeSave();
 }
Esempio n. 4
0
 public function beforeSave()
 {
     if ($this->isNewRecord) {
         $this->active = 1;
         $maxSorter = Yii::app()->db->createCommand()->select('MAX(sorter) as maxSorter')->from('{{articles}}')->queryScalar();
         $this->sorter = $maxSorter + 1;
     }
     return parent::beforeSave();
 }
Esempio n. 5
0
 public function beforeSave()
 {
     $settings = array();
     foreach ($this->payModel->attributes as $key => $value) {
         $settings[$key] = $value;
     }
     // Сохраняем аттрибуты зависимой модели (настройки платежки)
     $this->settings = CJSON::encode($settings);
     return parent::beforeSave();
 }
Esempio n. 6
0
 public function beforeSave()
 {
     if ($this->isNewRecord) {
         $this->active = 1;
         $maxSorter = Yii::app()->db->createCommand()->select('MAX(sorter) as maxSorter')->from('{{slider}}')->queryRow();
         $this->sorter = $maxSorter['maxSorter'] + 1;
     }
     $sql = "UPDATE {{slider}} SET date_updated=NOW() WHERE id='" . $this->id . "'";
     Yii::app()->db->createCommand($sql)->execute();
     return parent::beforeSave();
 }
Esempio n. 7
0
 public function beforeSave()
 {
     if ($this->isNewRecord) {
         $this->active = self::STATUS_ACTIVE;
         if (!Yii::app()->user->checkAccess('vacancy_admin')) {
             $this->active = self::STATUS_INACTIVE;
         }
         $maxSorter = Yii::app()->db->createCommand()->select('MAX(sorter) as maxSorter')->from('{{vacancy}}')->queryScalar();
         $this->sorter = $maxSorter + 1;
     }
     return parent::beforeSave();
 }
Esempio n. 8
0
 public function beforeSave()
 {
     if ($this->isNewRecord) {
         $maxSorter = Yii::app()->db->createCommand()->select('MAX(sorter) as maxSorter')->from($this->tableName())->queryScalar();
         $this->sorter = $maxSorter + 1;
     }
     //        $defaultCurrencyCharCode = Currency::getDefaultCurrencyModel()->char_code;
     //        if($defaultCurrencyCharCode != $this->in_currency){
     //            $this->price = (int) Currency::convert($this->price, $this->in_currency, $defaultCurrencyCharCode);
     //        }
     return parent::beforeSave();
 }
Esempio n. 9
0
 public function beforeSave()
 {
     if ($this->reference_category_id != $this->oldRefId && $this->oldRefId != 0 && !$this->isNewRecord) {
         $sql = 'UPDATE ' . $this->tableName() . ' SET sorter=sorter-1 WHERE sorter > "' . $this->sorter . '" AND reference_category_id="' . $this->oldRefId . '"';
         Yii::app()->db->createCommand($sql)->execute();
     }
     if ($this->isNewRecord || $this->reference_category_id != $this->oldRefId && $this->oldRefId != 0) {
         $sql = 'SELECT MAX(sorter) FROM ' . $this->tableName() . ' WHERE reference_category_id = "' . $this->reference_category_id . '"';
         $maxSorter = Yii::app()->db->createCommand($sql)->queryScalar();
         $this->sorter = $maxSorter + 1;
     }
     return parent::beforeSave();
 }
Esempio n. 10
0
 public function beforeSave()
 {
     if ($this->isNewRecord) {
         $sql = 'SELECT MAX(sorter) FROM {{images}} WHERE id_object=:id';
         $this->sorter = Yii::app()->db->createCommand($sql)->queryScalar(array(':id' => $this->id_object)) + 1;
         $sql = 'SELECT COUNT(*) FROM {{images}} WHERE id_object=:id AND is_main=1';
         $main = Yii::app()->db->createCommand($sql)->queryScalar(array(':id' => $this->id_object));
         if ($main == 0) {
             $this->is_main = 1;
         }
     }
     return parent::beforeSave();
 }
Esempio n. 11
0
 public function beforeSave()
 {
     if ($this->imageInstance) {
         $path = Yii::getPathOfAlias($this->path);
         $name = $this->imageInstance->getName();
         while (file_exists($path . DIRECTORY_SEPARATOR . $name)) {
             $name = rand(0, 9) . $name;
         }
         if ($this->imageInstance->saveAs($path . DIRECTORY_SEPARATOR . $name)) {
             $this->name = $name;
         } else {
             return false;
         }
     }
     return parent::beforeSave();
 }
Esempio n. 12
0
 public function beforeSave()
 {
     if ($this->isNewRecord) {
         //default value
         $this->file_name_modified = '';
         $this->comment = '';
         $dateTime = date('Y-m-d H:i:s');
         $this->date_updated = $dateTime;
         $this->is_main = 0;
         $sql = 'SELECT MAX(sorter) FROM {{images}} WHERE id_object=:id';
         $this->sorter = Yii::app()->db->createCommand($sql)->queryScalar(array(':id' => $this->id_object)) + 1;
         $sql = 'SELECT COUNT(*) FROM {{images}} WHERE id_object=:id AND is_main=1';
         $main = Yii::app()->db->createCommand($sql)->queryScalar(array(':id' => $this->id_object));
         if ($main == 0) {
             $this->is_main = 1;
         }
     }
     return parent::beforeSave();
 }
Esempio n. 13
0
 public function beforeSave()
 {
     //		foreach (Lang::getActiveLangs() as $key => $item) {
     //			$additionalInfo = 'additional_info_'.$item;
     //			if (isset($this->$additionalInfo) && !empty($this->$additionalInfo)) {
     //				$this->$additionalInfo = nl2br($this->$additionalInfo);
     //			}
     //		}
     $this->type = $this->type && in_array($this->type, self::getTypeList('key')) ? $this->type : User::TYPE_PRIVATE_PERSON;
     return parent::beforeSave();
 }
Esempio n. 14
0
 public function beforeSave()
 {
     if (!$this->square) {
         $this->square = 0;
     }
     /***изменено - вставляем пустые значения */
     if (!$this->title_ru) {
         $this->title_ru = '';
     }
     if (!$this->description_ru) {
         $this->description_ru = '';
     }
     if (!$this->description_near_ru) {
         $this->description_near_ru = '';
     }
     if (!$this->address_ru) {
         $this->address_ru = '';
     }
     if (!$this->date_up_search) {
         $timestamp = '01/01/2100 00:00:00';
         $timestamp = DateTime::createFromFormat('d/m/Y H:i:s', $timestamp);
         $this->date_up_search = $timestamp->format('Y-m-d H:i:s');
     }
     if (!$this->is_special_offer) {
         $this->is_special_offer = '';
     }
     if (!$this->is_free_from) {
         $timestamp = '01/01/2000 00:00:00';
         $timestamp = DateTime::createFromFormat('d/m/Y H:i:s', $timestamp);
         $this->is_free_from = $timestamp->format('Y-m-d H:i:s');
     }
     if (!$this->is_free_to) {
         $timestamp = '01/01/2100 00:00:00';
         $timestamp = DateTime::createFromFormat('d/m/Y H:i:s', $timestamp);
         $this->is_free_to = $timestamp->format('Y-m-d H:i:s');
     }
     if (!$this->exchange_to_ru) {
         $this->exchange_to_ru = '';
     }
     if (!$this->note) {
         $this->note = '';
     }
     if (!$this->phone) {
         $this->phone = '';
     }
     if (!$this->sublocation_id) {
         $this->sublocation_id = 0;
     }
     if (!$this->location_id) {
         $this->location_id = '';
     }
     if (!$this->price_old) {
         $this->price_old = 0;
     }
     /*************************/
     if (!$this->land_square) {
         $this->land_square = 0;
     }
     if ($this->isNewRecord) {
         $this->owner_id = $this->owner_id ? $this->owner_id : Yii::app()->user->id;
         $userInfo = User::model()->findByPk($this->owner_id, array('select' => 'isAdmin'));
         if ($userInfo && $userInfo->isAdmin == 1) {
             $this->owner_active = self::STATUS_ACTIVE;
         }
         if ($this->active != Apartment::STATUS_DRAFT) {
             // if admin
             if ($userInfo && $userInfo->isAdmin == 1) {
                 $this->active = Apartment::STATUS_ACTIVE;
             } else {
                 if (param('useUseradsModeration')) {
                     $this->active = self::STATUS_MODERATION;
                 }
             }
         }
         $maxSorter = Yii::app()->db->createCommand()->select('MAX(sorter) as maxSorter')->from($this->tableName())->queryScalar();
         $this->sorter = $maxSorter + 1;
         if ($this->obj_type_id == 0) {
             $this->obj_type_id = Yii::app()->db->createCommand('SELECT MIN(id) FROM {{apartment_obj_type}}')->queryScalar();
         }
     }
     if (!isFree()) {
         $defaultCurrencyCharCode = Currency::getDefaultCurrencyModel()->char_code;
         if ($defaultCurrencyCharCode != $this->in_currency) {
             $this->price = (int) Currency::convert($this->price, $this->in_currency, $defaultCurrencyCharCode);
             if (isset($this->price_to) && $this->price_to) {
                 $this->price_to = (int) Currency::convert($this->price_to, $this->in_currency, $defaultCurrencyCharCode);
             }
         }
     }
     switch ($this->type) {
         case self::TYPE_SALE:
             $this->price_type = self::PRICE_SALE;
             break;
         case self::TYPE_BUY:
             $this->price_type = self::PRICE_BUY;
             break;
         case self::TYPE_RENTING:
             $this->price_type = self::PRICE_RENTING;
             break;
         case self::TYPE_CHANGE:
             $this->price_type = self::PRICE_CHANGE;
             break;
         case self::TYPE_MORTGAGE:
             $this->price_type = self::PRICE_MORTGAGE;
             break;
         case self::TYPE_PRIVATISATION:
             $this->price_type = self::PRICE_PRIVATISATION;
             break;
     }
     if (isset($_POST['set_period_activity']) && $_POST['set_period_activity'] == 1 && $this->period_activity) {
         $list = self::getPeriodActivityList();
         if (isset($list[$this->period_activity])) {
             if ($this->period_activity == 'always') {
                 $this->activity_always = 1;
             } else {
                 $this->date_end_activity = date('Y-m-d', strtotime($this->period_activity, time()));
                 $this->activity_always = 0;
             }
         }
     }
     return parent::beforeSave();
 }
Esempio n. 15
0
 public function beforeSave()
 {
     if ($this->isNewRecord) {
         $maxSorter = Yii::app()->db->createCommand()->select('MAX(sorter) as maxSorter')->from($this->tableName())->queryScalar();
         $this->sorter = $maxSorter + 1;
     }
     if ($this->scenario == 'set_default') {
         $sql = "UPDATE " . $this->tableName() . " SET main=0 WHERE id!=" . $this->id;
         Yii::app()->db->createCommand($sql)->execute();
     }
     if ($this->scenario == 'set_admin_mail') {
         $sql = "UPDATE " . $this->tableName() . " SET admin_mail=0 WHERE id!=" . $this->id;
         Yii::app()->db->createCommand($sql)->execute();
     }
     // set RFC-3066
     $langCode = 'en-US';
     if (array_key_exists($this->name_iso, self::$RFC3066langs)) {
         $langCode = self::$RFC3066langs[$this->name_iso];
     }
     $this->name_rfc3066 = $langCode;
     return parent::beforeSave();
 }
Esempio n. 16
0
 public function beforeSave()
 {
     if ($this->fileInstance) {
         $path = Yii::getPathOfAlias($this->path) . DIRECTORY_SEPARATOR . $this->apartment_id;
         $name = $this->fileInstance->getName();
         $ext = $this->fileInstance->getExtensionName();
         while (file_exists($path . DIRECTORY_SEPARATOR . $name)) {
             $name = rand(0, 9) . $name;
         }
         $oldUMask = umask(0);
         if (!is_dir($path)) {
             @mkdir($path, 0777, true);
         }
         umask($oldUMask);
         if ($this->fileInstance->saveAs($path . DIRECTORY_SEPARATOR . $name)) {
             $this->name = $name;
             if ($ext == 'jpg' || $ext == 'png' || $ext == 'gif') {
                 $image = new CImageHandler();
                 if ($image->load($path . DIRECTORY_SEPARATOR . $name)) {
                     $this->width = $image->getWidth();
                     $this->height = $image->getHeight();
                 } else {
                     return false;
                 }
             }
         } else {
             return false;
         }
     }
     return parent::beforeSave();
 }
Esempio n. 17
0
 public function beforeSave()
 {
     Configuration::clearCache();
     return parent::beforeSave();
 }
Esempio n. 18
0
 public function beforeSave()
 {
     if ($this->blogImage) {
         if ($this->image) {
             $this->image->delete();
         }
         $image = new BlogImage();
         $image->imageInstance = $this->blogImage;
         $image->save();
         if ($image->id) {
             $this->image_id = $image->id;
         }
     }
     return parent::beforeSave();
 }
Esempio n. 19
0
 public function beforeSave()
 {
     $this->status = self::STATUS_NO_ERROR;
     return parent::beforeSave();
 }
Esempio n. 20
0
 public function beforeSave()
 {
     return parent::beforeSave();
 }
Esempio n. 21
0
 public function beforeSave()
 {
     if ($this->widget == 'apartments' && isset($_POST['filter'])) {
         $this->widget_data = CJSON::encode($_POST['filter']);
     }
     return parent::beforeSave();
 }
Esempio n. 22
0
 public function afterSave()
 {
     if ($this->id_userTo) {
         $user = User::model()->findByPk($this->id_userTo);
         if ($user) {
             $sql = 'SELECT id FROM ' . Yii::app()->session->sessionTableName . ' WHERE user_id = ' . $user->id . ' AND expire > ' . time();
             $res = Yii::app()->db->createCommand($sql)->queryScalar();
             # полагаем, что пользователь оффлайн - отправляем уведомление на почту
             if (!$res) {
                 $user->messageEmailSend = $this->message;
                 $notifier = new Notifier();
                 $notifier->raiseEvent('onNewPrivateMessage', $user, array('user' => $user));
                 /*if (!$resSend) {
                 			$errorsSend[] = $userModel->email;
                 		}*/
             }
         }
     }
     return parent::beforeSave();
 }