优化文件分享管理的搜素条件
This commit is contained in:
parent
e0d2fb1bc4
commit
8b0a5a5c9b
@ -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
|
||||
{
|
||||
$query = Share::find()->where(['sharer_id' => Yii::$app->user->id]);
|
||||
|
||||
// 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
|
||||
$query->andFilterWhere([
|
||||
'share_id' => $this->share_id,
|
||||
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,
|
||||
]);
|
||||
'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]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user