new-support.webeffector.ru/common/components/user/models/search/UserSearch.php

43 lines
1005 B
PHP
Raw Permalink Normal View History

2024-07-04 06:42:20 +03:00
<?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;
}
}