From d3ef0357067cbac825ae878b334725379b49ff3c Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 22 Mar 2022 12:10:13 +0000 Subject: [PATCH] MDL-74295 question bank: add help icons to columns that need it --- .../comment/classes/comment_count_column.php | 2 +- question/bank/comment/styles.css | 4 -- .../classes/columns/discrimination_index.php | 8 +++- .../columns/discriminative_efficiency.php | 6 ++- .../classes/columns/facility_index.php | 5 ++- question/bank/statistics/classes/helper.php | 6 +-- .../statistics/lang/en/qbank_statistics.php | 6 ++- .../tests/behat/statistics_action.feature | 4 +- .../usage/classes/question_usage_column.php | 6 ++- question/bank/usage/lang/en/qbank_usage.php | 1 + question/bank/usage/styles.css | 6 --- question/classes/local/bank/column_base.php | 15 ++++++- question/templates/column_header.mustache | 41 ++++++++++++++----- 13 files changed, 78 insertions(+), 32 deletions(-) delete mode 100644 question/bank/usage/styles.css diff --git a/question/bank/comment/classes/comment_count_column.php b/question/bank/comment/classes/comment_count_column.php index 03dd56d9f92..f9aa7c191a4 100644 --- a/question/bank/comment/classes/comment_count_column.php +++ b/question/bank/comment/classes/comment_count_column.php @@ -68,10 +68,10 @@ class comment_count_column extends column_base { $datatarget = '[data-target="' . $target . '"]'; $PAGE->requires->js_call_amd('qbank_comment/comment', 'init', [$datatarget]); $attributes = [ + 'href' => '#', 'data-target' => $target, 'data-questionid' => $question->id, 'data-courseid' => $this->qbank->course->id, - 'class' => 'link-primary comment-pointer' ]; } echo \html_writer::tag('a', $commentcount, $attributes); diff --git a/question/bank/comment/styles.css b/question/bank/comment/styles.css index 6fa9bcb860e..97dfe55b7fb 100644 --- a/question/bank/comment/styles.css +++ b/question/bank/comment/styles.css @@ -3,7 +3,3 @@ max-width: none; width: 100%; } - -.comment-pointer { - cursor: pointer; -} diff --git a/question/bank/statistics/classes/columns/discrimination_index.php b/question/bank/statistics/classes/columns/discrimination_index.php index a7cbabc7264..1f5b65a51e9 100644 --- a/question/bank/statistics/classes/columns/discrimination_index.php +++ b/question/bank/statistics/classes/columns/discrimination_index.php @@ -19,7 +19,9 @@ namespace qbank_statistics\columns; use core_question\local\bank\column_base; use qbank_statistics\helper; /** - * Discrimination index column + * This columns shows a message about whether this question is OK or needs revision. + * + * This is based on the average discrimination index. * * @package qbank_statistics * @copyright 2021 Catalyst IT Australia Pty Ltd @@ -37,6 +39,10 @@ class discrimination_index extends column_base { return get_string('discrimination_index', 'qbank_statistics'); } + public function help_icon(): ?\help_icon { + return new \help_icon('discrimination_index', 'qbank_statistics'); + } + /** * Column name. * diff --git a/question/bank/statistics/classes/columns/discriminative_efficiency.php b/question/bank/statistics/classes/columns/discriminative_efficiency.php index 45a201b8a63..713bbf9c827 100644 --- a/question/bank/statistics/classes/columns/discriminative_efficiency.php +++ b/question/bank/statistics/classes/columns/discriminative_efficiency.php @@ -19,7 +19,7 @@ namespace qbank_statistics\columns; use core_question\local\bank\column_base; use qbank_statistics\helper; /** - * Discriminative efficiency column + * This column show the average discriminative efficiency for this question. * * @package qbank_statistics * @copyright 2021 Catalyst IT Australia Pty Ltd @@ -37,6 +37,10 @@ class discriminative_efficiency extends column_base { return get_string('discriminative_efficiency', 'qbank_statistics'); } + public function help_icon(): ?\help_icon { + return new \help_icon('discriminative_efficiency', 'qbank_statistics'); + } + /** * Column name. * diff --git a/question/bank/statistics/classes/columns/facility_index.php b/question/bank/statistics/classes/columns/facility_index.php index efbf5425129..850ddd67a14 100644 --- a/question/bank/statistics/classes/columns/facility_index.php +++ b/question/bank/statistics/classes/columns/facility_index.php @@ -19,7 +19,7 @@ namespace qbank_statistics\columns; use core_question\local\bank\column_base; use qbank_statistics\helper; /** - * Facility index column + * This column show the average facility index for this question. * * @package qbank_statistics * @copyright 2021 Catalyst IT Australia Pty Ltd @@ -37,6 +37,9 @@ class facility_index extends column_base { return get_string('facility_index', 'qbank_statistics'); } + public function help_icon(): ?\help_icon { + return new \help_icon('facility_index', 'qbank_statistics'); + } /** * Column name. diff --git a/question/bank/statistics/classes/helper.php b/question/bank/statistics/classes/helper.php index c2845a54ba2..32b15c689c3 100644 --- a/question/bank/statistics/classes/helper.php +++ b/question/bank/statistics/classes/helper.php @@ -38,12 +38,12 @@ require_once($CFG->dirroot . '/mod/quiz/attemptlib.php'); class helper { /** - * @var float Threshold to determine 'need for revision' + * @var float Threshold to determine 'Needs checking?' */ private const NEED_FOR_REVISION_LOWER_THRESHOLD = 30; /** - * @var float Threshold to determine 'need for revision' + * @var float Threshold to determine 'Needs checking?' */ private const NEED_FOR_REVISION_UPPER_THRESHOLD = 50; @@ -198,7 +198,7 @@ class helper { } /** - * Format discrimination index (need for revision). + * Format discrimination index (Needs checking?). * * @param float|null $value stats value * @return array diff --git a/question/bank/statistics/lang/en/qbank_statistics.php b/question/bank/statistics/lang/en/qbank_statistics.php index 3bf07d557fc..e22faf79ba1 100644 --- a/question/bank/statistics/lang/en/qbank_statistics.php +++ b/question/bank/statistics/lang/en/qbank_statistics.php @@ -30,8 +30,12 @@ $string['privacy:metadata'] = 'The Question statistics question bank plugin does // Columns. $string['facility_index'] = 'Facility index'; +$string['facility_index_help'] = 'The facility index gives the average mark (as a percentage) obtained on the question (all versions) in all quizzes where the question has been attempted. A higher value normally indicates an easier question.'; $string['discriminative_efficiency'] = 'Discriminative efficiency'; -$string['discrimination_index'] = 'Need for revision'; +$string['discriminative_efficiency_help'] = 'Discriminative efficiency is a statistical estimate of how well the question assesses students, with a higher value being better. A particularly low value may indicate a problem with the question. A very difficult or easy question (with facility index close to 0% or 100%) can also lead to a low value.'; +$string['discriminative_efficiency_link'] = 'mod/quiz/statistics'; +$string['discrimination_index'] = 'Needs checking?'; +$string['discrimination_index_help'] = 'A question is indicated as likely to need checking based on question statistics. For example, if students obtain a low score on the question but a high score on the whole quiz, or a high score on the question but a low score on the whole quiz, then there may be a problem with the question such as the wrong answer being set as correct. Statistics are not infallible though; this is just a hint that the question should be checked.'; // Text format. $string['verylikely'] = 'Very likely'; diff --git a/question/bank/statistics/tests/behat/statistics_action.feature b/question/bank/statistics/tests/behat/statistics_action.feature index 4962d9456bc..1ffaccc58bf 100644 --- a/question/bank/statistics/tests/behat/statistics_action.feature +++ b/question/bank/statistics/tests/behat/statistics_action.feature @@ -25,11 +25,11 @@ Feature: Use the qbank plugin manager page for statistics And I navigate to "Question bank" in current page administration Then I should not see "Facility index" And I should not see "Discriminative efficiency" - And I should not see "Need for revision" + And I should not see "Needs checking?" And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration And I click on "Enable" "link" in the "Question statistics" "table_row" And I am on the "Test quiz" "quiz activity" page And I navigate to "Question bank" in current page administration And I should see "Facility index" And I should see "Discriminative efficiency" - And I should see "Need for revision" + And I should see "Needs checking?" diff --git a/question/bank/usage/classes/question_usage_column.php b/question/bank/usage/classes/question_usage_column.php index 72af6117eec..1a31c66077e 100644 --- a/question/bank/usage/classes/question_usage_column.php +++ b/question/bank/usage/classes/question_usage_column.php @@ -36,6 +36,10 @@ class question_usage_column extends column_base { return get_string('questionusage', 'qbank_usage'); } + public function help_icon(): ?\help_icon { + return new \help_icon('questionusage', 'qbank_usage'); + } + protected function display_content($question, $rowclasses): void { global $PAGE; $usagecount = helper::get_question_entry_usage_count($question); @@ -45,10 +49,10 @@ class question_usage_column extends column_base { $datatarget = '[data-target="' . $target . '"]'; $PAGE->requires->js_call_amd('qbank_usage/usage', 'init', [$datatarget, $question->contextid]); $attributes = [ + 'href' => '#', 'data-target' => $target, 'data-questionid' => $question->id, 'data-courseid' => $this->qbank->course->id, - 'class' => 'link-primary comment-pointer' ]; } echo \html_writer::tag('a', $usagecount, $attributes); diff --git a/question/bank/usage/lang/en/qbank_usage.php b/question/bank/usage/lang/en/qbank_usage.php index e44c6d07b9e..08efc6d94af 100644 --- a/question/bank/usage/lang/en/qbank_usage.php +++ b/question/bank/usage/lang/en/qbank_usage.php @@ -26,6 +26,7 @@ $string['pluginname'] = 'Question usage'; $string['privacy:metadata'] = 'The Question usage question bank plugin does not store any user data.'; $string['questionusage'] = 'Usage'; +$string['questionusage_help'] = 'The number of quizzes in which the question is used, with a link to open a window listing the quizzes and the number of attempts.'; $string['usageheader'] = 'Question usage'; // Table. diff --git a/question/bank/usage/styles.css b/question/bank/usage/styles.css deleted file mode 100644 index 1e9399a1e76..00000000000 --- a/question/bank/usage/styles.css +++ /dev/null @@ -1,6 +0,0 @@ -.questionusage { - cursor: pointer; -} -#categoryquestions .questionusage { - width: 5em; -} diff --git a/question/classes/local/bank/column_base.php b/question/classes/local/bank/column_base.php index 57e3994d820..c09022c9326 100644 --- a/question/classes/local/bank/column_base.php +++ b/question/classes/local/bank/column_base.php @@ -97,6 +97,7 @@ abstract class column_base { */ public function display_header(): void { global $PAGE; + $renderer = $PAGE->get_renderer('core_question', 'bank'); $data = []; $data['sortable'] = true; @@ -125,8 +126,11 @@ abstract class column_base { $data['tip'] = $tip; } } + $help = $this->help_icon(); + if ($help) { + $data['help'] = $help->export_for_template($renderer); + } - $renderer = $PAGE->get_renderer('core_question', 'bank'); echo $renderer->render_column_header($data); } @@ -145,6 +149,15 @@ abstract class column_base { return ''; } + /** + * If you return a help icon here, it is shown in the column header after the title. + * + * @return \help_icon|null help icon to show, if required. + */ + public function help_icon(): ?\help_icon { + return null; + } + /** * Get a link that changes the sort order, and indicates the current sort state. * @param string $sort the column to sort on. diff --git a/question/templates/column_header.mustache b/question/templates/column_header.mustache index 43d231374df..660e437102a 100644 --- a/question/templates/column_header.mustache +++ b/question/templates/column_header.mustache @@ -17,18 +17,36 @@ {{! @template core_question/column_header + Displays the header cell for a column in the question bank. + + Context variables required for this template: + * extraclasses: CSS classes to add to the th. E.g. "questionstatus pr-3". + * help: (optional, may be omitted) help icon. The structure here needs to be as from help_icon::export_for_template(). + + Other fields vary, depending on whether the column is sortable. + + Column with plain title, not sortable: + * sortable: false + * tiptitle: Column name (e.g. "Status") + * sorttip: (optional) must be true if tip is present. + * tip: (optional) a tool tip to show, if the title needs explanation. E.g. "Select questions for bulk actions". + + Sortable column, with a single type of sort (e.g. question type) + * sortable: true + * sortlinks: HTML of the title, in a link to sort by this. E.g. "\n T<\/i>\n<\/a>" + + Sortable column, with an overall title, and multiple sort types (e.g. question name/idnumber) + * sortable: true + * title: "Question" + * sortlinks: Several sort links concatenated. E.g. "\n Question name\n<\/a> \/ \n ID number\n<\/a>" + Example context (json): { - "qbankheaderdata": [ - { - "extraclasses": "checkbox", - "sortable": false, - "tiptitle": "Element title", - "sorttip": true, - "tip": "Select questions for bulk actions", - "sortlinks": "sort / sort" - } - ] + "sortable": false, + "extraclasses": "checkbox pr-3", + "tiptitle": "\n