class ScaleResponse in Quiz 8.4
Extension of QuizQuestionResponse
Hierarchy
- class \Drupal\quiz_question\QuizQuestionResponse
- class \Drupal\scale\ScaleResponse
Expanded class hierarchy of ScaleResponse
1 file declares its use of ScaleResponse
- ScaleQuestion.php in question_types/
scale/ lib/ Drupal/ scale/ ScaleQuestion.php - The main classes for the short answer question type.
File
- question_types/
scale/ lib/ Drupal/ scale/ ScaleResponse.php, line 19 - The main classes for the short answer response.
Namespace
Drupal\scaleView source
class ScaleResponse extends QuizQuestionResponse {
/**
* ID of the answer.
*/
protected $answer_id = 0;
/**
* Constructor
*/
public function __construct($result_id, $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_id = :rid AND question_nid = :qnid AND question_vid = :qvid', array(
':rid' => $result_id,
':qnid' => $this->question
->id(),
':qvid' => $this->question
->getRevisionId(),
))
->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 isValid() {
if (empty($this->answer_id)) {
return t('You must provide an answer');
}
return TRUE;
}
/**
* Implementation of save
*
* @see QuizQuestionResponse#save()
*/
public function save() {
$id = db_insert('quiz_scale_user_answers')
->fields(array(
'answer_id' => $this->answer_id,
'result_id' => $this->rid,
'question_vid' => $this->question
->getRevisionId(),
'question_nid' => $this->question
->id(),
))
->execute();
}
/**
* Implementation of delete
*
* @see QuizQuestionResponse#delete()
*/
public function delete() {
db_delete('quiz_scale_user_answers')
->condition('result_id', $this->rid)
->condition('question_nid', $this->question
->id())
->condition('question_vid', $this->question
->getRevisionId())
->execute();
}
/**
* Implementation of score
*
* @see QuizQuestionResponse#score()
*/
public function score() {
return $this
->isValid() ? 1 : 0;
}
/**
* Implementation of getResponse
*
* @see QuizQuestionResponse#getResponse()
*/
public function getResponse() {
return $this->answer_id;
}
/**
* Implementation of getReportFormResponse
*
* @see getReportFormResponse($showpoints, $showfeedback, $allow_scoring)
*/
public function getReportFormResponse($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) {
$form = array();
$form['#theme'] = 'scale_response_form';
$form['answer'] = array(
'#markup' => check_plain($this->answer),
);
return $form;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | 8 | |
QuizQuestionResponse:: |
protected | function | Utility function that returns the format of the node body | |
QuizQuestionResponse:: |
public | function | Returns stored max score if it exists, if not the max score is calculated and returned. | |
QuizQuestionResponse:: |
public | function | Get data suitable for reporting a user's score on the question. This expects an object with the following attributes: | |
QuizQuestionResponse:: |
public | function | Creates the report form for the admin pages, and for when a user gets feedback after answering questions. | 1 |
QuizQuestionResponse:: |
public | function | 2 | |
QuizQuestionResponse:: |
public | function | get the question part of the reportForm | |
QuizQuestionResponse:: |
public | function | Get the score part of the report form | 3 |
QuizQuestionResponse:: |
public | function | Get the submit function for the reportForm | 2 |
QuizQuestionResponse:: |
public | function | Get the theme key for the reportForm | |
QuizQuestionResponse:: |
public | function | Get the validate function for the reportForm | 2 |
QuizQuestionResponse:: |
function | Returns stored score if it exists, if not the score is calculated and returned. | ||
QuizQuestionResponse:: |
function | Check to see if the answer is marked as correct. | ||
QuizQuestionResponse:: |
public | function | Indicate whether the response has been evaluated (scored) yet. Questions that require human scoring (e.g. essays) may need to manually toggle this. | |
QuizQuestionResponse:: |
public | function | Used to refresh this instances question node in case drupal has changed it. | |
QuizQuestionResponse:: |
public | function | Saves the quiz result. This is not used when a question is skipped! | |
QuizQuestionResponse:: |
function | Represent the response as a stdClass object. | ||
ScaleResponse:: |
protected | property | ID of the answer. | |
ScaleResponse:: |
public | function |
Implementation of delete Overrides QuizQuestionResponse:: |
|
ScaleResponse:: |
public | function |
Implementation of getReportFormResponse Overrides QuizQuestionResponse:: |
|
ScaleResponse:: |
public | function |
Implementation of getResponse Overrides QuizQuestionResponse:: |
|
ScaleResponse:: |
public | function |
Validates response from a quiz taker. If the response isn't valid the quiz taker won't be allowed to proceed. Overrides QuizQuestionResponse:: |
|
ScaleResponse:: |
public | function |
Implementation of save Overrides QuizQuestionResponse:: |
|
ScaleResponse:: |
public | function |
Implementation of score Overrides QuizQuestionResponse:: |
|
ScaleResponse:: |
public | function |
Constructor Overrides QuizQuestionResponse:: |