Exemple #1
0
 /**
  * @return array
  */
 public function getSearchSources()
 {
     return [['class' => '\\maddoger\\core\\search\\ArraySearchSource', 'data' => [['label' => Yii::t('maddoger/website', 'Pages'), 'url' => ['/' . $this->id . '/page/index']], ['label' => Yii::t('maddoger/website', 'Create new page'), 'url' => ['/' . $this->id . '/page/create']], ['label' => Yii::t('maddoger/website', 'Menus'), 'url' => ['/' . $this->id . '/menu/index']], ['label' => Yii::t('maddoger/website', 'SEO Configuration'), 'url' => ['/' . $this->id . '/config']]], 'roles' => ['website.page.view', 'website.config.manage', 'website.menu.manage']], ['class' => '\\maddoger\\core\\search\\ActiveSearchSource', 'modelClass' => '\\maddoger\\website\\common\\models\\Menu', 'searchAttributes' => ['label'], 'url' => ['/' . $this->id . '/menu/index'], 'labelPrefix' => Yii::t('maddoger/website', 'Menu - '), 'roles' => ['website.menu.manage']], ['class' => '\\maddoger\\core\\search\\ActiveSearchSource', 'query' => PageI18n::find(), 'searchAttributes' => ['title'], 'url' => function ($model) {
         return Url::to(['/' . $this->id . '/page/view', 'id' => $model['page_id']]);
     }, 'label' => 'title', 'labelPrefix' => Yii::t('maddoger/website', 'Page - '), 'roles' => ['website.page.view']]];
 }
 public function actionPages($q, $sort = 'label')
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $sortAttributes = ['title' => SORT_ASC, 'updated_at' => SORT_DESC];
     if (!$sort || !isset($sortAttributes[$sort])) {
         throw new InvalidParamException('Unknown sort field.');
     }
     $query = PageI18n::find()->where(['like', 'title', $q])->orderBy([$sort => $sortAttributes[$sort]])->with('page');
     $query->limit(20);
     $res = [];
     foreach ($query->all() as $model) {
         /**
          * @var PageI18n $model
          */
         $res[] = ['id' => $model->page_id, 'text' => $model->title, 'title' => $model->title, 'url' => $model->page->getUrl($model->language)];
     }
     return $res;
 }