/** * @param int $id - PageLayout ID */ public function actionCloneTemplate($id) { $model = $this->findModel($id); $newModel = new ContentTemplate(); // Clone attributes foreach ($model->attributes as $name => $value) { if (in_array($name, ['id', 'can_be_deleted'])) { continue; } if ($name == 'name') { $value .= ' (Copy)'; } $newModel->{$name} = $value; } $newModel->save(false); // Clone widget positions foreach ($model->contentTemplateHasWidgets as $prototypeLayoutWidget) { $layoutWidget = new ContentTemplateHasWidget(); $layoutWidget->content_template_id = $newModel->id; $layoutWidget->content_template_widget_id = $prototypeLayoutWidget->content_template_widget_id; $layoutWidget->position = $prototypeLayoutWidget->position; $layoutWidget->sorter = $prototypeLayoutWidget->sorter; $layoutWidget->save(false); } }
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(); }
public function search($params) { $query = ContentTemplate::find(); $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_template.created_at', strtotime($tmp[0]), strtotime($tmp[1])]); } } $query->andFilterWhere(['content_template.id' => $this->id, 'content_template.active' => $this->active, 'content_template.can_be_deleted' => $this->can_be_deleted]); $query->andFilterWhere(['like', 'content_template.name', $this->name]); return $dataProvider; }
/** * @param string $slug * * @throws \yii\web\NotFoundHttpException * @return string */ public function actionView($slug) { $contentPage = ContentPage::getDb()->cache(function () use($slug) { return ContentPage::find()->andWhere(['active' => 1, 'slug' => $slug])->one(); }, ContentModule::CACHE_TIME, new TagDependency(['tags' => ContentModule::CACHE_TAG])); if (!$contentPage) { throw new NotFoundHttpException(Yii::t('yii', 'Page not found.')); } // content_template_id is set in ContentUrlRule $templateId = Singleton::getData('content_template_id'); if ($templateId && $this->module->enableTemplates) { $template = ContentTemplate::getDb()->cache(function () use($templateId) { return ContentTemplate::find()->andWhere(['id' => $templateId, 'active' => 1])->one(); }, ContentModule::CACHE_TIME, new TagDependency(['tags' => ContentModule::CACHE_TAG])); if ($template && is_file(Yii::getAlias('@app/templates/') . $template->layout . '/layout.php')) { $this->layout = '@app/templates/' . $template->layout . '/layout.php'; } } else { $this->layout = $this->module->defaultLayout; } $breadcrumbs[] = ['label' => $contentPage->name]; // $this->prepareBreadcrumbs($contentPage, $breadcrumbs); return $this->renderIsAjax('view', compact('contentPage', 'breadcrumbs')); }
/** * @return \yii\db\ActiveQuery */ public function getContentTemplates() { return $this->hasMany(ContentTemplate::className(), ['id' => 'content_template_id'])->viaTable('{{%content_template_has_widget}}', ['content_template_widget_id' => 'id']); }
<?php if (Yii::$app->getModule('content')->enableTemplates) { ?> <div class="col-lg-4"> <?php if (count(Yii::$app->params['mlConfig']['languages']) > 1) { ?> <br/><br/> <?php } ?> <?php $templates = ContentTemplate::find()->active()->asArray()->all(); if (count($templates) == 1 and !$model->content_template_id) { $model->content_template_id = $templates[0]; } ?> <?php echo $form->field($model, 'content_template_id', ['options' => ['class' => 'required']])->dropDownList(ArrayHelper::map($templates, 'id', 'name'), ['prompt' => '']); ?> </div> <?php } ?>
<div class="col-sm-12"> <?php echo ContentTemplate::renderWidgets('center_top'); ?> </div> <div class="col-sm-12"> <?php echo $content; ?> </div> <div class="col-sm-12"> <?php echo ContentTemplate::renderWidgets('center_bottom'); ?> </div> </div> </div> <div class="col-sm-3"> <?php echo ContentTemplate::renderWidgets('right'); ?> </div> </div> </div> <?php $this->endContent();
/** * @return \yii\db\ActiveQuery */ public function getContentTemplate() { return $this->hasOne(ContentTemplate::className(), ['id' => 'content_template_id']); }
?> </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>