/** * Creates a new Preferences model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Preferences(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->pref_ID]); } else { return $this->render('create', ['model' => $model]); } }
public function actionIndex() { //Get the preferences model $preferences = new Preferences(); // Make an user model from current user $person = \Yii::$app->user->identity; if (isset(\Yii::$app->request->post()['Preferences'])) { $preferences->load(\Yii::$app->request->post()); $preferences->saveForUser($person); } // Fill preferences with user preferences $preferences->fillForUser($person); // Show data as form return $this->render("index", ["model" => $person, "preferences" => $preferences]); }
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); }