public function validate() { if (parent::validate()) { if (!$this->date_start) { $this->datetime_start = null; } else { $this->datetime_start = date('Y-m-d', strtotime($this->date_start)); $timestart = $this->time_start != '' ? date('H:i:s', strtotime($this->time_start)) : '00:00:00'; $this->datetime_start .= ' ' . $timestart; } if (!$this->date_end) { $this->datetime_end = null; } else { $this->datetime_end = date('Y-m-d', strtotime($this->date_end)); $timeend = $this->time_end != '' ? date('H:i:s', strtotime($this->time_end)) : '00:00:00'; $this->datetime_end .= ' ' . $timeend; } if ($this->datetime_start !== null && $this->datetime_end !== null) { $timestampStart = strtotime($this->datetime_start); $timestampEnd = strtotime($this->datetime_end); if ($timestampStart > 0 && $timestampEnd > 0 && $timestampEnd <= $timestampStart) { $this->addError('date_end', 'Дата и время окончания срока действия промо-кода должны быть больше, чем дата его начала'); } } } return !$this->hasErrors(); }
public function afterFind() { parent::afterFind(); if ($this->date != null) { $this->date = Yii::app()->dateFormatter->format("dd.MM.yyyy", $this->date); } }
public function afterDelete() { if (Yii::app()->hasModule('delivery')) { $this->clearDeliveryMethods(); } parent::afterDelete(); }
/** * Метод выполняемый перед сохранением: * * @return void */ public function beforeSave() { if ($this->isNewRecord) { $this->user_id = Yii::app()->getUser()->getId(); } return parent::beforeSave(); }
/** * Метод выполняемый перед удалением: * * @return void */ public function beforeDelete() { foreach ($this->packages as $package) { $package->delete(); } return parent::beforeDelete(); }
public function beforeValidate() { if (!$this->alias) { $this->alias = yupe\helpers\YText::translit($this->title); } return parent::beforeValidate(); }
/** * Метод выполняемый перед удалением: * * @return void */ public function beforeDelete() { // Удаляем изображения foreach ($this->images as $image) { $image->delete(); } return parent::beforeDelete(); }
public function beforeSave() { $this->update_date = new CDbExpression('NOW()'); if ($this->isNewRecord) { $this->creation_date = $this->update_date; } return parent::beforeSave(); }
/** * beforeValidate * * @return parent::beforeValidate() **/ public function beforeValidate() { // Проверяем наличие установленного хозяина галереи if (isset($this->owner) && empty($this->owner)) { $this->owner = Yii::app()->user->getId(); } return parent::beforeValidate(); }
/** * Метод выполняемый перед удалением: * * @return void */ public function beforeDelete() { // Удаляем значения foreach ($this->dictionaryData as $item) { $item->delete(); } return parent::beforeDelete(); }
/** * @return bool */ public function beforeDelete() { if ($this->is_system) { $this->addError('statuses', Yii::t('OrderModule.order', 'You can not delete a system status.')); return false; } return parent::beforeDelete(); }
/** * Метод выполняемый перед удалением: * * @return void */ public function beforeDelete() { // Обнуляем категории у сообщений foreach ($this->messages as $item) { $item->category_id = null; $item->update(['category_id']); } return parent::beforeDelete(); }
/** * Метод выполняемый перед удалением: * * @return void */ public function beforeDelete() { // Обнуляем категорию у атрибутов foreach ($this->attrs as $attr) { $attr->category_id = null; $attr->save(false, array('category_id')); } return parent::beforeDelete(); }
/** * Метод выполняемый перед удалением: * * @return void */ public function beforeDelete() { // Обнуляем группу у результатов foreach ($this->results as $result) { $result->group_id = null; $result->save(false, array('group_id')); } return parent::beforeDelete(); }
/** * Метод выполняемый перед сохранением: * * @return void */ public function beforeSave() { if (parent::beforeSave()) { $this->phone = preg_replace("/[^0-9]/", "", $this->phone); return true; } else { return false; } }
public function beforeValidate() { if (!$this->alias) { $this->alias = yupe\helpers\YText::translit($this->name); } if (!$this->lang) { $this->lang = Yii::app()->language; } return parent::beforeValidate(); }
protected function beforeSave() { $this->initType(); // связи без типа в базу не пройдут! if (!$this->entity_name) { return false; } $this->_isNew = $this->isNewRecord; return parent::beforeSave(); }
protected function beforeSave() { if (parent::beforeSave()) { Yii::app()->cache->delete("ContentBlock{$this->code}" . Yii::app()->language); if ($this->type == self::SIMPLE_TEXT) { $this->content = strip_tags($this->content); } return true; } return false; }
protected function beforeSave() { parent::beforeSave(); if ($this->role_id == 1) { if (!array_intersect(Yii::app()->user->role, ['1'])) { throw new CHttpException(403, 'Ошибка прав доступа.'); } else { return true; } } else { return true; } }
/** * Метод перед удалением: * * @return bool */ public function beforeDelete() { if ($this->_oldAccess_level == self::ACCESS_LEVEL_ADMIN && $this->admin()->count() == 1) { $this->addError('access_level', Yii::t('UserModule.default', 'You can\'t make this changes!')); return false; } return parent::beforeDelete(); }
/** * Returns the static model of the specified AR class. * @return DictionaryData the static model class */ public static function model($className = __CLASS__) { return parent::model($className); }
public function beforeValidate() { if ($this->isNewRecord) { $this->creation_date = new CDbExpression('NOW()'); $this->user_id = Yii::app()->user->getId(); } return parent::beforeValidate(); }
/** * Метод выполняемый перед удалением: * * @return void */ public function beforeDelete() { // Удаляем дочерние блоки foreach ($this->children as $subblock) { $subblock->delete(); } return parent::beforeDelete(); }
/** * Метод перед удалением: * * @return void */ public function beforeDelete() { // Удаляем шаблоны foreach ($this->templates as $template) { $template->delete(); } return parent::beforeDelete(); }
public function beforeSave() { $this->start_time = $this->start_time ?: null; $this->end_time = $this->end_time ?: null; return parent::beforeSave(); }
protected function afterDelete() { Yii::app()->getCache()->clear($this->menu->code); return parent::afterDelete(); }
public function beforeDelete() { Yii::app()->cache->delete("Blog::Blog::members::{$this->user_id}"); return parent::beforeDelete(); }
/** * Обновляем дату изменения. Если новая запись * обновляем необходимые поля: * * @return void */ public function beforeValidate() { $this->change_date = new CDbExpression('NOW()'); if ($this->isNewRecord) { $this->creation_date = $this->change_date; $this->ip = Yii::app()->getRequest()->userHostAddress; if (!$this->type) { $this->type = self::TYPE_DEFAULT; } } return parent::beforeValidate(); }
/** * Метод выполняемый перед удалением: * * @return void */ public function beforeDelete() { // Удаляем описания foreach ($this->descriptions as $description) { $description->delete(); } return parent::beforeDelete(); }
public function __construct($scenario = 'insert') { Yii::app()->setImport(['application.modules.dictionary.models.*']); parent::__construct($scenario); }