public function beforeValidate() { if ($this->isNewRecord && $this->keyword === null) { $this->keyword = AdminHelper::generateUrlStr($this->alias, $this, 'keyword'); } return parent::beforeValidate(); }
public function beforeSave() { $id = !$this->isNewRecord ? $this->primaryKey : null; foreach (Yii::app()->languageManager->languages as $l => $lang) { if ($l === Yii::app()->sourceLanguage) { $suffix = ''; $language = null; } else { $suffix = '_' . $l; $language = $l; } $this->{'title_url' . $suffix} = AdminHelper::generateUrlStr($this->{'title' . $suffix}, $this, 'title_url', $id, $language); } return parent::beforeSave(); }
/** * Generate the filtered url string. */ public function beforeSave($event) { $owner = $this->getOwner(); $id = !$owner->isNewRecord ? $owner->primaryKey : null; foreach (Yii::app()->languageManager->languages as $l => $lang) { if ($l === Yii::app()->sourceLanguage) { $suffix = ''; $language = null; } else { $suffix = '_' . $l; $language = $l; } $owner->{$this->attribute . $suffix} = AdminHelper::generateUrlStr($owner->{$this->sourceAttribute . $suffix}, $owner, $this->attribute, $id, $language); } }
/** * Saving related Bloc entry. */ public function afterSave($event) { $owner = $this->getOwner(); if ($owner->isNewRecord) { $contentBloc = new Bloc(); if (Yii::app()->languageManager->multilang) { $contentBloc->multilang(); } $contentBloc->parent_id = $owner->parent_id; $contentBloc->bloc_type = mb_substr($owner->tableName(), 5); $contentBloc->bloc_id = $owner->primaryKey; } else { if (Yii::app()->languageManager->multilang) { $contentBloc = Bloc::model()->multilang()->findByAttributes(array('bloc_id' => $owner->primaryKey, 'bloc_type' => mb_substr($owner->tableName(), 5))); } else { $contentBloc = Bloc::model()->findByAttributes(array('bloc_id' => $owner->primaryKey, 'bloc_type' => mb_substr($owner->tableName(), 5))); } } $contentBloc->rank = $owner->rank; $contentBloc->title_anchor = $owner->title_anchor; $contentBloc->title_page = $owner->title_page; $contentBloc->unique_id = $owner->unique_id; $contentBloc->last_modified = date('Y-m-d H:i:s'); foreach (Yii::app()->languageManager->languages as $l => $fullLanguage) { if ($l === Yii::app()->sourceLanguage) { $suffix = ''; } else { $suffix = '_' . $l; } $contentBloc->{'title' . $suffix} = $owner->{'title' . $suffix}; if ($owner->isNewRecord) { $contentBloc->{'title_url' . $suffix} = AdminHelper::generateUrlStr($owner->{'title' . $suffix}, $contentBloc, 'title_url', null, $l); } else { $contentBloc->{'title_url' . $suffix} = AdminHelper::generateUrlStr($owner->{'title' . $suffix}, $contentBloc, 'title_url', $contentBloc->id, $l); } } $contentBloc->save(false); }
public function actions() { $formSettings = array('redirect' => $this->createUrl('admin'), 'forms' => array('id' => 'mainForm', 'varName' => 'contentPage', 'models' => 'ContentPage', 'forms' => array('id' => 'blocsForm', 'blocs' => 'content', 'varName' => 'blocs'), 'onAfterSetAttributes' => function ($event) { if (Yii::app()->user->id != 'Admin-1' && isset($this->module->layouts)) { $model = $event->params['model']; if ($model->layout == '') { foreach ($this->module->layouts as $layoutName => $layoutTitle) { $model->layout = $layoutName; break; } } } }, 'onBeforeSave' => function ($event) { $model = $event->params['model']; if ($model->isNewRecord) { $alias = new CmsAlias(); foreach (Yii::app()->languageManager->languages as $language => $fullLanguage) { if ($language === Yii::app()->sourceLanguage) { $suffix = ''; } else { $suffix = '_' . $language; } $alias->{'alias' . $suffix} = AdminHelper::generateUrlStr($model->{'title' . $suffix}, $alias, 'alias', null, $language); $alias->{'title' . $suffix} = $model->{'title' . $suffix}; } $alias->section_id = CmsSection::model()->findByAttributes(array('module' => 'content'))->id; $alias->allow_children = 1; $alias->attributes = $_POST['CmsAlias']; $root = CmsAlias::model()->roots()->find(); $alias->appendTo($root); $aliasRoute = new CmsAliasRoute(); $aliasRoute->route = 'content'; $aliasRoute->alias_id = $alias->primaryKey; $aliasRoute->save(); $model->alias_id = $alias->primaryKey; } else { $alias = CmsAlias::model()->multilang()->findByPk($model->alias->id); $alias->attributes = $_POST['CmsAlias']; foreach (Yii::app()->languageManager->languages as $language => $fullLanguage) { if ($language === Yii::app()->sourceLanguage) { $suffix = ''; } else { $suffix = '_' . $language; } $alias->{'alias' . $suffix} = AdminHelper::generateUrlStr($model->{'title' . $suffix}, $alias, 'alias', $alias->id, $language); $alias->{'title' . $suffix} = $model->{'title' . $suffix}; } } if ($alias->location != 'nochange') { $decode = CJSON::decode($_POST['CmsAlias']['location']); $to = CmsAlias::model()->findByPk((int) $decode['to']); $action = $decode['action']; switch ($action) { case 'child': $alias->moveAsLast($to); break; case 'before': if ($to->isRoot()) { $alias->moveAsRoot(); } else { $alias->moveBefore($to); } break; case 'after': if ($to->isRoot()) { $alias->moveAsRoot(); } else { $alias->moveAfter($to); } break; } } else { $alias->saveNode(); } })); return array('create' => array('class' => 'application.components.actions.Create', 'formSettings' => $formSettings), 'update' => array('class' => 'application.components.actions.Update', 'formSettings' => $formSettings), 'delete' => array('class' => 'application.components.actions.Delete', 'modelClass' => 'ContentPage'), 'admin' => array('class' => 'application.components.actions.Admin', 'modelClass' => 'ContentPage')); }