Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
75.00% |
3 / 4 |
CRAP | |
97.14% |
34 / 35 |
| OrganizationSearch | |
0.00% |
0 / 1 |
|
75.00% |
3 / 4 |
5 | |
97.14% |
34 / 35 |
| rules | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| scenarios | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| attributeLabels | |
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
|||
| search | |
0.00% |
0 / 1 |
2 | |
96.43% |
27 / 28 |
|||
| <?php | |
| namespace frontend\models; | |
| use Yii; | |
| use yii\base\Model; | |
| use yii\data\ActiveDataProvider; | |
| use common\models\Organization; | |
| use common\models\OrganizationProfile; | |
| use common\models\OrganizationType; | |
| use common\models\Supervisor; | |
| /** | |
| * OrganizationSearch represents the model behind the search form about `common\models\Organization`. | |
| */ | |
| class OrganizationSearch extends Organization | |
| { | |
| public $organization_profile; | |
| public $organization_type; | |
| public $supervisor; | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function rules() | |
| { | |
| return [ | |
| [['name', 'email', 'address', 'postal_code', 'city', 'country', 'phone', 'fax', 'website', 'founded', 'organization_size', 'description', 'offer', 'interest'], 'safe'], | |
| [['organization_profile', 'organization_type', 'supervisor'], 'integer'], | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function scenarios() | |
| { | |
| // bypass scenarios() implementation in the parent class | |
| return Model::scenarios(); | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function attributeLabels() | |
| { | |
| $labels = parent::attributeLabels(); | |
| $labels['organization_profile'] = Yii::t('app', 'Organization profile'); | |
| $labels['organization_type'] = Yii::t('app', 'Organization type'); | |
| $labels['supervisor'] = Yii::t('app', 'Supervisor office'); | |
| // bypass attributeLabels() implementation in the parent class | |
| return $labels; | |
| } | |
| /** | |
| * Creates data provider instance with search query applied | |
| * | |
| * @param array $params | |
| * | |
| * @return ActiveDataProvider | |
| */ | |
| public function search($params) | |
| { | |
| $query = Organization::find() | |
| ->active(); | |
| $dataProvider = new ActiveDataProvider([ | |
| 'query' => $query, | |
| ]); | |
| $dataProvider->setSort([ | |
| 'defaultOrder' => [ | |
| 'name' => SORT_ASC, | |
| ], | |
| ]); | |
| $this->load($params); | |
| if (!$this->validate()) { | |
| // uncomment the following line if you do not want to any records when validation fails | |
| // $query->where('0=1'); | |
| return $dataProvider; | |
| } | |
| $query->andFilterWhere([ | |
| 'organization_profile_id' => $this->organization_profile, | |
| 'organization_type_id' => $this->organization_type, | |
| 'supervisor_id' => $this->supervisor, | |
| ]); | |
| $query->andFilterWhere(['like', 'name', $this->name]) | |
| ->andFilterWhere(['like', 'email', $this->email]) | |
| ->andFilterWhere(['like', 'address', $this->address]) | |
| ->andFilterWhere(['like', 'postal_code', $this->postal_code]) | |
| ->andFilterWhere(['like', 'city', $this->city]) | |
| ->andFilterWhere(['like', 'country', $this->country]) | |
| ->andFilterWhere(['like', 'phone', $this->phone]) | |
| ->andFilterWhere(['like', 'fax', $this->fax]) | |
| ->andFilterWhere(['like', 'website', $this->website]) | |
| ->andFilterWhere(['like', 'founded', $this->founded]) | |
| ->andFilterWhere(['like', 'organization_size', $this->organization_size]) | |
| ->andFilterWhere(['like', 'description', $this->description]) | |
| ->andFilterWhere(['like', 'offer', $this->offer]) | |
| ->andFilterWhere(['like', 'interest', $this->interest]); | |
| return $dataProvider; | |
| } | |
| } |