Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 71 |
| MeetingSearch | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
42.00 | |
0.00% |
0 / 71 |
| attributes | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 8 |
|||
| 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 / 54 |
|||
| <?php | |
| namespace backend\models; | |
| use Yii; | |
| use yii\base\Model; | |
| use yii\data\ActiveDataProvider; | |
| use common\models\Meeting; | |
| /** | |
| * MeetingSearch represents the model behind the search form about `common\models\Meeting`. | |
| */ | |
| class MeetingSearch extends Meeting | |
| { | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function attributes() | |
| { | |
| // add related fields to searchable attributes | |
| return array_merge(parent::attributes(), [ | |
| 'event.name', | |
| 'table.name', | |
| 'hostParticipant.user.fullname', | |
| 'guestParticipant.user.fullname', | |
| ]); | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function rules() | |
| { | |
| return [ | |
| [['is_confirmed_host', 'is_confirmed_guest'], 'boolean'], | |
| [['event.name', 'table.name', 'hostParticipant.user.fullname', 'guestParticipant.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 = Meeting::find() | |
| ->joinWith('eventSpan.event', false) | |
| ->joinWith('table', false) | |
| ->joinWith(['hostParticipant' => function($q){ $q->from(['hostParticipant' => '{{%participant}}']); }], false) | |
| ->joinWith(['guestParticipant' => function($q){ $q->from(['guestParticipant' => '{{%participant}}']); }], false) | |
| ->innerJoin(['hostUser' => '{{%user}}'], 'hostUser.id = hostParticipant.user_id') | |
| ->innerJoin(['guestUser' => '{{%user}}'], 'guestUser.id = guestParticipant.user_id'); | |
| $dataProvider = new ActiveDataProvider([ | |
| 'query' => $query, | |
| ]); | |
| $dataProvider->sort->attributes['time'] = [ | |
| 'asc' => ['{{%meeting}}.event_span_time_on' => SORT_ASC], | |
| 'desc' => ['{{%meeting}}.event_span_time_on' => SORT_DESC], | |
| ]; | |
| $dataProvider->sort->attributes['event.name'] = [ | |
| 'asc' => ['{{%event}}.name' => SORT_ASC], | |
| 'desc' => ['{{%event}}.name' => SORT_DESC], | |
| ]; | |
| $dataProvider->sort->attributes['eventSpan.date'] = [ | |
| 'asc' => ['{{%event_span}}.[[date]]' => SORT_ASC], | |
| 'desc' => ['{{%event_span}}.[[date]]' => SORT_DESC], | |
| ]; | |
| $dataProvider->sort->attributes['table.name'] = [ | |
| 'asc' => ['{{%table}}.name' => SORT_ASC], | |
| 'desc' => ['{{%table}}.name' => SORT_DESC], | |
| ]; | |
| $dataProvider->sort->attributes['hostParticipant.user.fullname'] = [ | |
| 'asc' => ['hostUser.lastname' => SORT_ASC, 'hostUser.firstname' => SORT_ASC], | |
| 'desc' => ['hostUser.lastname' => SORT_DESC, 'hostUser.firstname' => SORT_DESC], | |
| ]; | |
| $dataProvider->sort->attributes['guestParticipant.user.fullname'] = [ | |
| 'asc' => ['guestUser.lastname' => SORT_ASC, 'guestUser.firstname' => SORT_ASC], | |
| 'desc' => ['guestUser.lastname' => SORT_DESC, 'guestUser.firstname' => SORT_DESC], | |
| ]; | |
| if (!($this->load($params) && $this->validate())) { | |
| return $dataProvider; | |
| } | |
| $query->andFilterWhere([ | |
| 'is_confirmed_host' => $this->is_confirmed_host, | |
| 'is_confirmed_guest' => $this->is_confirmed_guest, | |
| ]); | |
| $query->andFilterWhere(['like', 'host_confirmation_token', $this->host_confirmation_token]) | |
| ->andFilterWhere(['like', 'guest_confirmation_token', $this->guest_confirmation_token]); | |
| $query->andFilterWhere(['like', '{{%event}}.name', $this->getAttribute('event.name')]) | |
| ->andFilterWhere(['like', '{{%table}}.name', $this->getAttribute('table.name')]) | |
| ->andFilterWhere(['or', | |
| ['like', 'hostUser.lastname', $this->getAttribute('hostParticipant.user.fullname')], | |
| ['like', 'hostUser.firstname', $this->getAttribute('hostParticipant.user.fullname')], | |
| ]) | |
| ->andFilterWhere(['or', | |
| ['like', 'guestUser.lastname', $this->getAttribute('guestParticipant.user.fullname')], | |
| ['like', 'guestUser.firstname', $this->getAttribute('guestParticipant.user.fullname')], | |
| ]); | |
| return $dataProvider; | |
| } | |
| } |