public function beforeSave() { if ($this->position == '') { $max = OrderStatus::model()->orderByPositionDesc()->find(); if ($max) { $this->position = (int) $max->position + 1; } else { $this->position = 0; } } return parent::beforeSave(); }
/** * @return bool */ public function beforeSave() { if (empty($this->url)) { // Create slug Yii::import('ext.SlugHelper.SlugHelper'); $this->url = SlugHelper::run($this->title); } // Check if url available if ($this->isNewRecord) { $test = Event::model()->withUrl($this->url)->count(); } else { $test = Event::model()->withUrl($this->url)->count('id!=:id', array(':id' => $this->id)); } if ($test > 0) { $this->url .= '-' . date('YmdHis'); } return parent::beforeSave(); }
public function beforeSave() { if (parent::beforeSave()) { $reurl = false; if ($this->isNewRecord) { $this->_newRec = true; $this->author = Yii::app()->user ? Yii::app()->user->id : null; } else { $this->_curr = self::findByPk($this->id); if ($this->_curr) { if ($this->title != $this->_curr->title) { $reurl = true; } } } // Create slug Yii::import('ext.SlugHelper.SlugHelper'); if (!$this->url || $reurl) { // $this->url = SlugHelper::run(preg_replace('/\s{2,}/', ' ', $this->synonim)); $this->url = SlugHelper::run($this->title, 'yandex'); } else { $this->url = SlugHelper::run($this->url, 'yandex'); } $unique = $this->url; $addsuffix = 0; while ($this->checkUniqueUrl($unique) > 0) { $unique = $this->url . $suffix . '-' . $addsuffix; $addsuffix++; } $this->url = $unique; $this->description = trim(MHelper::String()->purifyFromScript($this->description)); $this->updated_date = date('Y-m-d H:i:s'); return true; } else { return false; } }
/** * @return bool */ public function beforeSave() { return parent::beforeSave(); }
public function beforeSave() { if (empty($this->url)) { // Create slug Yii::import('ext.SlugHelper.SlugHelper'); $this->url = SlugHelper::run(preg_replace('/\\s{2,}/', ' ', $this->name)); } // Check if url available if ($this->isNewRecord) { $test = StoreProduct::model()->withUrl($this->url)->count(); $this->created = date('Y-m-d H:i:s'); } else { $test = StoreProduct::model()->withUrl($this->url)->count('t.id!=:id', array(':id' => $this->id)); } // Create unique url if ($test > 0) { $this->url .= '-' . date('YmdHis'); } return parent::beforeSave(); }
/** * @return bool */ public function beforeSave() { // Set new password if ($this->new_password) { $this->password = User::encodePassword($this->new_password); } if ($this->isNewRecord) { if (!$this->created_at) { $this->created_at = date('Y-m-d H:i:s'); } $this->login_ip = Yii::app()->request->userHostAddress; if (!$this->hasErrors()) { $this->password = User::encodePassword($this->password); } } return parent::beforeSave(); }
public function beforeSave() { if(parent::beforeSave()) { $reurl = false; if($this->isNewRecord) { $this->_newRec = true; $this->author = (Yii::app()->user)?Yii::app()->user->id:null; } else { $this->_curr = self::findByPk($this->id,array('select'=>'status_org')); if($this->_curr) { if($this->title != $this->_curr->title) $reurl = true; } } // Create slug Yii::import('ext.SlugHelper.SlugHelper'); if(!$this->url || $reurl){ // $this->url = SlugHelper::run(preg_replace('/\s{2,}/', ' ', $this->synonim)); $this->url = SlugHelper::run($this->title, 'yandex'); } else { $this->url = SlugHelper::run($this->url, 'yandex'); } $this->description = trim(MHelper::String()->purifyFromScript($this->description)); $this->updated_date = date('Y-m-d H:i:s'); return true; } else return false; }
/** * @return bool */ public function beforeSave() { if (!$this->created && $this->isNewRecord) { $this->created = date('Y-m-d H:i:s'); } if (!$this->updated) { $this->updated = date('Y-m-d H:i:s'); } if (!Yii::app()->user->isGuest) { $this->user_id = Yii::app()->user->id; } if (empty($this->url)) { // Create slug Yii::import('ext.SlugHelper.SlugHelper'); $this->url = SlugHelper::run($this->title); } // Check if url available if ($this->isNewRecord) { $test = Page::model()->withUrl($this->url)->count(); } else { $test = Page::model()->withUrl($this->url)->count('id!=:id', array(':id' => $this->id)); } if ($test > 0) { $this->url .= '-' . date('YmdHis'); } return parent::beforeSave(); }
/** * Before save. */ public function beforeSave() { if($this->isNewRecord) { $this->ip_address = Yii::app()->request->userHostAddress; $this->created = date('Y-m-d H:i:s'); if($this->status == self::STATUS_APPROVED){ if($this->rating) { $this->starRating($this->object_pk, $this->rating); } } } else { $this->_curr = self::findByPk($this->id); if($this->status == self::STATUS_APPROVED && $this->_curr->status != self::STATUS_APPROVED){ if($this->rating) { $this->starRating($this->object_pk, $this->rating); } } else if($this->status != self::STATUS_APPROVED && $this->_curr->status == self::STATUS_APPROVED){ if($this->rating) { if($this->_curr->rating != $this->rating){ $this->starRatingBack($this->object_pk, $this->_curr->rating); } else { $this->starRatingBack($this->object_pk, $this->rating); } } } else { if($this->_curr->rating != $this->rating){ $this->starRatingBack($this->object_pk, $this->_curr->rating); $this->starRating($this->object_pk, $this->rating); } else { // do nothing with rating } } } $this->updated = date('Y-m-d H:i:s'); return parent::beforeSave(); }
/** * Before save. */ public function beforeSave() { if ($this->isNewRecord) { $this->status = $this->defaultStatus; $this->ip_address = Yii::app()->request->userHostAddress; $this->created = date('Y-m-d H:i:s'); } $this->updated = date('Y-m-d H:i:s'); return parent::beforeSave(); }
public function beforeSave() { if (empty($this->url)) { // Create slug Yii::import('ext.SlugHelper.SlugHelper'); $this->url = SlugHelper::run($this->name); } // Check if url available if ($this->isNewRecord) { $test = StoreCategory::model()->withUrl($this->url)->count(); } else { $test = StoreCategory::model()->withUrl($this->url)->count('id!=:id', array(':id' => $this->id)); } // Create unique url if ($test > 0) { $this->url .= '-' . date('YmdHis'); } $this->rebuildFullPath(); return parent::beforeSave(); }
/** * @return bool */ public function beforeSave() { if ($this->isNewRecord) { $this->secret_key = $this->createSecretKey(); $this->ip_address = Yii::app()->request->userHostAddress; $this->created = date('Y-m-d H:i:s'); if (!Yii::app()->user->isGuest) { $this->user_id = Yii::app()->user->id; } } $this->updated = date('Y-m-d H:i:s'); // Set `New` status if (!$this->status_id) { $this->status_id = 1; } return parent::beforeSave(); }
public function beforeSave() { if (!$this->created && $this->isNewRecord) { $this->created = date('Y-m-d H:i:s'); } if (!$this->updated) { $this->updated = date('Y-m-d H:i:s'); } if (empty($this->url)) { Yii::import('ext.SlugHelper.SlugHelper'); $this->url = SlugHelper::run($this->name); } // Check if url available if ($this->isNewRecord) { $test = PageCategory::model()->withUrl($this->url)->count('parent_id=:parent_id', array(':parent_id' => $this->parent_id)); } else { $test = PageCategory::model()->withUrl($this->url)->count('id!=:id AND parent_id=:parent_id', array(':id' => $this->id, ':parent_id' => $this->parent_id)); } if ($test > 0) { $this->url .= '-' . date('YmdHis'); } return parent::beforeSave(); }
public function beforeSave() { if(parent::beforeSave()) { $ydata = false; $reurl = false; if($this->isNewRecord) { $this->ip_address = Yii::app()->request->userHostAddress; $ydata = true; $this->_newRec = true; $this->author = (!Yii::app()->user->isGuest)?Yii::app()->user->id:null; } else { $this->_curr = self::findByPk($this->id,array('select'=>'city_id,status,address,lat,lng')); if($this->_curr) { if($this->title != $this->_curr->title) $reurl = true; } if($this->city_id != $this->_curr->city_id || $this->address != $this->_curr->address || !$this->lat || !$this->lng){ $ydata = true; } } if($ydata == true){ if(!empty($this->address)){ $address = $this->address; $params = array( 'geocode' => $address, // адрес 'format' => 'json', // формат ответа 'results' => 1, // количество выводимых результатов // 'key' => '...', // ваш api key ); $response = json_decode(@file_get_contents('http://geocode-maps.yandex.ru/1.x/?' . http_build_query($params, '', '&'))); $result = ''; if ($response && isset($response->response) && $response->response->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found > 0) { $result = $response->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos; if($result){ $exp_str1 = explode(" ", $result); $this->lat = $exp_str1[1]; $this->lng = $exp_str1[0]; // $this->yanData(); } } } } // Create slug Yii::import('ext.SlugHelper.SlugHelper'); if(!$this->url || $reurl){ $this->url = SlugHelper::run($this->title, 'yandex'); } else { $this->url = SlugHelper::run($this->url, 'yandex'); } $this->updated_date = date('Y-m-d H:i:s'); return true; } else return false; }
public function beforeSave() { if(parent::beforeSave()) { // Create slug Yii::import('ext.SlugHelper.SlugHelper'); if(!$this->name){ $this->name = SlugHelper::run($this->title, 'yandex'); } else { $this->name = SlugHelper::run($this->name, 'yandex'); } $unique = $this->name; $suffix = 1; while ($this->checkUniqueUrl($unique) > 0){ $unique = $this->name.$suffix; $suffix++; } $this->name = $unique; return true; } else return false; }