/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Person::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['user_id' => $this->user_id, 'department_id' => $this->department_id]); $query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname])->andFilterWhere(['like', 'photo', $this->photo])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'tel', $this->tel]); return $dataProvider; }
/** * Get Person. * @return Person */ public function getPerson() { return $this->hasOne(Person::className(), ['id' => 'id_person']); }
/** * Save application form. * * @return Profile|null the saved model or null if saving fails */ public function save() { if ($this->validate()) { $person = Person::findById($this->id_person); if (empty($person)) { $person = new Person(); } if (trim($this->parent1_type) != '') { $parent1 = Person::findById($person->id_parent1); if (empty($parent1)) { $parent1 = new Person(); } $parent1->attributes = $this->getMyAttributes('parent1_'); $parent1->save(); $person->id_parent1 = $parent1->id; } else { $parent1 = Person::findById($person->id_parent1); if (!empty($parent1)) { $parent1->delete(); } $person->id_parent1 = null; } if (trim($this->parent2_type) != '') { $parent2 = Person::findById($person->id_parent2); if (empty($parent2)) { $parent2 = new Person(); } $parent2->attributes = $this->getMyAttributes('parent2_'); $parent2->save(); $person->id_parent2 = $parent2->id; } else { $parent2 = Person::findById($person->id_parent2); if (!empty($parent2)) { $parent2->delete(); } $person->id_parent2 = null; } $person->attributes = $this->attributes; if ($person->save()) { $this->id_person = $person->id; $profile = Profile::findById($this->id); if (empty($profile)) { $profile = new Profile(); } $profile->attributes = $this->attributes; $profile->id_person = $person->id; $profile->status = $this->status; if ($profile->validate()) { $profile->save(); $this->id = $profile->id; $specs = Yii::$app->request->post('spec'); $SpecArray = array(); $i = 0; if (!empty($specs)) { foreach ($specs as $id => $spec) { if ($spec != 'none') { $SpecArray[$i]['id_profile'] = $profile->id; $SpecArray[$i]['id_spec'] = $id; $spec == 'form_fulltime' ? $SpecArray[$i]['form_fulltime'] = 1 : ($SpecArray[$i]['form_fulltime'] = 0); $spec == 'form_extramural' ? $SpecArray[$i]['form_extramural'] = 1 : ($SpecArray[$i]['form_extramural'] = 0); $SpecArray[$i]['priority'] = $i + 1; $i++; } } } Yii::$app->db->createCommand()->delete('profile_spec', 'id_profile=:id', [':id' => $profile->id])->execute(); if (!empty($SpecArray)) { Yii::$app->db->createCommand()->batchInsert('profile_spec', ['id_profile', 'id_spec', 'form_fulltime', 'form_extramural', 'priority'], $SpecArray)->execute(); } return true; } else { return false; } } } return false; }
/** * Get Mather. * @return Person|Null */ public function getParent2() { return $this->hasOne(Person::className(), ['id' => 'id_parent2']); }
/** * Finds the Person model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Person the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Person::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getPeople() { return $this->hasMany(Person::className(), ['department_id' => 'id']); }