public function save($userId, $cvFileName, $pfFileName) { if ($userId !== null) { $transaction = Yii::app()->db->beginTransaction(); try { foreach ($this->jobTitles as $jobTitle) { $studentJobTitle = new StudentJobTitle(); $studentJobTitle->user_id = $userId; $studentJobTitle->job_title_id = $jobTitle; $studentJobTitle->job_type_id = $this->jobType; $studentJobTitle->resume_file = $cvFileName; //if($pfFileName != NULL) //{ $studentJobTitle->portfolio_file = $pfFileName; //} $studentJobTitle->ECWS_id = $this->ecwsCourse; $studentJobTitle->skills = $this->skills; $studentJobTitle->date_created = new CDbExpression('NOW()'); $studentJobTitle->expiry_date = new CDbExpression('DATE(NOW()+INTERVAL 3 MONTH)'); if (!$studentJobTitle->save()) { throw new CException(json_encode($studentJobTitle->errors)); } } $transaction->commit(); return true; } catch (Exception $e) { $transaction->rollback(); throw new CException($e->getMessage()); } } else { throw new CException('User not found!'); } }