From 245b5800825730b234512d72507039ca94da8f78 Mon Sep 17 00:00:00 2001 From: Azat Kashapov Date: Sun, 24 Sep 2023 09:14:54 +0200 Subject: [PATCH] feat: images search --- common/models/Image.php | 2 +- modules/api/models/ImageSearch.php | 84 +++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/common/models/Image.php b/common/models/Image.php index 80ca49c..4dfb537 100644 --- a/common/models/Image.php +++ b/common/models/Image.php @@ -8,7 +8,7 @@ use yii\helpers\ArrayHelper; /** - * This is the model class for table "media". + * This is the model class for table "image". * * @property int $id * @property string|null $file_name diff --git a/modules/api/models/ImageSearch.php b/modules/api/models/ImageSearch.php index 4d25354..913e735 100644 --- a/modules/api/models/ImageSearch.php +++ b/modules/api/models/ImageSearch.php @@ -1,7 +1,89 @@ $query, + ]); + $query->joinWith('book'); + $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; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'book_id' => $this->book_id, + ]); + $query->andFilterWhere( + ['ilike', 'book.name', $this->bookName] + ); + $query->andFilterWhere(['ilike', 'file_name', $this->file_name]) + ->andFilterWhere(['ilike', 'path', $this->path]) + ->andFilterWhere(['ilike', 'book.name', $this->getAttribute('book.name')]); + + $query->groupBy('image.id'); + $dataProvider->sort->attributes['book.name'] = [ + 'asc' => ['book.name' => SORT_ASC], + 'desc' => ['book.name' => SORT_DESC], + ]; + return $dataProvider; + } }