/**
  * 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);
     }
 }
 /**
  * Finds the gallery model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return gallery the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Gallery::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }