/**
  * Creates data provider instance with search query applied
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Gallery::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created' => SORT_DESC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Esempio n. 2
0
 public function run()
 {
     $dependency = new DbDependency();
     $dependency->sql = 'SELECT MAX(updated) FROM {{%gallery}}';
     $model = BaseGallery::getDb()->cache(function () {
         return BaseGallery::find()->where('id = :id', [':id' => $this->galleryId])->active()->one();
     }, Yii::$app->getModule('gallery')->queryCacheDuration, $dependency);
     if (is_null($model) || !count($model->files)) {
         return false;
     }
     if (!is_null($this->template)) {
         return $this->render($this->template, ['model' => $model, 'models' => $model->files]);
     } else {
         return $this->getDefaultGallery($model);
     }
 }