View source
<?php
class QuizQuestionH5PResponse extends QuizQuestionResponse {
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();
}
public function getResponse() {
}
public function save() {
global $user;
$data = new H5PReportXAPIData(json_decode($this->answer));
$this
->saveXAPIData($data);
}
private function saveXAPIData($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();
if ($data
->isCompound()) {
foreach ($data
->getChildren($dataID) as $subData) {
$this
->saveXAPIData($subData);
}
}
}
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());
}
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),
);
}
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();
$questionsById = array();
foreach ($result as $record) {
$questionsById[$record->id] = $record;
}
foreach ($questionsById as $question) {
if ($question->parent_id === NULL) {
$baseQuestion = $question;
}
elseif (isset($questionsById[$question->parent_id])) {
$questionsById[$question->parent_id]->children[] = $question;
}
}
if (isset($baseQuestion)) {
$report = theme('quiz_h5p_response', array(
'question' => $baseQuestion,
));
if (!empty($report)) {
return array(
'#markup' => $report,
);
}
}
return array(
'#no-response' => TRUE,
);
}
public function getReportFormAnswerFeedback($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) {
return FALSE;
}
}