/** * Finds the QuestionAnswer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return QuestionAnswer the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = QuestionAnswer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // $questionAnswer = QuestionAnswer::find($id); if (!$questionAnswer) { return $this->respondNotFound('Item Not Found'); } return $this->respond(['data' => [$this->questionAnswerTransformer->transform($questionAnswer)]]); }
/** * Display the specified resource. * * @param $answer array post data * @param $user_id user id * @param $session_id session of material * @param $material_id * @internal param int $id * @return Response */ protected function createMaterialAnswer(array $answer, $user_id, $session_id, $material_id) { $insertedAnswer = QuestionAnswer::create($answer); $this->dispatch(new QuestionHasBeenAnswered($insertedAnswer, $user_id, $session_id)); $answer_id = $insertedAnswer->id; if (!$answer_id) { return false; } return $this->updateMaterialData($material_id, $answer_id); }
public function run() { QuestionAnswer::truncate(); $faker = Faker\Factory::create(); $authorIds = User::lists('id'); $questionIds = Question::lists('id'); for ($i = 0; $i < 10; $i++) { QuestionAnswer::create(['answer' => $faker->sentence, 'status' => $faker->randomElement(array(0, 1)), 'question_id' => $faker->randomElement($questionIds), 'author_id' => $faker->randomElement($authorIds)]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = QuestionAnswer::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id_av' => $this->id_av, 'id_q' => $this->id_q, 'npp' => $this->npp, 'isHidden' => $this->isHidden, 'hasText' => $this->hasText, 'textMaxLength' => $this->textMaxLength, 'isNoRandomized' => $this->isNoRandomized]); $query->andFilterWhere(['like', 'separator', $this->separator])->andFilterWhere(['like', 'name_ua', $this->name_ua])->andFilterWhere(['like', 'name_ru', $this->name_ru]); return $dataProvider; }
</div> </div> <div class="row"> <div class="col-md-3"> <?php echo $form->field($model, 'isHidden')->dropDownList(QuestionAnswer::getIsHiddenOptions()); ?> </div> <div class="col-md-3"> <?php echo $form->field($model, 'isNoRandomized')->dropDownList(QuestionAnswer::getIsNoRandomizedOptions()); ?> </div> <div class="col-md-3"> <?php echo $form->field($model, 'hasText')->dropDownList(QuestionAnswer::getHasTextOptions()); ?> </div> <div class="col-md-3"> <?php echo $form->field($model, 'textMaxLength')->textInput(); ?> </div> </div> <div class="row"> <div class="col-md-12"> <?php echo $form->field($model, 'separator')->textInput(['maxlength' => true]); ?> </div> </div>
public function selectAnswer($answer_id) { return $this->hasMany(QuestionAnswer::className(), ['question_id' => 'id'])->where('answer_id = :id', ['id' => $answer_id]); }