コード例 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Page::find();
     $query->with(['tags', 'parent']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['lft' => SORT_ASC]]]);
     if (!($this->load($params) && $this->validate())) {
         if ($this->excludeRoots) {
             $query->excludeRoots();
         }
         return $dataProvider;
     }
     $query->andFilterWhere(['{{%core_page}}.id' => $this->id, '{{%core_page}}.parent_id' => $this->parent_id, '{{%core_page}}.created_at' => $this->created_at, '{{%core_page}}.updated_at' => $this->updated_at, '{{%core_page}}.status' => $this->status, '{{%core_page}}.created_by' => $this->created_by, '{{%core_page}}.updated_by' => $this->updated_by, '{{%core_page}}.lft' => $this->lft, '{{%core_page}}.rgt' => $this->rgt, '{{%core_page}}.level' => $this->level, '{{%core_page}}.ordering' => $this->ordering, '{{%core_page}}.hits' => $this->hits, '{{%core_page}}.lock' => $this->lock]);
     $query->andFilterWhere(['like', '{{%core_page}}.title', $this->title])->andFilterWhere(['like', '{{%core_page}}.path', $this->path])->andFilterWhere(['like', '{{%core_page}}.alias', $this->alias])->andFilterWhere(['like', '{{%core_page}}.preview_text', $this->preview_text])->andFilterWhere(['like', '{{%core_page}}.detail_text', $this->detail_text])->andFilterWhere(['like', '{{%core_page}}.metakey', $this->metakey])->andFilterWhere(['like', '{{%core_page}}.metadesc', $this->metadesc]);
     if ($this->excludeRoots) {
         $query->excludeRoots();
     }
     if ($this->excludePage && ($page = Page::findOne($this->excludePage))) {
         /** @var $page Page */
         $query->excludePage($page);
     }
     if ($this->tags) {
         $query->innerJoinWith('tags')->andFilterWhere(['{{%core_tag}}.id' => $this->tags]);
     }
     return $dataProvider;
 }
コード例 #2
0
 public function loadModel($id)
 {
     if (!($model = Page::find()->where(['id' => $id])->published()->one())) {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.'));
     }
     return $model;
 }
コード例 #3
0
ファイル: PageView.php プロジェクト: ezsky/yii2-platform-core
 public function init()
 {
     if ($this->page && !$this->page instanceof Page) {
         $this->page = Page::findOne(intval($this->page));
     }
     if (empty($this->page)) {
         throw new InvalidConfigException(Yii::t('gromver.platform', 'Page not found.'));
     }
 }
コード例 #4
0
 protected function getViewData()
 {
     /** items list */
     if ($this->page->level - $this->rootPage->level > 1) {
         $listRoot = $this->page->parents($this->page->isLeaf() ? 2 : 1)->one();
     } else {
         $listRoot = $this->rootPage;
     }
     /** @var $items \gromver\platform\core\modules\page\models\Page[] */
     $items = $listRoot->children(2)->published()->all();
     if (count($items)) {
         $items = $this->prepareItems($items, $items[0]->level, $hasActiveChild);
     }
     /** nav */
     $model = $this->page;
     $prevModel = $nextModel = null;
     // предыдущая страница
     if (!$this->rootPage->equals($this->page)) {
         if ($prevModel = $model->prev()->published()->one()) {
             //пытаемся найти лист(правый)
             if ($rgtLeaf = $prevModel->leaves()->published()->orderBy(['lft' => SORT_DESC])->one()) {
                 $prevModel = $rgtLeaf;
             }
         } else {
             $prevModel = $model->parent;
         }
     }
     // следущая страница
     if ($this->rootPage->equals($this->page)) {
         $nextModel = $model->children(1)->published()->one();
     } else {
         if (!($nextModel = $model->children(1)->published()->one() or $nextModel = $model->next()->published()->one())) {
             //пытаемся выйти наверх
             while (($parentModel = $model->parent) && !$parentModel->equals($this->rootPage)) {
                 if ($nextModel = $parentModel->next()->one()) {
                     break;
                 }
                 $model = $parentModel;
             }
         }
     }
     return [$items, $prevModel, $nextModel];
 }
コード例 #5
0
ファイル: Page.php プロジェクト: ezsky/yii2-platform-core
 /**
  * @param $event \gromver\platform\core\modules\search\modules\sql\widgets\events\SqlBeforeSearchEvent
  */
 public static function sqlBeforeFrontendSearch($event)
 {
     if ($event->modelClass == self::className()) {
         $event->query->andWhere(['AND', ['=', 'model_class', self::className()], ['NOT IN', 'model_id', Page::find()->unpublished()->select('{{%core_page}}.id')->column()]]);
     }
 }
コード例 #6
0
ファイル: select.php プロジェクト: ezsky/yii2-platform-core
 */
$this->title = Yii::t('gromver.platform', 'Select Page');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="page-index">

	<?php 
/*<h1><?= Html::encode($this->title) ?></h1>*/
?>

	<?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

	<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'id' => 'grid', 'pjax' => true, 'pjaxSettings' => ['neverTimeout' => true], 'columns' => [['attribute' => 'id', 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'width' => '60px'], ['attribute' => 'title', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var \gromver\platform\core\modules\page\models\Page $model */
    return str_repeat(" • ", max($model->level - 2, 0)) . $model->title . '<br/>' . Html::tag('small', ' — ' . $model->path, ['class' => 'text-muted']);
}, 'format' => 'html'], ['attribute' => 'status', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \gromver\platform\core\modules\page\models\Page */
    return $model->getStatusLabel();
}, 'width' => '100px', 'filter' => \gromver\platform\core\modules\page\models\Page::statusLabels()], ['attribute' => 'tags', 'width' => '120px', 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) {
    /** @var $model \gromver\platform\core\modules\page\models\Page */
    return implode(', ', \yii\helpers\ArrayHelper::map($model->tags, 'id', 'title'));
}, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => \yii\helpers\ArrayHelper::map(\gromver\platform\core\modules\tag\models\Tag::find()->where(['id' => $searchModel->tags])->all(), 'id', 'title'), 'theme' => \kartik\select2\Select2::THEME_BOOTSTRAP, 'pluginOptions' => ['allowClear' => true, 'placeholder' => Yii::t('gromver.platform', 'Select ...'), 'ajax' => ['url' => \yii\helpers\Url::to(['/tag/backend/default/tag-list'])]]]], ['header' => Yii::t('gromver.platform', 'Action'), 'hAlign' => GridView::ALIGN_CENTER, 'vAlign' => GridView::ALIGN_MIDDLE, 'value' => function ($model) use($route) {
    /** @var $model \gromver\platform\core\modules\page\models\Page */
    return Html::a(Yii::t('gromver.platform', 'Select'), '#', ['class' => 'btn btn-primary btn-xs', 'onclick' => \gromver\widgets\ModalIFrame::postDataJs(['id' => $model->id, 'title' => $model->title, 'description' => Yii::t('gromver.platform', 'Page: {title}', ['title' => $model->title]), 'route' => \gromver\platform\core\modules\menu\models\MenuItem::toRoute($route, ['id' => $model->id]), 'link' => Yii::$app->urlManager->createUrl($model->getFrontendViewLink()), 'value' => $model->id . ':' . $model->alias])]);
}, 'width' => '80px', 'mergeHeader' => true, 'format' => 'raw']], 'responsive' => true, 'hover' => true, 'condensed' => true, 'floatHeader' => true, 'floatHeaderOptions' => ['scrollingTop' => 0], 'bordered' => false, 'panel' => ['heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-th-list"></i> ' . Html::encode($this->title) . '</h3>', 'type' => 'info', 'after' => Html::a('<i class="glyphicon glyphicon-repeat"></i> ' . Yii::t('gromver.platform', 'Reset List'), [null], ['class' => 'btn btn-info']), 'showFooter' => false]]);
?>

</div>
コード例 #7
0
ファイル: Module.php プロジェクト: ezsky/yii2-platform-core
 /**
  * @inheritdoc
  */
 public function events()
 {
     return [Desktop::EVENT_FETCH_ITEMS => 'addDesktopItem', MenuItemRoutes::EVENT_FETCH_ITEMS => 'addMenuItemRoutes', MenuUrlRule::EVENT_FETCH_MODULE_ROUTERS => 'addMenuRouter', SqlSearchResults::EVENT_BEFORE_SEARCH => [Page::className(), 'sqlBeforeFrontendSearch'], ElasticSearchResults::EVENT_BEFORE_SEARCH => [Page::className(), 'elasticBeforeFrontendSearch'], SearchResultsBackend::EVENT_FETCH_SEARCHABLE_MODELS => 'addSearchableModelsBackend', SearchResultsFrontend::EVENT_FETCH_SEARCHABLE_MODELS => 'addSearchableModelsFrontend'];
 }
コード例 #8
0
 /**
  * Finds the Page model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Page the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Page::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.'));
     }
 }
コード例 #9
0
 /**
  * Находит путь к пункту меню ссылающемуся на категорию $categoryId, либо ее предка
  * Если путь ведет к предку, то достраиваем путь категории $categoryId
  * @param $pageId
  * @param $menuMap \gromver\platform\core\components\MenuMap
  * @return null|string
  */
 private function findPageMenuPath($pageId, $menuMap)
 {
     /** @var Page $page */
     if (!isset($this->_pagePaths[$pageId])) {
         if ($path = $menuMap->getMenuPathByRoute(MenuItem::toRoute('page/frontend/default/guide', ['id' => $pageId]))) {
             $this->_pagePaths[$pageId] = $path;
         } elseif (($page = Page::findOne($pageId)) && !$page->isRoot() && ($path = $this->findPageMenuPath($page->parent_id, $menuMap))) {
             $this->_pagePaths[$pageId] = $path . '/' . $page->alias;
         } else {
             $this->_pagePaths[$pageId] = false;
         }
     }
     return $this->_pagePaths[$pageId];
 }