diff --git a/question/bank/editquestion/amd/build/datafilter/filtertypes/status.min.js b/question/bank/editquestion/amd/build/datafilter/filtertypes/status.min.js new file mode 100644 index 00000000000..df64bdb5965 --- /dev/null +++ b/question/bank/editquestion/amd/build/datafilter/filtertypes/status.min.js @@ -0,0 +1,11 @@ +define("qbank_editquestion/datafilter/filtertypes/status",["exports","core/datafilter/filtertypes/binary","core/str"],(function(_exports,_binary,_str){var obj; +/** + * Filter for Status - Ready/Draft + * + * @module qbank_editquestion/datafilter/filtertypes/status + * @author Mark Johnson + * @copyright 2024 Catalyst IT Europe Ltd + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_binary=(obj=_binary)&&obj.__esModule?obj:{default:obj};class _default extends _binary.default{getTextValues(){return(0,_str.get_strings)([{key:"questionstatusready",component:"qbank_editquestion"},{key:"questionstatusdraft",component:"qbank_editquestion"}])}}return _exports.default=_default,_exports.default})); + +//# sourceMappingURL=status.min.js.map \ No newline at end of file diff --git a/question/bank/editquestion/amd/build/datafilter/filtertypes/status.min.js.map b/question/bank/editquestion/amd/build/datafilter/filtertypes/status.min.js.map new file mode 100644 index 00000000000..32a09371d8e --- /dev/null +++ b/question/bank/editquestion/amd/build/datafilter/filtertypes/status.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"status.min.js","sources":["../../../src/datafilter/filtertypes/status.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Filter for Status - Ready/Draft\n *\n * @module qbank_editquestion/datafilter/filtertypes/status\n * @author Mark Johnson \n * @copyright 2024 Catalyst IT Europe Ltd\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Binary from 'core/datafilter/filtertypes/binary';\nimport {get_strings as getStrings} from 'core/str';\n\nexport default class extends Binary {\n /**\n * Return strings for Draft/Ready statuses.\n *\n * @returns {Promise}\n */\n getTextValues() {\n return getStrings([\n {key: 'questionstatusready', component: 'qbank_editquestion'},\n {key: 'questionstatusdraft', component: 'qbank_editquestion'}\n ]);\n }\n}\n"],"names":["Binary","getTextValues","key","component"],"mappings":";;;;;;;;oKA2B6BA,gBAMzBC,uBACW,oBAAW,CACd,CAACC,IAAK,sBAAuBC,UAAW,sBACxC,CAACD,IAAK,sBAAuBC,UAAW"} \ No newline at end of file diff --git a/question/bank/editquestion/amd/src/datafilter/filtertypes/status.js b/question/bank/editquestion/amd/src/datafilter/filtertypes/status.js new file mode 100644 index 00000000000..5bd0a5f536c --- /dev/null +++ b/question/bank/editquestion/amd/src/datafilter/filtertypes/status.js @@ -0,0 +1,40 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Filter for Status - Ready/Draft + * + * @module qbank_editquestion/datafilter/filtertypes/status + * @author Mark Johnson + * @copyright 2024 Catalyst IT Europe Ltd + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +import Binary from 'core/datafilter/filtertypes/binary'; +import {get_strings as getStrings} from 'core/str'; + +export default class extends Binary { + /** + * Return strings for Draft/Ready statuses. + * + * @returns {Promise} + */ + getTextValues() { + return getStrings([ + {key: 'questionstatusready', component: 'qbank_editquestion'}, + {key: 'questionstatusdraft', component: 'qbank_editquestion'} + ]); + } +} diff --git a/question/bank/editquestion/classes/plugin_feature.php b/question/bank/editquestion/classes/plugin_feature.php index bb5b813c28f..9d43930181f 100644 --- a/question/bank/editquestion/classes/plugin_feature.php +++ b/question/bank/editquestion/classes/plugin_feature.php @@ -71,4 +71,10 @@ class plugin_feature extends \core_question\local\bank\plugin_features_base { ]; } + #[\Override] + public function get_question_filters(?view $qbank = null): array { + return [ + new status_condition($qbank), + ]; + } } diff --git a/question/bank/editquestion/classes/status_condition.php b/question/bank/editquestion/classes/status_condition.php new file mode 100644 index 00000000000..97a2af824b1 --- /dev/null +++ b/question/bank/editquestion/classes/status_condition.php @@ -0,0 +1,88 @@ +. + +namespace qbank_editquestion; + +use core_question\local\bank\condition; +use core_question\local\bank\question_version_status; + +/** + * Filter condition for the status column + * + * @package qbank_editquestion + * @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net} + * @author Mark Johnson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class status_condition extends condition { + #[\Override] + public function get_title() { + return get_string('filter:status', 'qbank_editquestion'); + } + + #[\Override] + public static function get_condition_key() { + return 'status'; + } + + #[\Override] + public function get_filter_class() { + return 'qbank_editquestion/datafilter/filtertypes/status'; + } + + /** + * Return a single join type, we don't want a join type selector for this condition. + * + * @return array + */ + public function get_join_list(): array { + return [ + self::JOINTYPE_DEFAULT, + ]; + } + + /** + * Return an array mapping the values returned from the filter to the values required for the query. + * + * @return array + */ + protected static function get_status_list() { + return [ + 0 => question_version_status::QUESTION_STATUS_READY, + 1 => question_version_status::QUESTION_STATUS_DRAFT, + ]; + } + + /** + * Return an SQL condition to filter qv.status on the selected status. + * + * @param array $filter + * @return array + */ + public static function build_query_from_filter(array $filter): array { + if (!isset($filter['values'][0])) { + return ['', []]; + } + $statuses = self::get_status_list(); + if (!array_key_exists($filter['values'][0], $statuses)) { + throw new \moodle_exception('filter:invalidstatus', 'qbank_editquestion', '', $filter['values'][0]); + } + return [ + 'qv.status = :status', + ['status' => $statuses[$filter['values'][0]]], + ]; + } +} diff --git a/question/bank/editquestion/lang/en/qbank_editquestion.php b/question/bank/editquestion/lang/en/qbank_editquestion.php index 84312d1a378..02bc1ce45ce 100644 --- a/question/bank/editquestion/lang/en/qbank_editquestion.php +++ b/question/bank/editquestion/lang/en/qbank_editquestion.php @@ -23,6 +23,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['filter:status'] = 'Status of latest version'; +$string['filter:invalidstatus'] = 'Invalid value "{$a}" for status filter.'; + $string['pluginname'] = 'Edit questions'; $string['privacy:metadata'] = 'The Edit questions question bank plugin does not store any personal data.'; diff --git a/question/bank/editquestion/tests/behat/filter_condition_question_status.feature b/question/bank/editquestion/tests/behat/filter_condition_question_status.feature new file mode 100644 index 00000000000..8e96c030760 --- /dev/null +++ b/question/bank/editquestion/tests/behat/filter_condition_question_status.feature @@ -0,0 +1,41 @@ +@qbank @qbank_editquestion @javascript +Feature: Filter questions by status + As a teacher + In order to quickly find questions in Draft or Ready status + I want to filter the list of questions by status + + Background: + Given the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "activities" exist: + | activity | name | intro | course | idnumber | + | qbank | Qbank 1 | Question bank 1 | C1 | qbank1 | + And the following "question categories" exist: + | contextlevel | reference | name | + | Activity module | qbank1 | Test questions | + And the following "questions" exist: + | questioncategory | qtype | name | questiontext | status | + | Test questions | truefalse | First question | Answer the first question | ready | + | Test questions | numerical | Second question | Answer the second question | draft | + | Test questions | essay | Third question | Answer the third question | ready | + + Scenario: Filter by ready status + Given I am on the "Qbank 1" "core_question > question bank" page logged in as "admin" + And I should see "First question" + And I should see "Second question" + And I should see "Third question" + When I apply question bank filter "Status of latest version" with value "Ready" + Then I should see "First question" + And I should not see "Second question" + And I should see "Third question" + + Scenario: Filter by draft status + Given I am on the "Qbank 1" "core_question > question bank" page logged in as "admin" + And I should see "First question" + And I should see "Second question" + And I should see "Third question" + When I apply question bank filter "Status of latest version" with value "Draft" + Then I should not see "First question" + And I should see "Second question" + And I should not see "Third question"