public function actionPerformance() { if (Yii::app()->user->agreeToTerms == 0) { $this->redirect(Yii::app()->createUrl('company/terms')); } // renders the view file 'protected/views/site/index.php' // using the default layout 'protected/views/layouts/main.php' if (!isset(Yii::app()->user->userProfileID)) { $this->redirect('/user/login'); } $candidateID = Yii::app()->request->getParam('id'); $candidateModel = new Candidate(); $performanceModel = new Performance(); $companyModel = new Company(); $criteria = new CDbCriteria(); $criteria2 = new CDbCriteria(); $criteria->with = array('performances'); $criteria2->with = array('companyPerformances'); $companyPerformance = $companyModel->findByPk(Yii::app()->user->companyID, $criteria2); $currentYear = date('Y'); $criteria->condition = 'performances.CandidateID = :CandidateID and performances.PerformanceYear = :PerformanceYear'; $criteria->params = array(':CandidateID' => $candidateID, ':PerformanceYear' => $currentYear); // if no new record insert new record $candidatePerformance = $candidateModel->findByAttributes(array(), $criteria); if (empty($candidatePerformance) && !isset($_POST['RatePerformance'])) { $performanceModel->CandidateID = $candidateID; $performanceModel->PerformanceYear = $currentYear; $performanceModel->save(); $candidatePerformance = $candidateModel->findByAttributes(array(), $criteria); } if (isset($_POST['RatePerformance'])) { //$performanceModel = new Performance(); $criteria = new CDbCriteria(); $criteria->condition = 'CandidateID = :CandidateID and PerformanceYear = :PerformanceYear'; $criteria->params = array(':CandidateID' => $_POST['RatePerformance']['CandidateID'], ':PerformanceYear' => $currentYear); $performanceRating = $performanceModel->findByAttributes(array(), $criteria); $performanceRating->attributes = $_POST['RatePerformance']; // if ($performanceRating->PerformanceYear==DATE('Y')) // { $performanceRating->update(array('Contribution', 'Conduct', 'Effort', 'Notes')); // } // else // { // $performanceRating->insert(array('Contribution', 'Conduct', 'Effort', 'Notes')); // } $this->redirect('rating/' . $_POST['RatePerformance']['CandidateID']); } // Pull Last Years Performance $sql = "select * from Performance where CandidateID=" . $candidateID . " and PerformanceYear=" . date('Y') . "-1"; $row = Yii::app()->db->createCommand($sql)->queryRow(); $last = array(); if ($row) { $last = array("lastContribution" => $row['Contribution'], "lastConduct" => $row['Conduct'], "lastEffort" => $row['Effort']); } else { $last = array("lastContribution" => "", "lastConduct" => "", "lastEffort" => ""); } $this->render('performance', array('candidatePerformance' => $candidatePerformance, 'companyPerformance' => $companyPerformance, 'last' => $last)); }