ScaleResponse.php in Quiz 8.6
File
question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleResponse.php
View source
<?php
class ScaleResponse extends QuizQuestionResponse {
protected $answer_id = 0;
public function __construct($result_id, stdClass $question_node, $answer = NULL) {
parent::__construct($result_id, $question_node, $answer);
if (isset($answer)) {
$this->answer_id = intval($answer);
}
else {
$this->answer_id = db_query('SELECT answer_id FROM {quiz_scale_user_answers} WHERE result_answer_id = :raid', array(
':raid' => $this->result_answer_id,
))
->fetchField();
}
$answer = db_query('SELECT answer FROM {quiz_scale_answer} WHERE id = :id', array(
':id' => $this->answer_id,
))
->fetchField();
$this->answer = check_plain($answer);
}
public function save() {
db_merge('quiz_scale_user_answers')
->key(array(
'result_answer_id' => $this->result_answer_id,
))
->fields(array(
'answer_id' => $this->answer_id,
'result_answer_id' => $this->result_answer_id,
))
->execute();
}
public function delete() {
db_delete('quiz_scale_user_answers')
->condition('result_answer_id', $this->result_answer_id)
->execute();
}
public function score() {
return (bool) $this
->getResponse();
}
public function getResponse() {
return $this->answer_id;
}
public function getFeedbackValues() {
$data = array();
$data[] = array(
'choice' => $this->answer,
);
return $data;
}
}