public function actionFav($stu_job_id)
 {
     if (isset($stu_job_id)) {
         if (StudentJobTitle::model()->exists('stu_job_id=:stu_job_id', array(':stu_job_id' => $stu_job_id))) {
             $favJobTitle = new FavoriteStudentJobTitle();
             $favJobTitle->stu_job_id = $stu_job_id;
             $favJobTitle->employer_id = Yii::app()->user->id;
             try {
                 if ($favJobTitle->save()) {
                     $this->renderPartial('//common/_alerts', array('type' => 'success', 'msg' => Yii::t('app', 'msg.success.fav_resume')));
                 }
             } catch (CDbException $e) {
                 $this->renderPartial('//common/_alerts', array('type' => 'danger', 'msg' => Yii::t('app', 'msg.error.fav_resume')));
             }
         } else {
             $this->renderPartial('//common/_alerts', array('type' => 'danger', 'msg' => Yii::t('app', 'msg.error.resume_not_found')));
         }
     }
 }
 public function actionDeleteJob($stuJobID)
 {
     if ($stuJobID !== null) {
         $jobTitleModel = StudentJobTitle::model()->with('jobTitle')->findByAttributes(array('stu_job_id' => $stuJobID, 'user_id' => Yii::app()->user->id));
         if ($jobTitleModel != null) {
             try {
                 if ($jobTitleModel->delete()) {
                     Yii::app()->user->setFlash('success', sprintf(Yii::t('app', 'msg.success.delete_job_title'), $jobTitleModel->jobTitle->job_title_name));
                     $this->redirect($this->createUrl('viewCat', array('jobCat' => $jobTitleModel->jobTitle->job_cat_id)), true);
                 } else {
                     throw new CHttpException(404, "Student Job Title {$stuJobID} cannot be deleted.");
                 }
             } catch (Exception $e) {
                 throw new CHttpException(404, "Student Job Title {$stuJobID} cannot be deleted.");
             }
         } else {
             throw new CHttpException(404, "Student Job Title {$stuJobID} is not found.");
         }
     } else {
         throw new CHttpException(404, "Student Job Title is not found.");
     }
 }
 public function __construct($userId = null, $scenario = '')
 {
     if ($userId !== null) {
         $this->_countUserJobs = StudentJobTitle::model()->countByAttributes(array('user_id' => $userId, 'is_hired' => 0));
     }
 }
 public static function unhireResumes($resumes, $empId)
 {
     if (!isset($resumes) || !is_array($resumes) || !isset($empId)) {
         throw new CException('Resumes and Employer Id are required');
     }
     $resCount = count($resumes);
     if ($resCount === 0) {
         return true;
     }
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $hiredResumes = StudentJobTitle::model()->FindAllByAttributes(array('stu_job_id' => $resumes, 'employer_id' => $empId, 'is_current_hired' => '1', 'is_hired' => '1'));
         $deletedCount = 0;
         foreach ($hiredResumes as $hired) {
             if ($hired->unhire($empId)) {
                 $deletedCount++;
             }
         }
         if ($deletedCount !== $resCount) {
             throw new CException("Only {$deletedCount} records deleted, while deleting {$resCount} records.");
         }
         $transaction->commit();
         return true;
     } catch (Exception $e) {
         $transaction->rollback();
         throw $e;
     }
 }