/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = WebTag::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'base_id' => $this->base_id, 'language_id' => $this->language_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'label', $this->label]); return $dataProvider; }
/** * Lists all WebTag models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => WebTag::find()->joinWith(['base', 'language'], true)->orderBy('base_tags.code')]); return $this->render('index', ['dataProvider' => $dataProvider, 'emptyBaseTags' => BaseTag::find()->withoutWebTags()->asArray()->all()]); }
/** * Renvoie la liste des tags associés à $this * * @param bool $useCache utilise un cache interne. false => on relance la requête à chaque fois. Vaut true par défaut. * @return array [WebTag] */ public function getTags($useCache = true) { if (!$useCache || is_null($this->tags)) { $this->tags = WebTag::find()->forWebNews($this->id)->addOrderBy('web_tags.label ASC')->all(); } return $this->tags; }
/** * Affichage de la liste des objets, avec ou sans filtre selon le contenu de la session * (frontend) * * @param int $page Numéro de la page courante (commence à 1) * @return mixed */ public function actionDisplaySearchResults($page) { // Récupération d'une liste éventuellement filtrée selon les critères du moteur de recherche $searchModel = new WebNewsSearch(); $advancedSearchFilters = $searchModel->retrieveFiltersFromSession(); $dataProvider = $searchModel->search($advancedSearchFilters); // Détermination de l'ordre de tri $sortClausesSessionKey = WebNews::class . '.display-search-results.sort'; $dataProvider->query = ListSorter::updateQuery($dataProvider->query, $sortClausesSessionKey); Yii::$app->session->set(WebNews::class . '.index.page', $page); $dataProvider->pagination->page = --$page; /** @var HCms $module */ $module = $this->module; if (isset($module->frontendLayout)) { $this->layout = $module->frontendLayout; } /** @noinspection PhpUndefinedMethodInspection */ return $this->render('displaySearchResults', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'tags' => ArrayHelper::map(WebTag::find()->byLanguageCode(h::getIso639Code())->orderByLabel()->all(), 'id', 'label'), 'sortClausesSessionKey' => $sortClausesSessionKey]); }