优化文件分享管理的搜素条件

This commit is contained in:
Chenx221 2024-04-07 14:35:30 +08:00
parent e0d2fb1bc4
commit 8b0a5a5c9b
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021

View File

@ -17,7 +17,7 @@ class ShareSearch extends Share
public function rules(): array
{
return [
[['share_id', 'sharer_id'], 'integer'],
[['share_id', 'sharer_id', 'status','dl_count'], 'integer'],
[['file_relative_path', 'access_code', 'creation_date'], 'safe'],
];
}
@ -40,8 +40,13 @@ class ShareSearch extends Share
*/
public function search($params): ActiveDataProvider
{
// if user can admin, show all shares
if (Yii::$app->user->can('admin')) {
$query = Share::find();
} else {
// if user can't admin, show only shares created by the user
$query = Share::find()->where(['sharer_id' => Yii::$app->user->id]);
}
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
@ -57,11 +62,28 @@ class ShareSearch extends Share
}
// grid filtering conditions
if (Yii::$app->user->can('admin')) {
$query->andFilterWhere([
'share_id' => $this->share_id,
'sharer_id' => $this->sharer_id,
'creation_date' => $this->creation_date,
'file_relative_path' => $this->file_relative_path,
'access_code' => $this->access_code,
'status' => $this->status,
'dl_count' => $this->dl_count,
]);
} else {
$query->andFilterWhere([
'share_id' => $this->share_id,
// 'sharer_id' => $this->sharer_id,
'creation_date' => $this->creation_date,
'file_relative_path' => $this->file_relative_path,
'access_code' => $this->access_code,
'status' => $this->status,
'dl_count' => $this->dl_count,
]);
}
$query->andFilterWhere(['like', 'file_relative_path', $this->file_relative_path])
->andFilterWhere(['like', 'access_code', $this->access_code]);