/** * @param CActiveRecord $owner */ public function attach($owner) { $validator = new yupe\components\validators\NumberValidator(); $validator->attributes = array($this->priceAttribute, $this->priceEurAttribute, $this->priceOldAttribute); $owner->getValidatorList()->add($validator); parent::attach($owner); }
/** * @param CActiveRecord $owner */ public function attach($owner) { $validator = new CSafeValidator(); $validator->attributes = array($this->attribute); $owner->getValidatorList()->add($validator); parent::attach($owner); }
public function afterValidate($event) { parent::afterValidate($event); if ($this->checkScenario() && !$this->owner->hasErrors()) { $modelName = get_class($this->owner); if (isset($_FILES[$modelName]['name'][$this->attributeName])) { $files = array(); foreach ($_FILES[$modelName] as $k => $v) { $files[$k] = $v[$this->attributeName]; } // Сохраняю if ($files) { Yii::import('ext.ImageUpload.ImageUpload'); $handle = new ImageUpload($files); if ($handle->uploaded) { $this->saveImage($handle); // Удаляю старую фотку if ($this->owner->scenario == 'update') { $this->deleteImage(); } $handle->clean(); } unset($handle, $files); } } } }
public function attach($owner) { parent::attach($owner); $this->_hasCreateDate = $this->getOwner()->hasAttribute('createDate'); $this->_hasLastUpdated = $this->getOwner()->hasAttribute('lastUpdated'); $this->_hasLastActivity = $this->getOwner()->hasAttribute('lastActivity'); }
/** * Triggered before the model saves, this is where the slug attribute is actually set * @see CActiveRecordBehavior::beforeSave() */ public function beforeSave($event) { if ($this->owner->isNewRecord || $this->owner->{$this->slugAttribute} == "") { $this->owner->{$this->slugAttribute} = $this->createSlug(); } return parent::beforeSave($event); }
public function beforeSave($event) { if ($this->_value !== NULL) { $this->getOwner()->setAttribute($this->getBackupAttribute(), $this->_value); } return parent::beforeSave($event); }
/** * @param CComponent $owner */ public function attach($owner) { $owner->attachEventHandler('onProductAdded', array($this, 'productAddedEvent')); $owner->attachEventHandler('onProductDeleted', array($this, 'productDeletedEvent')); $owner->attachEventHandler('onProductQuantityChanged', array($this, 'onProductQuantityChanged')); parent::attach($owner); }
/** * Attaches dynamic relations. * * @param CActiveRecord $owner owner * * @see CBehavior::attach() */ public function attach($owner) { parent::attach($owner); $ownerClassName = get_class($owner); $metaData = $owner->getMetaData(); $metaData->addRelation('parent', array(CActiveRecord::BELONGS_TO, $ownerClassName, $this->parentIdColumn)); }
/** * (non-PHPdoc). * * @see CBehavior::attach() */ public function attach($owner) { parent::attach($owner); if (!isset($this->defaultCounter)) { $this->defaultCounter = $this->counters[0]; } }
public function afterSave($event) { parent::afterSave($event); // do not auto-create meta data information for meta data table itself (recursion). if ($this->metaDataRelation == '_self_') { return true; } // create new meta data record or just update modifiedBy/At columns if ($this->resolveMetaDataModel() === null) { $metaClassName = $this->owner->getActiveRelation($this->metaDataRelation)->className; $metaModel = new $metaClassName(); $metaModel->id = $this->owner->id; $metaModel->status = self::STATUS_ACTIVE; $metaModel->language = Yii::app()->language; $metaModel->owner = Yii::app()->user->id; $primaryRole = key(Yii::app()->authManager->getRoles(Yii::app()->user->id)); $metaModel->checkAccessDelete = $primaryRole; $metaModel->createdAt = date('Y-m-d H:i:s'); $metaModel->createdBy = Yii::app()->user->id; $metaModel->model = get_class($this->owner); } else { $metaModel = $this->resolveMetaDataModel(); $metaModel->modifiedAt = date('Y-m-d H:i:s'); $metaModel->modifiedBy = Yii::app()->user->id; } $metaModel->save(); return true; }
public function afterSave($event) { $relations = $this->getRelations(); foreach ($relations as $relation) { if ($relation['type'] == CActiveRecord::MANY_MANY) { $forAdd = array_diff($relation['value'], $relation['oldValue']); foreach ($forAdd as $id) { if ($id) { $sql = 'INSERT INTO `' . $relation['m2mTable'] . '` (`' . $relation['m2mThisField'] . '`, `' . $relation['m2mForeignField'] . '`) VALUES (:this_field, :foreign_field)'; Yii::app()->getDb()->createCommand($sql)->bindValues(array('this_field' => $this->getOwner()->id, ':foreign_field' => $id))->execute(); } } $forRemove = array_diff($relation['oldValue'], $relation['value']); foreach ($forRemove as $id) { if ($id) { $sql = 'DELETE IGNORE FROM `' . $relation['m2mTable'] . '` WHERE `' . $relation['m2mThisField'] . '` = :this_field AND `' . $relation['m2mForeignField'] . '` = :foreign_field'; Yii::app()->getDb()->createCommand($sql)->bindValues(array('this_field' => $this->getOwner()->id, ':foreign_field' => $id))->execute(); } } } } //Yii::app()->end(); parent::afterSave($event); return true; }
public function beforeDelete($event) { foreach ($this->findAllAttaches() as $attach) { $attach->delete(); } return parent::beforeDelete($event); }
/** * Attaches the behavior object to the model. * * @param string $owner The component to which the behavior will be applied */ public function attach($owner) { parent::attach($owner); if ($this->getModule() === null) { // Resolve the module if (isset($this->baseRoute)) { // Try to extract it from $baseRoute (old custom modules) $this->module = preg_replace('/\\/.*/', '', preg_replace('/^\\//', '', $this->baseRoute)); } else { // Assume the model name is the same as the module/controller // (also true of custom modules) $this->module = strtolower(get_class($this->owner)); } } if (!isset($this->baseRoute)) { $this->baseRoute = '/' . $this->module; } if (!isset($this->viewRoute)) { $this->viewRoute = $this->baseRoute; } if (Yii::app()->params->isMobileApp) { $this->viewRoute .= '/mobileView'; } if (!isset($this->autoCompleteSource)) { $this->autoCompleteSource = $this->baseRoute . '/getItems?modelType=' . get_class($this->owner); } }
public function detach($owner) { parent::detach($owner); $this->objectId = null; $this->objectType = null; $this->_oaa = null; }
public function attach($owner) { parent::attach($owner); $this->_model = $owner; $this->addRelations(); $this->addSafeAttributes(); }
/** * @param CEvent $event * @return mixed */ public function afterDelete($event) { Yii::import('application.modules.comments.models.Comment'); $pk = $this->getObjectPkAttribute(); Comment::model()->deleteAllByAttributes(array('class_name' => $this->getClassName(), 'object_pk' => $this->getOwner()->{$pk})); return parent::afterDelete($event); }
/** * Actions to take before validating the owner. * @param CModelEvent $event */ public function beforeValidate($event) { parent::beforeValidate($event); if ($this->owner->hasAttribute($this->statusAttribute) && !isset($this->owner->{$this->statusAttribute})) { $this->owner->{$this->statusAttribute} = $this->defaultStatus; } }
public function __get($name) { if ($groupName = $this->groupName($name)) { return $this->getGroupLabels($groupName); } else { return parent::__get($name); } }
/** * @param CModelEvent $event */ public function beforeSave($event) { if (method_exists($this->getOwner(), 'setDefaultAttributes')) { $this->getOwner()->setDefaultAttributes(); } // will the following will be called twice? return parent::beforeSave($event); }
/** Will remove associated Gallery before object removal */ public function beforeDelete($event) { $gallery = $this->getGallery(); if ($gallery !== null) { $gallery->delete(); } parent::beforeDelete($event); }
/** * @param \CModelEvent $event */ public function beforeSave($event) { if ($this->getOwner()->getIsNewRecord()) { $position = Yii::app()->getDb()->createCommand("select max({$this->attributeName}) from {$this->getOwner()->tableName()}")->queryScalar(); $this->getOwner()->{$this->attributeName} = (int) $position + 1; } return parent::beforeSave($event); }
public function attach($owner) { $validators = $owner->getValidatorList(); foreach ($this->rules() as $rule) { $validators->add(CValidator::createValidator($rule[1], $owner, $rule[0], array_slice($rule, 2))); } parent::attach($owner); }
public function afterFind($event) { parent::afterFind($event); //это не открывать, работает для всех взаимосвязанных элементов // if(!Common::isCLI() && ($history = request()->getParam('history')) ){ // $this->getFullHistory($history); // } }
public function beforeDelete($event) { $model = $this->getOwner(); $files = FileManager::model()->findAllByAttributes(array('model_id' => get_class($model), 'object_id' => $model->id)); foreach ($files as $file) { $file->delete(); } return parent::beforeDelete($event); }
function afterDelete($event) { // removing all model's comments $comments = $this->getComments(); foreach ($comments as $comment) { $comment->delete(); } parent::afterDelete($event); }
public function beforeSave($event) { $model = $this->getOwner(); $column = $this->column; if ($model->isNewRecord) { $model->{$column} = Yii::app()->db->createCommand("SELECT MAX({$this->column}) FROM " . $model->tableName())->queryScalar() + 1; } parent::beforeSave($event); }
/** * Attach behavior to model * @param $owner */ public function attach($owner) { if (!$owner->isNewRecord && Yii::app()->controller instanceof Controller) { if (DiscountBehavior::$discounts === null) { DiscountBehavior::$discounts = Discount::model()->activeOnly()->applyDate()->findAll(); } parent::attach($owner); } }
public function events() { if (is_subclass_of($this->getOwner(), 'BaseMongoDocument')) { $tmp = parent::events(); } else { $tmp = array(); } return array_merge($tmp, array('onBeforeEmbeddedDocsInit' => 'beforeEmbeddedDocsInit', 'onAfterEmbeddedDocsInit' => 'afterEmbeddedDocsInit', 'onBeforeToArray' => 'beforeToArray', 'onAfterToArray' => 'afterToArray')); }
/** * @param CEvent $event * @return mixed */ public function afterDelete($event) { if (Yii::app()->hasModule('comments')) { Yii::import('mod.comments.models.Comments'); $pk = $this->getObjectPkAttribute(); Comments::model()->deleteAllByAttributes(array('model' => $this->getModelName(), 'object_id' => $this->getOwner()->{$pk})); } return parent::afterDelete($event); }
/** Will remove associated Gallery before object removal */ public function beforeDelete($event) { if (!empty($this->getOwner()->{$this->idAttribute})) { /** @var $gallery Gallery */ $gallery = Gallery::model()->findByPk($this->getOwner()->{$this->idAttribute}); $gallery->delete(); } parent::beforeDelete($event); }