|
- <?php
-
-
-
- namespace domain\User\UserGroup;
-
- use common\helpers\GlobalParam;
- use yii\data\ActiveDataProvider;
-
- class UserGroupSearch extends UserGroup
- {
- public function rules()
- {
- return [
- [['name'], 'string'],
- [['name'], 'string', 'max' => 255],
- ['id_producer', 'integer'],
- ];
- }
-
- public function search($params)
- {
- $userGroupRepository = UserGroupRepository::getInstance();
- $optionsSearch = $userGroupRepository->getDefaultOptionsSearch();
-
- $query = UserGroup::find()
- ->with($optionsSearch['with'])
- ->innerJoinWith($optionsSearch['join_with'], true)
- ->where(['user_group.id_producer' => GlobalParam::getCurrentProducerId()]);
-
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- 'sort' => ['attributes' => ['name']],
- 'pagination' => [
- 'pageSize' => 20,
- ],
- ]);
-
- $this->load($params);
- if (!$this->validate()) {
- return $dataProvider;
- }
-
- $query->andFilterWhere(['like', 'user_group.name', $this->name]);
-
- return $dataProvider;
- }
-
- }
|