/**
  * @inheritdoc
  */
 public function actionCreate($type = null, $menuId = null)
 {
     if (!in_array($type, [ContentPage::TYPE_TEXT, ContentPage::TYPE_INTERNAL_LINK, ContentPage::TYPE_EXTERNAL_LINK])) {
         throw new NotSupportedException('Type = ' . $type . ' is not supported');
     }
     $menuName = ContentMenu::withoutMenuName();
     $hasMenuImage = false;
     if ($menuId) {
         $contentMenu = ContentMenu::find()->andWhere(['id' => $menuId, 'active' => 1])->one();
         if (!$contentMenu) {
             throw new NotFoundHttpException(ContentModule::t('app', 'Menu not found'));
         }
         $menuName = $contentMenu->name;
         $hasMenuImage = $contentMenu->has_menu_image === 1;
     }
     $model = new ContentPage(['type' => $type, 'content_menu_id' => $menuId]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['tree', 'menuId' => $model->content_menu_id]);
     }
     return $this->renderIsAjax('create', 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;
 }
Esempio n. 3
0
}
?>



					<?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>
Esempio n. 4
0
 /**
  * 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);
 }
Esempio n. 5
0
?>
					</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>