<fieldset style="width: 45%"> <legend><?php echo Yii::t('admin', 'Routes'); ?> </legend> <?php $this->widget('application.components.widgets.TabularInput.TabularInputWidget', array('id' => 'routesForm', 'form' => $form, 'models' => $cmsAliasRoutes, 'layout' => array('_route' => new CmsAliasRoute()), 'template' => 'noheader-noborder')); ?> </fieldset> <div class="row"> <?php echo $form->labelEx($cmsAlias, 'section_id'); ?> <?php echo $form->dropDownList($cmsAlias, 'section_id', CHtml::listData(CmsSection::model()->findAll(), 'id', 'name'), array('empty' => '')); ?> <?php echo $form->error($cmsAlias, 'section_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($cmsAlias, 'allow_children'); ?> <?php echo $form->checkbox($cmsAlias, 'allow_children'); ?> <?php echo $form->error($cmsAlias, 'allow_children');
public function afterValidate() { if ($this->isNewRecord) { $auth = Yii::app()->authManager; $module = Yii::createComponent('application.modules.' . $this->module . '.' . ucfirst($this->module) . 'Module', null, null); if (!$module->instantiable && CmsSection::model()->findAllByAttributes(array('module' => $this->module)) != null) { $this->addError('module', Yii::t('admin', 'Ce module ne peut être instancié.')); } } return parent::afterValidate(); }
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')); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id, $ml = false) { if ($ml) { $model = CmsSection::model()->multilang()->findByPk((int) $id); } else { $model = CmsSection::model()->findByPk((int) $id); } if ($model === null) { throw new CHttpException(404, 'The requested post does not exist.'); } return $model; }
public function init() { $app = Yii::app(); // register dropbox autoload /* spl_autoload_unregister(array('YiiBase','autoload')); require_once 'protected/vendors/dropbox-sdk-php/lib/Dropbox/autoload.php'; spl_autoload_register(array('YiiBase','autoload')); */ $app->languageManager->restrictLanguage(Yii::app()->sourceLanguage); $app->urlManager->cancelAliasResolution = true; $app->user->loginUrl = array('/admin/login'); // There are two WebUser to not have conflicts, one for the front-end and one for the back-end, this sets it to the back-end Yii::app()->setComponent('user', Yii::app()->userBack); // Checking access if (isset($this->module->id) && in_array($this->module->id, $app->cms->modules)) { if ($this->module->instantiable == true && isset($_GET['section_id'])) { if (!($app->cms->currentSectionId = CmsSection::model()->findByPk($_GET['section_id'])->id)) { throw new CHttpException(404, 'The requested section does not exist.'); } if (!$app->user->checkAccess('adminSectionId-' . $app->cms->currentSectionId)) { $app->user->loginRequired(); } } else { if (!$app->user->checkAccess('adminModule-' . strtolower(substr(get_class($this->module), 0, strrpos(get_class($this->module), 'Module'))))) { $app->user->loginRequired(); } } } // Setting up ckeditor $ckContentCss = array('/css/admin/ck-bootstrap.css', '/css/framework.css', '/css/project.css', '/css/blocs.css', '/css/admin/ckeditor.css'); if (isset(Yii::app()->params['googleFont'])) { array_unshift($ckContentCss, Yii::app()->params['googleFont']); } $this->ckeditor = 'vendors/ckeditor/ckeditor.php'; $this->ckBasePath = Yii::app()->baseUrl . '/vendors/ckeditor/'; $this->ckEditorConfig = array('width' => '100%', 'height' => '400px', 'language' => $app->language, 'uiColor' => '#cae0ec', 'bodyId' => 'content', 'bodyClass' => 'ckeditor section-bloc bloc-editor', 'forcePasteAsPlainText' => true, 'disableReadonlyStyling' => true, 'startupShowBorders' => false, 'resize_enabled' => true, 'filebrowserUploadUrl' => $this->createUrl('/admin/ckeditorupload', array('type' => 'file')), 'filebrowserImageUploadUrl' => $this->createUrl('/admin/ckeditorupload', array('type' => 'image')), 'contentsCss' => $ckContentCss, 'format_tags' => 'p;h2;h3;h4', 'stylesSet' => 'my_styles:/javascript/ckstyles.js', 'toolbar' => 'Full', 'toolbar_Full' => array(array('Bold', 'Italic', 'Strike', 'Subscript', 'Superscript'), array('NumberedList', 'BulletedList', 'Outdent', 'Indent', 'Table'), array('Link', 'Unlink', 'Anchor', 'Image', 'MediaEmbed'), array('Format', 'Styles'), array('Cut', 'Copy', 'PasteText'), array('Undo', 'Redo', '-', 'SelectAll', 'RemoveFormat', 'Source'))); $this->ckEditorConfigSimple = array('width' => '100%', 'height' => '200px', 'uiColor' => '#cae0ec', 'language' => $app->language, 'bodyId' => 'content', 'bodyClass' => 'ckeditor section-bloc bloc-editor', 'forcePasteAsPlainText' => true, 'disableReadonlyStyling' => true, 'startupShowBorders' => false, 'resize_enabled' => true, 'contentsCss' => $ckContentCss, 'format_tags' => 'p;h2;h3;h4', 'stylesSet' => 'my_styles:/javascript/ckstyles.js', 'toolbar' => 'Full', 'toolbar_Full' => array(array('Bold', 'Italic', 'Strike', 'Subscript', 'Superscript'), array('Link', 'Unlink'), array('Undo', 'Redo'))); // Loading up js libraries //$app->clientScript->registerCoreScript('jquery'); //$app->clientScript->registerCoreScript('jquery.ui'); //$app->clientScript->registerCssFile(Yii::app()->request->baseUrl.'/css/jqueryui/backTheme/jquery-ui.css'); //$app->clientScript->registerScript('jqueryDatepickerLanguage', "$.datepicker.setDefaults($.datepicker.regional['".Yii::app()->language."']);", CClientScript::POS_READY); //$app->clientScript->registerScriptFile($app->clientScript->getCoreScriptUrl().'/jui/js/jquery-ui-i18n.min.js'); // Styling form buttons with jQuery /* $app->clientScript->registerScript('inputButtons', " $('input:submit, input:button').button(); ", CClientScript::POS_READY); */ // Setting up the menu foreach (CmsSection::model()->findAll() as $section) { if (in_array($section->module, $app->cms->modules)) { $className = $section->module . 'Module'; $moduleMenu = $className::getAdminMenu(); foreach ($moduleMenu as $moduleMenuItem) { $moduleMenuItem['label'] = str_replace('{sectionName}', $section->name, $moduleMenuItem['label']); $moduleMenuItem['url']['section_id'] = $section->id; $moduleMenuItem['icon'] = $moduleMenuItem['icon']; if (isset($moduleMenuItem['subMenu'])) { foreach ($moduleMenuItem['subMenu'] as $key => $moduleSubMenuItem) { $moduleMenuItem['subMenu'][$key]['url']['section_id'] = $section->id; } } $this->mainMenu[] = $moduleMenuItem; } } } return parent::init(); }