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();
 }
 /**
  * @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'));
 }
Exemplo n.º 3
0
 public function search($params)
 {
     $query = ContentPage::find();
     if (!Yii::$app->request->get('sort')) {
         $query->orderBy('content_page.sorter');
     }
     $query->joinWith(['contentTemplate', 'contentMenu']);
     $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_page.created_at', strtotime($tmp[0]), strtotime($tmp[1])]);
         }
     }
     $query->andFilterWhere(['content_page.id' => $this->id, 'content_page.active' => $this->active, 'content_page.sorter' => $this->sorter, 'content_page.is_main' => $this->is_main, 'content_page.type' => $this->type, 'content_page.parent_id' => $this->parent_id, 'content_page.content_template_id' => $this->content_template_id, 'content_page.content_menu_id' => $this->content_menu_id]);
     $query->andFilterWhere(['like', 'content_page.name', $this->name])->andFilterWhere(['like', 'content_page.slug', $this->slug])->andFilterWhere(['like', 'content_page.meta_title', $this->meta_title])->andFilterWhere(['like', 'content_page.meta_keywords', $this->meta_keywords])->andFilterWhere(['like', 'content_page.meta_description', $this->meta_description]);
     return $dataProvider;
 }
Exemplo n.º 4
0
 /**
  * @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'));
 }
Exemplo n.º 5
0
 /**
  * Prepare array of all pages indexed by slug
  *
  * @return array
  */
 protected function getAllPages()
 {
     if ($this->_pagesBySlug === null) {
         $this->_pagesBySlug = ContentPage::getDb()->cache(function () {
             return ContentPage::find()->select(['id', 'slug', 'is_main', 'parent_id', 'type', 'content_template_id'])->asArray()->andWhere(['active' => 1, 'type' => [ContentPage::TYPE_TEXT, ContentPage::TYPE_INTERNAL_LINK]])->indexBy('slug')->all();
         }, ContentModule::CACHE_TIME, new TagDependency(['tags' => ContentModule::CACHE_TAG]));
     }
     return $this->_pagesBySlug;
 }
Exemplo n.º 6
0
echo ButtonDropdown::widget(['label' => '<span class="glyphicon glyphicon-plus-sign"></span> ' . ContentModule::t('app', 'Create'), 'options' => ['class' => 'btn btn-success btn-sm'], 'encodeLabel' => false, 'dropdown' => ['items' => [['label' => ContentModule::t('app', 'Text page'), 'url' => Url::to(['create', 'type' => ContentPage::TYPE_TEXT, 'menuId' => $menuId])], ['label' => ContentModule::t('app', 'Internal link'), 'url' => Url::to(['create', 'type' => ContentPage::TYPE_INTERNAL_LINK, 'menuId' => $menuId])], ['label' => ContentModule::t('app', 'External link'), 'url' => Url::to(['create', 'type' => ContentPage::TYPE_EXTERNAL_LINK, 'menuId' => $menuId])]]]]);
?>
		<?php 
echo JQTreeWidget::widget(['models' => $pages, 'modelName' => 'webvimark\\ybc\\content\\models\\ContentPage', 'parentIdField' => 'parent_id', 'statusField' => 'active', 'orderField' => 'sorter', 'showExpandAndCollapse' => false, 'withChildren' => $hasSubmenu === 1, 'leafName' => function (ContentPage $model) {
    $pageName = $model->is_main == 1 ? '<span style="color:green; font-style: italic;">' . $model->name . '</span>' : $model->name;
    if ($model->type == ContentPage::TYPE_TEXT) {
        $pageType = ' <span class="page-tree-type">' . ContentModule::t('app', 'Text page') . '</span>';
        if ($model->is_main == 1) {
            $viewUrl = Yii::$app->homeUrl;
        } else {
            $viewUrl = ['/content/default/view', 'slug' => $model->slug];
        }
    } elseif ($model->type == ContentPage::TYPE_INTERNAL_LINK) {
        $pageType = ' <span class="page-tree-type">' . ContentModule::t('app', 'Internal link') . '</span>';
        if (is_numeric($model->slug)) {
            $page = ContentPage::find()->andWhere(['id' => $model->slug])->one();
            $viewUrl = $page ? ['/content/default/view', 'slug' => $page->slug] : Yii::$app->homeUrl;
        } else {
            $viewUrl = Yii::$app->homeUrl . $model->slug;
        }
    } else {
        $pageType = ' <span class="page-tree-type">' . ContentModule::t('app', 'External link') . '</span>';
        $viewUrl = $model->slug;
    }
    $editLink = Html::a($pageName . $pageType, ['/content/content-page/update', 'id' => $model->id]);
    $viewLink = Html::a('<i class="fa fa-eye"></i>', $viewUrl, ['target' => '_blank']);
    return $editLink . ' ' . $viewLink;
}]);
?>

	</div>
Exemplo n.º 7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContentPages()
 {
     return $this->hasMany(ContentPage::className(), ['content_template_id' => 'id']);
 }
Exemplo n.º 8
0
 /**
  * Make sure that only 1 main page exists
  *
  * @param bool $insert
  *
  * @return bool
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->type == static::TYPE_TEXT) {
             $this->slug = LittleBigHelper::slug($this->slug ? $this->slug : $this->name);
         }
         if ($this->is_main == 1 && ($insert || $this->oldAttributes['is_main'] == 0)) {
             ContentPage::updateAll(['is_main' => 0]);
             $this->active = 1;
         }
         return true;
     }
     return false;
 }
Exemplo n.º 9
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>