Ejemplo 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]);
 }
Ejemplo 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]);
 }
Ejemplo 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;
 }
Ejemplo n.º 4
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]);
 }
Ejemplo n.º 5
0
 /**
  * Creates and edits a page.
  *
  * @param int optional id of a page to edit. If id is not provided
  * a new page is created.
  * @return string
  */
 public function actionEdit($id = 0)
 {
     $model = new Page();
     if ($id) {
         $model = Page::find()->where(['id' => $id])->with(['author', 'editor'])->one();
     } else {
         $model->images['config'] = Gallery::getDefaultOptions();
     }
     $request = Yii::$app->getRequest();
     if ($model->load($request->post()) && $model->save()) {
         Yii::$app->getSession()->setFlash('success', Yii::t('cms', 'Page saved'));
         if (Yii::$app->toolbar->stayAfterSave()) {
             return $this->redirect(['edit', 'id' => $model->id]);
         } else {
             return $this->redirect(['index']);
         }
     }
     $categories = Yii::$app->big->categoryManager->getDropDownList('pages');
     $templates = Yii::$app->big->templateManager->getDropDownList(Yii::t('cms', '- Use default template -'));
     return $this->render('edit', ['model' => $model, 'templates' => $templates, 'categories' => $categories]);
 }
Ejemplo 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')]);
     }
 }
Ejemplo 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>