Exemple #1
0
 public function actionResume()
 {
     // Xu ly avatar
     $modelUser = User::findOne(Yii::$app->user->id);
     if ($modelUser == null) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $modelUserJob = UserJob::findOne(Yii::$app->user->id);
     if ($modelUserJob == null) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $model = UserJobSeekerResume::findOne(Yii::$app->user->id);
     if ($model == null) {
         $model = new UserJobSeekerResume();
         $model->_id = Yii::$app->user->id;
         $model->nationality = $modelUserJob->seeker_nationality;
         $model->salary = $modelUserJob->seeker_salary;
         $model->candidate_id = UserJob::getNextSequence('seeker');
     }
     $employments = UserJobSeekerEmployment::find()->where(['seeker_id' => Yii::$app->user->id])->indexBy('_id')->all();
     if ($employments == null) {
         $employments = new UserJobSeekerEmployment();
         $employments->seeker_id = $model->_id;
     }
     if ($model->load(Yii::$app->request->post()) && $modelUser->load(Yii::$app->request->post())) {
         // Sync data
         $model->phone_number = $modelUser->phone;
         // UserJobSeekerResume::search() có dùng đến phone_number nên cần đồng bộ chỗ này
         $modelValidate = $model->validate();
         $modelUserValidate = $modelUser->validate();
         if (!is_array($employments)) {
             $employments->load(Yii::$app->request->post());
             $employmentsValidate = $employments->validate();
         } else {
             $employmentsValidate = Model::loadMultiple($employments, Yii::$app->request->post()) && Model::validateMultiple($employments);
         }
         if ($employmentsValidate && $modelValidate && $modelUserValidate && $model->save(false) && $modelUser->save(false)) {
             $modelUserJob->seeker_nationality = $model->nationality;
             $modelUserJob->seeker_salary = $model->salary;
             $modelUserJob->save();
             if (!is_array($employments)) {
                 $employments->save();
                 //update latest company and position for seeker resume document
                 $model->latest_company = $employments->company_name;
                 $model->latest_position = $employments->position;
                 $model->save(false);
             } else {
                 if (isset($employmentsValidate) && $employmentsValidate == true) {
                     $i = 1;
                     $max = sizeof($employments);
                     foreach ($employments as $employment) {
                         $employment->save(false);
                         if ($i == $max) {
                             // is latest employment iformation
                             //update latest company and position for seeker resume document
                             $model->latest_company = $employment->company_name;
                             $model->latest_position = $employment->position;
                             $model->save(false);
                         }
                         $i++;
                     }
                 }
             }
             Yii::$app->getSession()->setFlash('flash', ['type' => 'success', 'title' => Yii::t('common', 'Message'), 'message' => Yii::t('common', 'Your information has been saved successfully.'), 'duration' => 10000]);
             return $this->refresh();
         }
     }
     Yii::$app->view->title = Yii::t($this->module->id, 'Resume');
     Yii::$app->view->params['breadcrumbs'][] = Yii::$app->view->title;
     return $this->render('resume', ['model' => $model, 'modelUser' => $modelUser, 'employments' => $employments]);
 }