コード例 #1
0
 public function createnewstep3()
 {
     $model = new Vacancy();
     $preferences = new Preferences();
     $data = Yii::$app->request->post();
     $model->load($data);
     $preferences->load($data);
     $transaction = \Yii::$app->db->beginTransaction();
     try {
         //TODO check for errors and cancel transaction
         $model->save();
         $model->savePreferences($preferences);
         $connection = \Yii::$app->db;
         // TODO Place this in preferences logic
         $connection->createCommand("INSERT INTO person_vacancy_role (person_id, vacancy_id, role_id) " . "VALUES (:person_id, :vacancy_id, :role_id)")->bindValues([":person_id" => \YII::$app->getUser()->getIdentity()->getId(), ":vacancy_id" => $model->getPrimaryKey(), ":role_id" => VacancyRoleHelper::OWNER])->execute();
         // Vacanty - course_id
         $course_id = $this->getSession()['create-new-vacancy-course-id'];
         if (isset($course_id) && $course_id != "none") {
             $connection->createCommand("INSERT INTO course_vacancy (course_id, vacancy_id) VALUES (:course_id, :vacancy_id)")->bindValues([":course_id" => $course_id, ":vacancy_id" => $model->getPrimaryKey()])->execute();
         }
         $transaction->commit();
     } catch (\Exception $e) {
         $transaction->rollBack();
         throw $e;
     }
     return $this->actionView($model->id);
 }