diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php index bdca5c7256e..2ed1246ac96 100644 --- a/mod/quiz/attemptlib.php +++ b/mod/quiz/attemptlib.php @@ -756,6 +756,20 @@ class quiz_attempt { return $this->quba->get_question_state_string($slot, $showcorrectness); } + /** + * Return the grade obtained on a particular question, if the user is permitted + * to see it. You must previously have called load_question_states to load the + * state data about this question. + * + * @param int $slot the number used to identify this question within this attempt. + * @param bool $showcorrectness Whether right/partial/wrong states should + * be distinguised. + * @return string class name for this state. + */ + public function get_question_state_class($slot, $showcorrectness) { + return $this->quba->get_question_state_class($slot, $showcorrectness); + } + /** * Return the grade obtained on a particular question. * You must previously have called load_question_states to load the state @@ -1167,7 +1181,7 @@ abstract class quiz_nav_panel_base { $button = new quiz_nav_question_button(); $button->id = 'quiznavbutton' . $slot; $button->number = $qa->get_question()->_number; - $button->stateclass = $qa->get_state()->get_state_class($showcorrectness); + $button->stateclass = $qa->get_state_class($showcorrectness); if (!$showcorrectness && $button->stateclass == 'notanswered') { $button->stateclass = 'complete'; } diff --git a/mod/quiz/renderer.php b/mod/quiz/renderer.php index 8ba1c279b45..2f518ebd999 100644 --- a/mod/quiz/renderer.php +++ b/mod/quiz/renderer.php @@ -484,6 +484,8 @@ class mod_quiz_renderer extends plugin_renderer_base { $row[] = $attemptobj->get_question_mark($slot); } $table->data[] = $row; + $table->rowclasses[] = $attemptobj->get_question_state_class( + $slot, $displayoptions->correctness); } // Print the summary table. diff --git a/question/engine/questionattempt.php b/question/engine/questionattempt.php index 083bb062a2d..7f9a268200e 100644 --- a/question/engine/questionattempt.php +++ b/question/engine/questionattempt.php @@ -517,6 +517,15 @@ class question_attempt { return $this->behaviour->get_state_string($showcorrectness); } + /** + * @param bool $showcorrectness Whether right/partial/wrong states should + * be distinguised. + * @return string a CSS class name for the current state. + */ + public function get_state_class($showcorrectness) { + return $this->get_state()->get_state_class($showcorrectness); + } + /** * @return int the timestamp of the most recent step in this question attempt. */ diff --git a/question/engine/questionusage.php b/question/engine/questionusage.php index 5811c8981ea..6583552d97a 100644 --- a/question/engine/questionusage.php +++ b/question/engine/questionusage.php @@ -246,6 +246,16 @@ class question_usage_by_activity { return $this->get_question_attempt($slot)->get_state_string($showcorrectness); } + /** + * @param int $slot the number used to identify this question within this usage. + * @param bool $showcorrectness Whether right/partial/wrong states should + * be distinguised. + * @return string a CSS class name for the current state. + */ + public function get_question_state_class($slot, $showcorrectness) { + return $this->get_question_attempt($slot)->get_state_class($showcorrectness); + } + /** * Get the time of the most recent action performed on a question. * @param int $slot the number used to identify this question within this usage.