From 97cdc1de72116d78238b15cd1ed8699d6bc4f89e Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 7 Jun 2011 15:10:59 +0100 Subject: [PATCH] MDL-27747 quiz summary, add a CSS class to the table rows based on question state. The standard themes do not use this for anything, but it makes it easier for themers to do cool stuff. Also improve the API for getting the question state class. --- mod/quiz/attemptlib.php | 16 +++++++++++++++- mod/quiz/renderer.php | 2 ++ question/engine/questionattempt.php | 9 +++++++++ question/engine/questionusage.php | 10 ++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) 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 @@ -757,6 +757,20 @@ class quiz_attempt { } /** + * 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 * data about this question. @@ -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 @@ -518,6 +518,15 @@ class question_attempt { } /** + * @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. */ public function get_last_action_time() { 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 @@ -247,6 +247,16 @@ class question_usage_by_activity { } /** + * @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. * @return int timestamp. -- 2.11.4.GIT