public function loadModel($id) { $profile = Profile::findById($id); if (!empty($profile)) { $this->id = $profile->id; $this->status = $profile->status; $this->created_at = $profile->created_at; $this->updated_at = $profile->updated_at; $this->attributes = $profile->attributes; return true; } else { return false; } }
/** * 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; }
public function actionProfileView($id) { $model = Profile::findById($id); return $this->render('profileView', ['model' => $model]); }
/** * Abitur application export to pdf. * * @return mixed * @throws BadRequestHttpException */ public function actionProfileToPdf() { $id = Yii::$app->getUser()->getId(); $user = UserFrontend::findIdentity($id); $profile = Profile::findById($user->id_profile); // get your HTML raw content without any layouts or scripts // $content = $this->renderPartial('abiturApplicationToPdf', ['model'=>$profile]); $content = $this->renderPartial('profileToPdf', ['model' => $profile]); // setup kartik\mpdf\Pdf component $pdf = new Pdf(['mode' => Pdf::MODE_CORE, 'format' => Pdf::FORMAT_A4, 'orientation' => Pdf::ORIENT_PORTRAIT, 'destination' => Pdf::DEST_BROWSER, 'content' => $content, 'mode' => Pdf::MODE_UTF8, 'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 'cssInline' => '.kv-heading-1{font-size:18px}', 'options' => ['title' => 'Заявление'], 'methods' => [], 'marginLeft' => 30, 'marginRight' => 15, 'marginTop' => 12, 'marginBottom' => 12]); // return the pdf output as per the destination setting return $pdf->render(); }