43 lines
1005 B
PHP
43 lines
1005 B
PHP
|
<?php
|
||
|
|
||
|
namespace common\components\user\models\search;
|
||
|
|
||
|
use yii\data\ActiveDataProvider;
|
||
|
use common\components\user\models\User;
|
||
|
|
||
|
class UserSearch extends User
|
||
|
{
|
||
|
|
||
|
public function scenarios(): array
|
||
|
{
|
||
|
return User::scenarios();
|
||
|
}
|
||
|
|
||
|
public function search($params): ?ActiveDataProvider
|
||
|
{
|
||
|
$query = User::find()
|
||
|
->select([User::tableName() . '.*', 'auth_assignment.item_name as role'])
|
||
|
->leftJoin('auth_assignment', 'auth_assignment.user_id = ' . User::tableName() . '.id');
|
||
|
|
||
|
$dataProvider = new ActiveDataProvider([
|
||
|
'query' => $query,
|
||
|
'sort' => [
|
||
|
'defaultOrder' => ['id' => SORT_ASC],
|
||
|
],
|
||
|
]);
|
||
|
|
||
|
$this->load($params);
|
||
|
|
||
|
if (!$this->validate()) {
|
||
|
return $dataProvider;
|
||
|
}
|
||
|
|
||
|
$query->andFilterWhere([
|
||
|
'status' => $this->status,
|
||
|
'auth_assignment.item_name' => $this->role,
|
||
|
]);
|
||
|
|
||
|
return $dataProvider;
|
||
|
}
|
||
|
}
|