/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find()->joinWith('translations'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'visible' => $this->visible, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Return all albums. * * @param bool $asArray return array * @param bool $withCategories Two-dimensional array with albums categories * * @return static[] */ public static function getAlbums($asArray = false, $withCategories = false) { if (!$withCategories) { $result = static::find()->all(); return $asArray ? ArrayHelper::map($result, 'id', 'title') : $result; } else { $result = []; $categories = Category::find()->all(); foreach ($categories as $category) { $result[$category->title] = ArrayHelper::map($category->albums, 'id', 'title'); } return $result; } }