class QuizQuestionH5PResponse in Quiz 7.4
Hierarchy
- class \QuizQuestionResponse
- class \QuizQuestionH5PResponse
Expanded class hierarchy of QuizQuestionH5PResponse
1 string reference to 'QuizQuestionH5PResponse'
- quiz_h5p_quiz_question_info in question_types/
quiz_h5p/ quiz_h5p.module - Implements hook_quiz_question_info().
File
- question_types/
quiz_h5p/ QuizQuestionH5PResponse.class.inc, line 3
View source
class QuizQuestionH5PResponse extends QuizQuestionResponse {
/**
* Delete result row for this question.
*/
public function delete() {
db_delete('quiz_h5p_user_results')
->condition('question_nid', $this->question->nid)
->condition('question_vid', $this->question->vid)
->condition('result_id', $this->rid)
->execute();
}
/**
* Needs to be implemented, not used.
*/
public function getResponse() {
}
/**
* Save current score and xAPI response in db.
*/
public function save() {
global $user;
// Decode xAPI answer data
$data = new H5PReportXAPIData(json_decode($this->answer));
// Parse data
$this
->saveXAPIData($data);
}
/**
* Recusive save of xAPI data
*
* @param \H5P\XAPIData $data
*/
private function saveXAPIData($data) {
// Save statement data
$dataID = db_insert('quiz_h5p_user_results')
->fields(array(
'parent_id' => $data
->getParentID(),
'question_nid' => $this->question->nid,
'question_vid' => $this->question->vid,
'result_id' => $this->rid,
'score_scaled' => $data
->getScoreScaled(),
'score_raw' => $data
->getScoreRaw(),
'score_min' => $data
->getScoreMin(),
'score_max' => $data
->getScoreMax(),
'interaction_type' => $data
->getInteractionType(),
'description' => $data
->getDescription(),
'correct_responses_pattern' => $data
->getCorrectResponsesPattern(),
'response' => $data
->getResponse(),
'additionals' => $data
->getAdditionals(),
))
->execute();
// Save sub content statements data
if ($data
->isCompound()) {
foreach ($data
->getChildren($dataID) as $subData) {
$this
->saveXAPIData($subData);
}
}
}
/**
* Get scaled score for question
*
* @return int
*/
public function score() {
global $user;
$percentScore = db_query("SELECT score_scaled\n FROM {quiz_h5p_user_results}\n WHERE question_nid = :question_nid\n AND question_vid = :question_vid\n AND result_id = :result_id", array(
'question_nid' => $this->question->nid,
'question_vid' => $this->question->vid,
'result_id' => $this->rid,
))
->fetchField();
return round($percentScore * $this
->getMaxScore());
}
/**
* Implementation of getReportFormQuestion
*
* @see QuizQuestionResponse#getReportFormQuestion($showpoints, $showfeedback, $allow_scoring)
*/
public function getReportFormQuestion($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) {
$title = db_query('SELECT title FROM {node} WHERE nid = :nid', array(
':nid' => $this->question->nid,
))
->fetchField();
return array(
'#markup' => check_plain($title),
);
}
/**
* Implements getReportFormResponse of QuizQuestionResponse interface
*/
public function getReportFormResponse($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) {
$result = db_select('quiz_h5p_user_results', 'qhur')
->fields('qhur')
->condition('question_nid', $this->question->nid)
->condition('question_vid', $this->question->vid)
->condition('result_id', $this->rid)
->orderBy('id', 'ASC')
->execute();
// Make it easy to map questions by id
$questionsById = array();
foreach ($result as $record) {
$questionsById[$record->id] = $record;
}
// Assemble our question tree
foreach ($questionsById as $question) {
if ($question->parent_id === NULL) {
// This is the root of our tree
$baseQuestion = $question;
}
elseif (isset($questionsById[$question->parent_id])) {
// Add to parent
$questionsById[$question->parent_id]->children[] = $question;
}
}
// Process question tree and create markup for report
if (isset($baseQuestion)) {
$report = theme('quiz_h5p_response', array(
'question' => $baseQuestion,
));
if (!empty($report)) {
return array(
'#markup' => $report,
);
}
}
// No report available
return array(
'#no-response' => TRUE,
);
}
/**
* Needs to be implemented. Is not used.
*/
public function getReportFormAnswerFeedback($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) {
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
QuizQuestionH5PResponse:: |
public | function |
Delete result row for this question. Overrides QuizQuestionResponse:: |
|
QuizQuestionH5PResponse:: |
public | function |
Needs to be implemented. Is not used. Overrides QuizQuestionResponse:: |
|
QuizQuestionH5PResponse:: |
public | function |
Implementation of getReportFormQuestion Overrides QuizQuestionResponse:: |
|
QuizQuestionH5PResponse:: |
public | function |
Implements getReportFormResponse of QuizQuestionResponse interface Overrides QuizQuestionResponse:: |
|
QuizQuestionH5PResponse:: |
public | function |
Needs to be implemented, not used. Overrides QuizQuestionResponse:: |
|
QuizQuestionH5PResponse:: |
public | function |
Save current score and xAPI response in db. Overrides QuizQuestionResponse:: |
|
QuizQuestionH5PResponse:: |
private | function | Recusive save of xAPI data | |
QuizQuestionH5PResponse:: |
public | function |
Get scaled score for question Overrides QuizQuestionResponse:: |
|
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | 9 | |
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 | Get the score part of the report form | 2 |
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. | 1 | |
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 | Validates response from a quiz taker. If the response isn't valid the quiz taker won't be allowed to proceed. | 6 |
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. | ||
QuizQuestionResponse:: |
public | function | Create a new user response. | 7 |