本文整理汇总了PHP中CActiveRecordBehavior::afterSave方法的典型用法代码示例。如果您正苦于以下问题:PHP CActiveRecordBehavior::afterSave方法的具体用法?PHP CActiveRecordBehavior::afterSave怎么用?PHP CActiveRecordBehavior::afterSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CActiveRecordBehavior
的用法示例。
在下文中一共展示了CActiveRecordBehavior::afterSave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterSave
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;
}
示例2: afterSave
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;
}
示例3: afterSave
public function afterSave($event)
{
if (Yii::app() instanceof CWebApplication) {
if (Yii::app()->user->getState(UserIdentity::STATE_AUDIT_TRAIL, true)) {
$isNewRecord = $this->getOwner()->getIsNewRecord();
UserActivityLog::model()->addRecord(array('user_id' => Yii::app()->user->id, 'ip' => Common::getIp(), 'action' => $isNewRecord ? 'create' : 'update', 'activity' => $this->prepareString($isNewRecord ? $this->createTemplate : $this->updateTemplate)));
}
}
return parent::afterSave($event);
}
示例4: afterSave
public function afterSave($event)
{
return parent::afterSave($event);
if ($this->owner->isNewRecord) {
if (array_key_exists(get_class($this->owner), self::$handlers)) {
$method = self::$handlers[get_class($this->owner)]['create'];
$this->{$method}();
}
}
}
示例5: afterSave
public function afterSave($event)
{
parent::afterSave($event);
if (!$this->owner->isNewRecord) {
$videoCache = Yii::app()->cache->get('Video::' . $this->owner->youtubeId);
$videoCache['description'] = $this->owner->description;
$videoCache['title'] = $this->owner->title;
Yii::app()->cache->set('Video::' . $this->owner->youtubeId, $videoCache);
}
}
示例6: afterSave
public function afterSave($event)
{
$model = $this->getOwner();
if ($model->isNewRecord) {
foreach ($this->findAllAttaches() as $attach) {
$attach->object_id = $model->id;
$attach->save();
}
}
return parent::afterSave($event);
}
示例7: afterSave
/**
* @param CEvent $event
*/
public function afterSave($event)
{
// restore values of attributes saved in _convertAttributesToDB()
if (count($this->_backupAttributes)) {
foreach ($this->_backupAttributes as $name => $value) {
$this->getOwner()->{$name} = $value;
}
$this->_backupAttributes = [];
}
parent::afterSave($event);
}
示例8: afterSave
public function afterSave($event)
{
$allowedFields = $this->allowed;
$ignoredFields = $this->ignored;
$ignoredClasses = $this->ignored_class;
$newattributes = $this->getOwner()->getAttributes();
$oldattributes = $this->getOldAttributes();
// Lets check if the whole class should be ignored
if (sizeof($ignoredClasses) > 0) {
if (array_search(get_class($this->getOwner()), $ignoredClasses) !== false) {
return;
}
}
// Lets unset fields which are not allowed
if (sizeof($allowedFields) > 0) {
foreach ($newattributes as $f => $v) {
if (array_search($f, $allowedFields) === false) {
unset($newattributes[$f]);
}
}
foreach ($oldattributes as $f => $v) {
if (array_search($f, $allowedFields) === false) {
unset($oldattributes[$f]);
}
}
}
// Lets unset fields which are ignored
if (sizeof($ignoredFields) > 0) {
foreach ($newattributes as $f => $v) {
if (array_search($f, $ignoredFields) !== false) {
unset($newattributes[$f]);
}
}
foreach ($oldattributes as $f => $v) {
if (array_search($f, $ignoredFields) !== false) {
unset($oldattributes[$f]);
}
}
}
// If no difference then WHY?
// There is some kind of problem here that means "0" and 1 do not diff for array_diff so beware: stackoverflow.com/questions/12004231/php-array-diff-weirdness :S
if (count(array_diff_assoc($newattributes, $oldattributes)) <= 0) {
return;
}
// If this is a new record lets add a CREATE notification
if ($this->getOwner()->getIsNewRecord()) {
$this->leaveTrail('CREATE');
}
// Now lets actually write the attributes
$this->auditAttributes($newattributes, $oldattributes);
// Reset old attributes to handle the case with the same model instance updated multiple times
$this->setOldAttributes($this->getOwner()->getAttributes());
return parent::afterSave($event);
}
示例9: afterSave
public function afterSave($event)
{
$owner = $this->getOwner();
if ($owner->getIsNewRecord() && $owner->send_email) {
$this->accountDetailsEmail();
}
if ($owner->getScenario() === Users::SCENARIO_RESET_PASSWORD && $owner->send_email) {
$this->newPasswordEmail();
}
if ($owner->getIsNewRecord() && $owner->getScenario() === Users::SCENARIO_SIGNUP) {
$this->sendAccActivationEmail();
}
return parent::afterSave($event);
}
示例10: afterSave
public function afterSave($event)
{
$attributes = Yii::app()->request->getParam('MetaTag');
if ($attributes) {
$meta_tag = MetaTag::model()->findByAttributes(array('object_id' => $this->owner->id, 'model_id' => get_class($this->owner)));
if (!$meta_tag) {
$meta_tag = new MetaTag();
}
$attributes['object_id'] = $this->owner->id;
$attributes['model_id'] = get_class($this->owner);
$meta_tag->attributes = $attributes;
$meta_tag->save();
}
return parent::afterSave($event);
}
示例11: afterSave
public function afterSave($event)
{
parent::afterSave($event);
// Save all languages updated via setTranslatedFields().
if ($this->autoSave) {
foreach ($this->updates as $language => $callback) {
$callback[0]->model_id = $this->owner->id;
if (!call_user_func($callback)) {
throw new \Exception("Model callback failed.");
}
}
if (isset($this->_current)) {
$this->_current->save();
}
}
$this->backupValues();
if (isset($this->_current)) {
$this->setLanguage($this->_current->language);
}
}
示例12: afterSave
public function afterSave($event)
{
parent::afterSave($event);
$this->processAttributes($event->sender, self::DIRECTION_CLIENT);
}
示例13: afterSave
/**
* Provides saving related HAS_ONE records.
*
* @param CEvent $event event object
*
* @see CActiveRecordBehavior::afterSave()
*
* @throws Exception
*/
public function afterSave($event)
{
$owner = $this->getOwner();
foreach ($owner->relations() as $key => $relation) {
$isHasOne = $relation['0'] == CActiveRecord::HAS_ONE;
if (!$isHasOne) {
continue;
}
if (isset($this->relations[$key]) || in_array($key, $this->relations)) {
$config = $this->_getRelationConfig($key);
$owner->{$key}->{$relation}[2] = $owner->primaryKey;
if ($config['createRelated'] && !$owner->{$key}) {
$related = new $relation[1]();
$related->{$relation}[2] = $owner->primaryKey;
} else {
$related = $owner->{$key};
}
if ($config['saveRelated'] && !$related->save()) {
$message = 'Can not save related record. ' . CHtml::errorSummary($related);
throw new CException($message);
}
}
}
parent::afterSave($event);
}
示例14: afterSave
/**
* Сохраняем историю
*/
public function afterSave($event)
{
parent::afterSave($event);
if ($this->saveHistory && $this->waitForSave) {
$table = $this->historyTable ? $this->historyTable : $this->owner->tableName() . "_events_history";
$builder = Yii::app()->db->schema->commandBuilder;
$builder->createMultipleInsertCommand($table, $this->waitForSave)->execute();
}
}
示例15: afterSave
/**
* Update model translations
*/
public function afterSave($event)
{
Tag::model()->updateFrequency($this->_oldTags, $this->getOwner()->tags);
return parent::afterSave($event);
}