|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @file |
| 5 | + * Response type class definition. |
| 6 | + */ |
| 7 | + |
| 8 | +class H5pQuizResponse extends QuizQuestionResponse { |
| 9 | + |
| 10 | + /** |
| 11 | + * @copydoc QuizQuestionResponse::save() |
| 12 | + */ |
| 13 | + public function save() { |
| 14 | + global $user; |
| 15 | + |
| 16 | + $scaled = h5p_quiz_data_load_score($user->uid,$this->question->nid,$this->question->vid); |
| 17 | + |
| 18 | + // Something went wrong. Set a score of -1. |
| 19 | + if (!isset($scaled) || !is_numeric($scaled)) { |
| 20 | + $scaled = -1; |
| 21 | + } |
| 22 | + |
| 23 | + db_insert('h5p_quiz_user_results') |
| 24 | + ->fields(array( |
| 25 | + 'question_nid' => $this->question->nid, |
| 26 | + 'question_vid' => $this->question->vid, |
| 27 | + 'result_id' => $this->rid, |
| 28 | + 'score_scaled' => $scaled, |
| 29 | + )) |
| 30 | + ->execute(); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @copydoc QuizQuestionResponse::delete() |
| 35 | + */ |
| 36 | + public function delete() { |
| 37 | + db_delete('h5p_quiz_user_results') |
| 38 | + ->condition('question_nid', $this->question->nid) |
| 39 | + ->condition('question_vid', $this->question->vid) |
| 40 | + ->condition('result_id', $this->rid) |
| 41 | + ->execute(); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @copydoc QuizQuestionResponse::score() |
| 46 | + */ |
| 47 | + public function score() { |
| 48 | + $scaled = db_select('h5p_quiz_user_results', 'o') |
| 49 | + ->fields('o', array('score_scaled')) |
| 50 | + ->condition('question_nid', $this->question->nid) |
| 51 | + ->condition('question_vid', $this->question->vid) |
| 52 | + ->condition('result_id', $this->rid) |
| 53 | + ->execute() |
| 54 | + ->fetchField(); |
| 55 | + |
| 56 | + |
| 57 | + $scaled *= $this->getMaxScore(); |
| 58 | + |
| 59 | + return $scaled; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @copydoc QuizQuestionResponse::getResponse() |
| 64 | + */ |
| 65 | + public function getResponse() { |
| 66 | + return 'In H5p package'; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Implementation of getReportForm |
| 71 | + * |
| 72 | + * @see QuizQuestionResponse#getReportForm($showpoints, $showfeedback, $allow_scoring) |
| 73 | + */ |
| 74 | + public function getReportForm($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) { |
| 75 | + return array( |
| 76 | + '#no_report' => TRUE, |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + |
| 81 | + public function getReportFormAnswerFeedback($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) { |
| 82 | + return FALSE; |
| 83 | + } |
| 84 | + |
| 85 | +} |
0 commit comments