From c22f6a820adf3701aaa715602352a73244ac0ffd Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Mon, 8 Apr 2024 16:18:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=BA=E5=8C=96=E6=96=87=E4=BB=B6=E6=94=B6?= =?UTF-8?q?=E9=9B=86=E4=BB=BB=E5=8A=A1=E7=9A=84=E6=90=9C=E7=B4=A0=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=EF=BC=8C=E4=BB=A5=E6=94=AF=E6=8C=81=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=AB=AF=E6=96=87=E4=BB=B6=E6=94=B6=E9=9B=86=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=8A=9F=E8=83=BD=20*=E6=9A=82=E6=9C=AA=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=9C=80=E6=96=B0=E6=94=B9=E5=8A=A8=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E4=BC=9A=E7=A0=B4=E5=9D=8F=E7=94=A8=E6=88=B7=E7=AB=AF=E9=A2=84?= =?UTF-8?q?=E6=9C=9F=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/CollectionSearch.php | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/models/CollectionSearch.php b/models/CollectionSearch.php index 38e8de4..3529e05 100644 --- a/models/CollectionSearch.php +++ b/models/CollectionSearch.php @@ -14,10 +14,10 @@ class CollectionSearch extends CollectionTasks /** * {@inheritdoc} */ - public function rules() + public function rules(): array { return [ - [['id', 'user_id'], 'integer'], + [['id', 'user_id','status'], 'integer'], [['folder_path', 'created_at', 'secret'], 'safe'], ]; } @@ -25,7 +25,7 @@ class CollectionSearch extends CollectionTasks /** * {@inheritdoc} */ - public function scenarios() + public function scenarios(): array { // bypass scenarios() implementation in the parent class return Model::scenarios(); @@ -38,9 +38,14 @@ class CollectionSearch extends CollectionTasks * * @return ActiveDataProvider */ - public function search($params) + public function search($params): ActiveDataProvider { - $query = CollectionTasks::find()->where(['user_id' => Yii::$app->user->id]); + // if user is admin + if (Yii::$app->user->can('admin')) { + $query = CollectionTasks::find(); + } else { + $query = CollectionTasks::find()->where(['user_id' => Yii::$app->user->id]); + } // add conditions that should always apply here @@ -57,11 +62,20 @@ class CollectionSearch extends CollectionTasks } // grid filtering conditions - $query->andFilterWhere([ - 'id' => $this->id, -// 'user_id' => $this->user_id, - 'created_at' => $this->created_at, - ]); + if (Yii::$app->user->can('admin')) { + $query->andFilterWhere([ + 'id' => $this->id, + 'user_id' => $this->user_id, + 'created_at' => $this->created_at, + 'status'=>$this->status, + ]); + }else{ + $query->andFilterWhere([ + 'id' => $this->id, + 'created_at' => $this->created_at, + 'status'=>$this->status, + ]); + } $query->andFilterWhere(['like', 'folder_path', $this->folder_path]) ->andFilterWhere(['like', 'secret', $this->secret]);