Ejemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new CvList();
     $this->performAjaxValidation($model);
     if (isset($_POST['CvList'])) {
         $model->attributes = $_POST['CvList'];
         $result = array();
         $t = false;
         if (!Yii::app()->db->currentTransaction) {
             $t = Yii::app()->db->beginTransaction();
         }
         if ($model->save()) {
             if (!empty($_POST['CvList']['residenciesIds'])) {
                 foreach ($_POST['CvList']['residenciesIds'] as $r) {
                     $residence = new CvToResidence();
                     $residence->cv_id = $model->id;
                     $residence->city_id = $r;
                     if (!$residence->save()) {
                         $result[] = false;
                     }
                 }
             }
             if (!empty($_POST['CvList']['driverLicensesIds'])) {
                 foreach ($_POST['CvList']['driverLicensesIds'] as $dl) {
                     $license = new CvToDriverLicense();
                     $license->cv_id = $model->id;
                     $license->license_id = $dl;
                     if (!$license->save()) {
                         $result[] = false;
                     }
                 }
             }
             if (!empty($_POST['CvList']['jobLocationsIds'])) {
                 foreach ($_POST['CvList']['jobLocationsIds'] as $jl) {
                     $jobLocation = new CvToJobLocation();
                     $jobLocation->cv_id = $model->id;
                     $jobLocation->city_id = $jl;
                     if (!$jobLocation->save()) {
                         $result[] = false;
                     }
                 }
             }
             if (!empty($_POST['CvList']['assistanceIds'])) {
                 foreach ($_POST['CvList']['assistanceIds'] as $ai) {
                     $assistance = new CvToAssistance();
                     $assistance->cv_id = $model->id;
                     $assistance->assistance_type_id = $ai;
                     if (!$assistance->save()) {
                         $result[] = false;
                     }
                 }
             }
         } else {
             $result[] = false;
         }
         if ($t && !in_array(false, $result)) {
             $t->commit();
             $log = new Log();
             $log->action = 'add_user_' . $model->id;
             $log->save();
             Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, 'Анкета була додана!');
             $this->redirect(array('index'));
         } else {
             $t->rollback();
         }
     }
     $this->render('create', array('model' => $model));
 }
Ejemplo n.º 2
0
 public function actionApplicants()
 {
     $model = new CvList();
     $model->scenario = 'public';
     $this->performAjaxValidation($model);
     if (isset($_POST['CvList'])) {
         $model->attributes = $_POST['CvList'];
         $result = array();
         $t = false;
         if (!Yii::app()->db->currentTransaction) {
             $t = Yii::app()->db->beginTransaction();
         }
         if ($model->save()) {
             if (!empty($_POST['CvList']['residenciesIds'])) {
                 foreach ($_POST['CvList']['residenciesIds'] as $r) {
                     $residence = new CvToResidence();
                     $residence->cv_id = $model->id;
                     $residence->city_id = $r;
                     if (!$residence->save()) {
                         $result[] = false;
                     }
                 }
             }
             if (!empty($_POST['CvList']['positionsIds'])) {
                 foreach ($_POST['CvList']['positionsIds'] as $positionId) {
                     $cvToPosition = new CvToPosition();
                     $cvToPosition->cv_id = $model->id;
                     $cvToPosition->position_id = $positionId;
                     if (!$cvToPosition->save()) {
                         $result[] = false;
                     }
                 }
             }
             if (!empty($_POST['CvList']['desiredPositionsIds'])) {
                 foreach ($_POST['CvList']['desiredPositionsIds'] as $desiredPositionId) {
                     $cvToPositionDesired = new CvToPositionDesired();
                     $cvToPositionDesired->cv_id = $model->id;
                     $cvToPositionDesired->position_id = $desiredPositionId;
                     if (!$cvToPositionDesired->save()) {
                         $result[] = false;
                     }
                 }
             }
             if (!empty($_POST['CvList']['driverLicensesIds'])) {
                 foreach ($_POST['CvList']['driverLicensesIds'] as $dl) {
                     $license = new CvToDriverLicense();
                     $license->cv_id = $model->id;
                     $license->license_id = $dl;
                     if (!$license->save()) {
                         $result[] = false;
                     }
                 }
             }
             if (!empty($_POST['CvList']['jobLocationsIds'])) {
                 foreach ($_POST['CvList']['jobLocationsIds'] as $jl) {
                     $jobLocation = new CvToJobLocation();
                     $jobLocation->cv_id = $model->id;
                     $jobLocation->city_id = $jl;
                     if (!$jobLocation->save()) {
                         $result[] = false;
                     }
                 }
             }
             if (!empty($_POST['CvList']['assistanceIds'])) {
                 foreach ($_POST['CvList']['assistanceIds'] as $ai) {
                     $assistance = new CvToAssistance();
                     $assistance->cv_id = $model->id;
                     $assistance->assistance_type_id = $ai;
                     if (!$assistance->save()) {
                         $result[] = false;
                     }
                 }
             }
             if (!empty($_POST['CvList']['applicantTypeIds'])) {
                 foreach ($_POST['CvList']['applicantTypeIds'] as $ati) {
                     $applicantType = new CvToApplicantType();
                     $applicantType->cv_id = $model->id;
                     $applicantType->applicant_type_id = $ati;
                     if (!($applicantType->validate(null, false) && $applicantType->save(false))) {
                         $model->addError('applicantTypeIds', $applicantType->getError('cv_id'));
                         $result[] = false;
                     }
                 }
             }
         } else {
             $result[] = false;
         }
         if ($t && !in_array(false, $result)) {
             $t->commit();
             $this->redirect(array('applicants', 'success' => true));
         } else {
             $t->rollback();
         }
     }
     $this->render('applicants', array('model' => $model));
 }