/** * Save changes to question instance * * Saves changes to the question grades in the quiz_question_instances table. * It does not update 'sumgrades' in the quiz table. * * @param int grade The maximal grade for the question * @param int $questionid The id of the question * @param int $quizid The id of the quiz to update / add the instances for. */ function quiz_update_question_instance($grade, $questionid, $quiz) { global $DB; $instance = $DB->get_record('quiz_question_instances', array('quiz' => $quiz->id, 'question' => $questionid)); $slot = quiz_get_slot_for_question($quiz, $questionid); if (!$instance || !$slot) { throw new coding_exception('Attempt to change the grade of a quesion not in the quiz.'); } if (abs($grade - $instance->grade) < 1e-7) { // Grade has not changed. Nothing to do. return; } $instance->grade = $grade; $DB->update_record('quiz_question_instances', $instance); question_engine::set_max_mark_in_attempts(new qubaids_for_quiz($quiz->id), $slot, $grade); }
public function test_quiz_get_slot_for_question() { $quiz = new stdClass(); $quiz->questions = '1,2,0,7,0'; $this->assertEquals(1, quiz_get_slot_for_question($quiz, 1)); $this->assertEquals(3, quiz_get_slot_for_question($quiz, 7)); }