/** * Consolidates the "from" and "to" fields by filling in data model objects from database. * In student mode, "from" will be the student model and "to" will be the employer model. * In employer mode, it will be wise versa. * @return boolean - true if the models are set successfully * @throws CException -if from and to fields are not valid or type is not a valid type */ private function _setFromAndTo() { if (!$this->hasErrors($this->from) && !$this->hasErrors($this->to)) { $criteria = new CDbCriteria(); $criteria->with = array('user' => array('select' => 'email, first_name, last_name', 'joinType' => 'INNER JOIN')); $criteria->together = true; switch ($this->type) { case self::TYPE_STU: $this->fromObj = Student::model()->findByPk($this->from, $criteria); $this->toObj = Employer::model()->findByPk($this->to, $criteria); $this->interviewObj = InterviewStudentJobTitle::model()->findByAttributes(array('stu_job_id' => $this->stu_job_id, 'employer_id' => $this->to, 'active' => 1)); break; case self::TYPE_EMP: $this->fromObj = Employer::model()->findByPk($this->from, $criteria); $this->toObj = Student::model()->findByPk($this->to, $criteria); //stu_job_id //$this->interviewObj=InterviewStudentJobTitle::model()->findByAttributes(array('stu_job_id'=>$this->stu_job_id,'employer_id'=>$this->from,'active'=>1)); $this->interviewObj = InterviewStudentJobTitle::model()->findByAttributes(array('employer_id' => $this->employer_id, 'stu_job_id' => $this->to)); break; default: throw new CException('Invalid type.'); break; } if ($this->fromObj != null && $this->toObj != null && $this->interviewObj != null) { return true; } else { return false; } } else { throw new CException('Cannot set From and To fields.'); } }
public static function deleteResumes($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 { $interviews = InterviewStudentJobTitle::model()->FindAllByAttributes(array('stu_job_id' => $resumes, 'employer_id' => $empId)); $deletedCount = 0; foreach ($interviews as $interview) { if ($interview->deleteInterview()) { $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; } }
public function actionDeleteSelected() { if (isset($_GET['ajax'])) { if (isset($_POST) && isset($_POST['stu_job_id']) && !empty($_POST['stu_job_id'])) { try { if (InterviewStudentJobTitle::deleteResumes($_POST['stu_job_id'], Yii::app()->user->id)) { $this->renderPartial('/common/_alerts', array('type' => 'success', 'msg' => Yii::t('app', 'msg.success.del_interview_resumes'))); } } catch (Exception $e) { $this->renderPartial('/common/_alerts', array('type' => 'danger', 'msg' => Yii::t('app', 'msg.error.del_interview_resumes'))); } return; } $this->renderPartial('/common/_alerts', array('type' => 'danger', 'msg' => Yii::t('app', 'msg.error.resumes_not_found'))); } }
public function delete() { $tr = Yii::app()->db->beginTransaction(); try { FavoriteStudentJobTitle::model()->deleteAllByAttributes(array('stu_job_id' => $this->stu_job_id)); InterviewStudentJobTitle::model()->deleteAllByAttributes(array('stu_job_id' => $this->stu_job_id)); parent::delete(); $tr->commit(); return true; } catch (Exception $e) { $tr->rollback(); throw $e; } }