예제 #1
0
 /**
  * Updates an existing UserJob model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $_id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $modelUser = User::findOne($id);
     $modelUserJob = UserJob::findOne($id);
     if (!isset($modelUser, $modelUserJob)) {
         throw new NotFoundHttpException("The user was not found.");
     }
     if ($modelUser->load(Yii::$app->request->post()) && $modelUserJob->load(Yii::$app->request->post())) {
         $modelUserValidate = $modelUser->validate();
         $modelUserJobValidate = $modelUserJob->validate();
         if ($modelUserValidate && $modelUserJobValidate) {
             $modelUserJob->email = $modelUser->email;
             if ($modelUser->save(false) && $modelUserJob->save(false)) {
                 if ($modelUserJob->role == 'seeker') {
                     UserJobSeekerResume::updateAll(['nationality' => $modelUserJob->seeker_nationality, 'salary' => $modelUserJob->seeker_salary], ['_id' => $modelUserJob->_id]);
                 }
                 if (Yii::$app->request->post('save_type') !== 'apply') {
                     return $this->redirect(['view', 'id' => (string) $modelUser->_id]);
                 }
             }
         }
     }
     Yii::$app->view->title = Yii::t('yii', 'Update');
     Yii::$app->view->params['breadcrumbs'][] = ['label' => Yii::t($this->module->id, 'Manage Members'), 'url' => ['index']];
     Yii::$app->view->params['breadcrumbs'][] = Yii::$app->view->title;
     return $this->render('form', ['modelUser' => $modelUser, 'modelUserJob' => $modelUserJob]);
 }
예제 #2
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]);
 }
예제 #3
0
 public function actionEditProfile()
 {
     $jobModel = UserJob::findOne(['_id' => Yii::$app->user->identity->_id]);
     $jobModel->scenario = "edit_recruiter";
     $model = User::findOne(['_id' => Yii::$app->user->identity->_id]);
     $model->scenario = "edit_recruiter";
     if ($model->load(Yii::$app->request->post()) && $jobModel->load(Yii::$app->request->post())) {
         $modelValidate = $model->validate();
         $jobModelValidate = $jobModel->validate();
         if ($modelValidate && $jobModelValidate) {
             if ($model->save(false)) {
                 if ($jobModel->save(false)) {
                     Yii::$app->getSession()->setFlash('flash', ['type' => 'success', 'title' => Yii::t('account', 'Message'), 'message' => Yii::t('account', 'Updated succesfully.'), 'duration' => 10000]);
                     return $this->redirect(['view-profile']);
                 }
             }
         }
     }
     Yii::$app->view->title = Yii::t($this->module->id, 'Edit Profile');
     Yii::$app->view->params['breadcrumbs'][] = Yii::$app->view->title;
     return $this->render('edit-profile', ['model' => $model, 'jobModel' => $jobModel]);
 }