/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new JukeboxAnswers(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['JukeboxAnswers'])) { $model->attributes = $_POST['JukeboxAnswers']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * This method gets userID , Question ID and arrary of data and creates the model * Returns Model if sucessfully created. * Returns the error Validated Model if validation fails * * Data arrary should have the following Hash keys * 1.answer * 2.reference URL * 3.E-mail answer * 4.correct * 5.status * * @param arrary $data,string $userId * @return model ||model with error */ public static function addJukeboxAnswer($userId, $questionId, $data) { $jukeboxAnswers = new JukeboxAnswers(); $jukeboxAnswers->user_id = $userId; $jukeboxAnswers->jukebox_question_id = $questionId; $jukeboxAnswers->answer = $data->answer; $jukeboxAnswers->reference_url = $data->reference_url; $jukeboxAnswers->status = 0; if ($jukeboxAnswers->save()) { return $jukeboxAnswers; } else { return false; } }