Пример #1
0
 public function actionAddcandidate()
 {
     if (!isset(Yii::app()->user->userProfileID)) {
         $this->redirect('/user/login');
     }
     // renders the view file 'protected/views/site/index.php'
     // using the default layout 'protected/views/layouts/main.php'
     $candidateModel = new Candidate();
     $performanceModel = new Performance();
     $ratingModel = new Rating();
     $planningModel = new Planning();
     if (isset($_POST['Candidate'])) {
         $candidateModel->attributes = $_POST['Candidate'];
         $candidateModel->IsActive = 1;
         //$candidateModel->UserProfileID = Yii::app()->user->userProfileID;
         $candidateModel->CompanyID = Yii::app()->user->companyID;
         if ($candidateModel->validate()) {
             if ($candidateModel->save()) {
                 $currentYear = date('Y');
                 // insert new record
                 $performanceModel->CandidateID = $candidateModel->CandidateID;
                 $performanceModel->PerformanceYear = $currentYear;
                 $ratingModel->CandidateID = $candidateModel->CandidateID;
                 $ratingModel->RatingYear = $currentYear;
                 $planningModel->CandidateID = $candidateModel->CandidateID;
                 $planningModel->PlanningYear = $currentYear;
                 $planningModel->CurrentPositionLevel = $_POST['Candidate']['CompanyPositionID'];
                 if ($_POST['Candidate']['CompanyPositionID'] == 5) {
                     $planningModel->NextStepPositionLevel = 5;
                     $planningModel->LongTermPositionLevel = 5;
                 } else {
                     $planningModel->NextStepPositionLevel = $_POST['Candidate']['CompanyPositionID'];
                     $planningModel->LongTermPositionLevel = $_POST['Candidate']['CompanyPositionID'];
                 }
                 $performanceModel->save();
                 $ratingModel->save();
                 $planningModel->save();
                 $this->redirect(Yii::app()->createUrl('company/candidates'));
             }
         }
     }
     $criteria3 = new CDbCriteria();
     $criteria3->condition = 'companyID = :companyID';
     $criteria3->params = array(':companyID' => Yii::app()->user->companyID);
     $criteria3->order = 'Email';
     $userManagers = UserProfile::model()->findAllByAttributes(array(), $criteria3);
     $managersArray = array();
     foreach ($userManagers as $UserManager) {
         $managersArray[$UserManager->UserProfileID] = $UserManager->Email;
     }
     $managerArray = $managersArray;
     $companyPositions = Helper::getCompanyPositions(Yii::app()->user->companyID);
     $this->render('candidate-form', array('candidateModel' => $candidateModel, 'planningModel' => $planningModel, 'companyPositionSelect' => $companyPositions, 'managerArray' => $managerArray));
 }