/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new ContentMenu(); if ($model->load(Yii::$app->request->post()) && $model->convertPositionIds() && $model->save()) { return $this->redirect($this->getRedirectPage('create', $model)); } return $this->renderIsAjax('create', compact('model')); }
public function safeDown() { ContentPage::deleteAll(); ContentTemplateWidget::deleteAll(['name' => ['Side menu', 'Top menu']]); ContentTemplate::deleteIfExists(['name' => 'Default']); ContentMenu::deleteAll(['code' => ['topMenu', 'sideMenu']]); Yii::$app->cache->flush(); }
/** * List of items for backend side menu * * @return array */ public static function getSideMenuItems() { $output = ['17' => ['label' => '<i class="fa fa-pagelines"></i> ' . ContentModule::t('app', 'Page templates'), 'url' => ['/content/content-template/index'], 'visible' => Yii::$app->getModule('content')->enableTemplates && User::canRoute(['/content/content-template/index'])], '18' => ['label' => '<i class="fa fa-code-fork"></i> ' . ContentModule::t('app', 'Template widgets'), 'url' => ['/content/content-template-widget/index'], 'visible' => Yii::$app->getModule('content')->enableTemplates && User::canRoute(['/content/content-template-widget/index'])], '19' => ['label' => '<i class="fa fa-table"></i> ' . ContentModule::t('app', 'Manage menus'), 'url' => ['/content/content-menu/index']]]; $menus = ContentMenu::getListOfMenus(); krsort($menus); foreach ($menus as $menu) { array_unshift($output, $menu); } return $output; }
/** * @inheritdoc */ public function actionUpdate($id) { $model = $this->findModel($id); $hasMenuImage = $model->contentMenu && $model->contentMenu->has_menu_image === 1; $menuName = $model->contentMenu ? $model->contentMenu->name : ContentMenu::withoutMenuName(); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { if ($model->oldAttributes['content_menu_id'] != $model->content_menu_id) { $model->parent_id = null; } $model->save(false); return $this->redirect(['tree', 'menuId' => $model->content_menu_id]); } } return $this->renderIsAjax('update', compact('model', 'menuName', 'hasMenuImage')); }
public function search($params) { $query = ContentMenu::find(); if (!Yii::$app->request->get('sort')) { $query->orderBy('content_menu.sorter'); } $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } if ($this->created_at) { $tmp = explode(' - ', $this->created_at); if (isset($tmp[0], $tmp[1])) { $query->andFilterWhere(['between', 'content_menu.created_at', strtotime($tmp[0]), strtotime($tmp[1])]); } } $query->andFilterWhere(['content_menu.id' => $this->id, 'content_menu.active' => $this->active, 'content_menu.has_submenu' => $this->has_submenu]); $query->andFilterWhere(['like', 'content_menu.name', $this->name])->andFilterWhere(['like', 'content_menu.code', $this->code]); if ($this->position) { $query->andFilterWhere(['like', 'content_menu.position', '|' . $this->position . '|']); } return $dataProvider; }
/** * Fill items with ContentMenu elements */ public function init() { $this->items = ContentMenu::getItemsForMenu($this->code); }
} ?> <?php echo $form->field($model->loadDefaultValues(), 'open_in_new_tab', ['template' => '<div class="row"><div class="col-sm-6 text-right" style="margin-top: 5px">{label}</div><div class="col-sm-6">{input}{error}{hint}</div></div>'])->checkbox(['class' => 'b-switch'], false); ?> </div> <div class="col-sm-6"> <?php echo $form->field($model, 'content_menu_id')->dropDownList(ArrayHelper::map(ContentMenu::find()->asArray()->all(), 'id', 'name'), ['prompt' => '']); ?> <?php if ($hasMenuImage) { ?> <?php if (!$model->isNewRecord and is_file($model->getImagePath('medium', 'menu_image'))) { ?> <div class='form-group'> <div class='col-sm-3'></div> <div class='col-sm-6'> <?php echo Html::img($model->getImageUrl('medium', 'menu_image'), ['alt' => 'menu_image']); ?> </div>
/** * Invalidate cache * * @param bool $insert * @param array $changedAttributes */ public function afterSave($insert, $changedAttributes) { if (!$insert and array_key_exists('content_menu_id', $changedAttributes)) { $menu = ContentMenu::find()->andWhere(['id' => $this->content_menu_id])->one(); foreach ($this->contentPages as $child) { if ($menu->has_submenu != 1) { $child->parent_id = null; } $child->content_menu_id = $this->content_menu_id; $child->save(false); } } TagDependency::invalidate(Yii::$app->cache, ContentModule::CACHE_TAG); parent::afterSave($insert, $changedAttributes); }
?> </p> </div> <div class="col-xs-6 text-right"> <?php echo GridPageSize::widget(['pjaxId' => 'content-page-grid-pjax']); ?> </div> </div> <?php Pjax::begin(['id' => 'content-page-grid-pjax']); ?> <?php echo GridView::widget(['id' => 'content-page-grid', 'dataProvider' => $dataProvider, 'pager' => ['options' => ['class' => 'pagination pagination-sm'], 'hideOnSinglePage' => true, 'lastPageLabel' => '>>', 'firstPageLabel' => '<<'], 'layout' => '{items}<div class="row"><div class="col-sm-8">{pager}</div><div class="col-sm-4 text-right">{summary}' . GridBulkActions::widget(['gridId' => 'content-page-grid']) . '</div></div>', 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'options' => ['style' => 'width:10px']], ['attribute' => 'name', 'value' => function ($model) { return Html::a($model->name, ['update', 'id' => $model->id], ['data-pjax' => 0]); }, 'format' => 'raw'], ['class' => 'webvimark\\components\\StatusColumn', 'attribute' => 'is_main', 'toggleUrl' => Url::to(['toggle-attribute', 'attribute' => 'is_main', 'id' => '_id_'])], 'type', 'slug', ['value' => function (ContentPage $model) { return Html::img($model->getImageUrl('small', 'menu_image')); }, 'contentOptions' => ['width' => '10px'], 'format' => 'raw'], ['attribute' => 'parent_id', 'filter' => ArrayHelper::map(ContentPage::find()->asArray()->all(), 'id', 'name'), 'value' => 'parent.name'], ['attribute' => 'content_template_id', 'filter' => ArrayHelper::map(ContentTemplate::find()->asArray()->all(), 'id', 'name'), 'value' => 'contentTemplate.name'], ['attribute' => 'content_menu_id', 'filter' => ArrayHelper::map(ContentMenu::find()->asArray()->all(), 'id', 'name'), 'value' => 'contentMenu.name'], ['class' => 'webvimark\\components\\StatusColumn', 'attribute' => 'active', 'toggleUrl' => Url::to(['toggle-attribute', 'attribute' => 'active', 'id' => '_id_'])], ['class' => 'webvimark\\components\\SorterColumn'], ['class' => 'yii\\grid\\CheckboxColumn', 'options' => ['style' => 'width:10px']], ['class' => 'yii\\grid\\ActionColumn', 'contentOptions' => ['style' => 'width:70px; text-align:center;']]]]); ?> <?php Pjax::end(); ?> </div> </div> </div>