Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 37 |
| SupervisorSearch | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
42.00 | |
0.00% |
0 / 37 |
| attributes | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 5 |
|||
| rules | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 6 |
|||
| scenarios | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| search | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 23 |
|||
| <?php | |
| namespace backend\models; | |
| use Yii; | |
| use yii\base\Model; | |
| use yii\data\ActiveDataProvider; | |
| use common\models\Supervisor; | |
| /** | |
| * SupervisorSearch represents the model behind the search form about `common\models\Supervisor`. | |
| */ | |
| class SupervisorSearch extends Supervisor | |
| { | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function attributes() | |
| { | |
| // add related fields to searchable attributes | |
| return array_merge(parent::attributes(), [ | |
| 'user.fullname', | |
| ]); | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function rules() | |
| { | |
| return [ | |
| [['office_name'], 'safe'], | |
| [['user.fullname'], 'safe'], | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function scenarios() | |
| { | |
| // bypass scenarios() implementation in the parent class | |
| return Model::scenarios(); | |
| } | |
| /** | |
| * Creates data provider instance with search query applied | |
| * | |
| * @param array $params | |
| * | |
| * @return ActiveDataProvider | |
| */ | |
| public function search($params) | |
| { | |
| $query = Supervisor::find() | |
| ->joinWith('user', false); | |
| $dataProvider = new ActiveDataProvider([ | |
| 'query' => $query, | |
| ]); | |
| $dataProvider->sort->attributes['user.fullname'] = [ | |
| 'asc' => ['{{%user}}.lastname' => SORT_ASC, '{{%user}}.firstname' => SORT_ASC], | |
| 'desc' => ['{{%user}}.lastname' => SORT_DESC, '{{%user}}.firstname' => SORT_DESC], | |
| ]; | |
| $dataProvider->sort->defaultOrder = [ | |
| 'office_name' => SORT_ASC, | |
| ]; | |
| if (!($this->load($params) && $this->validate())) { | |
| return $dataProvider; | |
| } | |
| $query->andFilterWhere(['like', 'office_name', $this->office_name]); | |
| $query->andFilterWhere(['or', | |
| ['like', '{{%user}}.lastname', $this->getAttribute('user.fullname')], | |
| ['like', '{{%user}}.firstname', $this->getAttribute('user.fullname')], | |
| ]); | |
| return $dataProvider; | |
| } | |
| } |