Esempio n. 1
0
 /**
  * Shows a single page.
  *
  * @param string $alias a page alias (slug).
  * @return string the rendering result of this action.
  * @throws InvalidParamException if a model with the provided id is not found. 
  */
 public function actionShow($alias)
 {
     $model = Page::find()->where(['alias' => $alias])->byState(Page::STATE_ACTIVE)->one();
     if (!$model) {
         throw new NotFoundHttpException(Yii::t('cms', 'Page not found.'));
     }
     Yii::$app->big->setTemplate($model->template_id);
     return $this->render('index', ['model' => $model]);
 }
Esempio n. 2
0
 /**
  * Runs the block.
  *
  * @return string the content of this block.
  */
 public function run()
 {
     $orderCondition = $this->model->order_by . ' ' . $this->model->order_direction;
     $maxPages = (int) $this->model->max_pages;
     $query = Page::find()->byCategory($this->model->category_id)->byState(Page::STATE_ACTIVE)->orderBy($orderCondition)->with(['author', 'editor']);
     if ($maxPages > 0) {
         $query->limit($this->model->max_pages);
     }
     $pages = $query->asArray()->all();
     return $this->render('index', ['block' => $this, 'pages' => $pages]);
 }
Esempio n. 3
0
 /**
  * Returns a [[ActiveDataProvider]] filter by the provided paramters.
  *
  * @param array $params list of parameters to filter pages by.
  */
 public function search($params)
 {
     $query = Page::find()->with(['category']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params, '') && $this->validate())) {
         return $dataProvider;
     }
     if ($this->id) {
         $query->byCategory($this->id);
     }
     if ($this->q) {
         $query->andWhere(['like', 'title', $this->q]);
     }
     $dataProvider->query = $query;
     return $dataProvider;
 }
Esempio n. 4
0
 /**
  * Deletes a page after a form submission.
  *
  * @param int $id an id of a page to delete. Must match id in posted form.
  * @throws InvalidCallException if provided id does not match id in posted form.
  */
 public function actionDelete($id)
 {
     $pageId = Yii::$app->getRequest()->post('id');
     if ($pageId != $id) {
         throw new InvalidCallException("Invalid form submitted. Page with id: '{$id}' not deleted.");
     }
     $model = Page::findOne($id);
     if ($model) {
         if ($model->delete()) {
             Yii::$app->getSession()->setFlash('success', Yii::t('cms', 'Page deleted.'));
         } else {
             Yii::$app->getSession()->setFlash('info', Yii::t('cms', 'Page not deleted, please try again.'));
         }
     } else {
         Yii::$app->getSession()->setFlash('error', Yii::t('cms', 'Page with id "{id}" not found.', ['id' => $id]));
     }
     return $this->redirect(['index']);
 }
Esempio n. 5
0
 /**
  * Shows pages from a single category.
  *
  * @param int $catid id of a category to load pages from.
  * @return string the rendering result.
  */
 public function actionPages($catid)
 {
     $category = Yii::$app->big->categoryManager->getItem($catid);
     if (!$category) {
         throw new NotFoundHttpException(Yii::t('cms', 'Category not found.'));
     }
     Yii::$app->big->setTemplate($category->template_id);
     $sortBy = 'created_at';
     $params = $category->params;
     if (isset($params['sort_by'])) {
         $sortBy = $params['sort_by'] . ' ' . $params['sort_direction'];
     }
     $pages = Page::find()->with(['author', 'editor'])->byCategory($catid)->byState(Page::STATE_ACTIVE)->orderBy($sortBy)->asArray()->all();
     foreach ($pages as &$page) {
         $page['params'] = Json::decode($page['params']);
     }
     return $this->render('pages', ['category' => $category, 'pages' => $pages]);
 }
Esempio n. 6
0
 /**
  * Registers page content when big performs a search.
  * See [[bigbrush\big\core\Big::search()]] for more information about the search process.
  *
  * @param bigbrush\big\core\SearchEvent $event the event being triggered
  */
 public static function onSearch($event)
 {
     $query = Page::find()->select(['id', 'title', 'category_id', 'alias', 'intro_content', 'created_at'])->orderBy('title')->asArray();
     // adjust query if $event->value is not empty. Then a search for a specific value is being made.
     if (!empty($event->value)) {
         $query->orWhere(['like', 'title', $event->value]);
         $query->orWhere(['like', 'content', $event->value]);
     }
     $items = $query->all();
     foreach ($items as $item) {
         $event->addItem(['title' => $item['title'], 'route' => Route::page($item), 'text' => $item['intro_content'], 'date' => $item['created_at'], 'section' => Yii::t('cms', 'Pages')]);
     }
     // pages categories
     foreach (Yii::$app->big->categoryManager->getItems('pages') as $item) {
         // $event->value is a value being searched for. If set then only include the category when its title matches
         // the search string
         if (!empty($event->value) && strpos($item->title, $event->value) === false) {
             continue;
         }
         // match found so add it in the $event
         $event->addItem(['title' => str_repeat('- ', $item->depth - 1) . $item->title, 'route' => Route::category($item), 'text' => $item->content, 'date' => $item->created_at, 'section' => Yii::t('cms', 'Pages categories')]);
     }
 }
Esempio n. 7
0
<?php

/**
 * @link http://www.bigbrush-agency.com/
 * @copyright Copyright (c) 2015 Big Brush Agency ApS
 * @license http://www.bigbrush-agency.com/license/
 */
use yii\helpers\Html;
use yii\data\ArrayDataProvider;
use yii\grid\GridView;
use bigbrush\cms\modules\pages\models\Page;
$models = Page::find()->orderBy('updated_at')->limit(5)->asArray()->all();
$dataProvider = new ArrayDataProvider(['allModels' => $models]);
$boxContent = '<div class="table-responsive">';
$boxContent .= GridView::widget(['dataProvider' => $dataProvider, 'tableOptions' => ['class' => 'table'], 'showHeader' => false, 'summary' => '', 'columns' => [['header' => Yii::t('cms', 'Title'), 'format' => 'raw', 'value' => function ($data) {
    return Html::a($data['title'], ['/pages/page/edit', 'id' => $data['id']]);
}]]]);
$boxContent .= '</div>';
$boxContent .= Html::a('<i class="fa fa-plus-circle"></i> ' . Yii::t('cms', 'New page'), ['/pages/page/edit'], ['class' => 'btn btn-sm btn-primary pull-left']);
$boxContent .= Html::a('<i class="fa fa-eye"></i> ' . Yii::t('cms', 'See all'), ['/pages/page/index'], ['class' => 'btn btn-sm btn-default pull-right']);
$this->title = Yii::t('cms', 'Welcome to Big CMS');
$this->registerJs('
    $(".box").activateBox();
');
?>
<div class="row">
    <div class="col-md-12">
        <h1><?php 
echo $this->title;
?>
</h1>