mirror of
https://github.com/moodle/moodle.git
synced 2025-03-23 09:00:30 +01:00
MDL-83883 qbank_editquestion: Add status filter condition
This allows users to filter questions based on whether a question is in "draft" or "ready" status.
This commit is contained in:
parent
e347532af4
commit
bfb057001b
11
question/bank/editquestion/amd/build/datafilter/filtertypes/status.min.js
vendored
Normal file
11
question/bank/editquestion/amd/build/datafilter/filtertypes/status.min.js
vendored
Normal file
@ -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 <mark.johnson@catalyst-eu.net>
|
||||
* @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
|
@ -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 <http://www.gnu.org/licenses/>.\n\n/**\n * Filter for Status - Ready/Draft\n *\n * @module qbank_editquestion/datafilter/filtertypes/status\n * @author Mark Johnson <mark.johnson@catalyst-eu.net>\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"}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Filter for Status - Ready/Draft
|
||||
*
|
||||
* @module qbank_editquestion/datafilter/filtertypes/status
|
||||
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
|
||||
* @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'}
|
||||
]);
|
||||
}
|
||||
}
|
@ -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),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
88
question/bank/editquestion/classes/status_condition.php
Normal file
88
question/bank/editquestion/classes/status_condition.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 <mark.johnson@catalyst-eu.net>
|
||||
* @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]]],
|
||||
];
|
||||
}
|
||||
}
|
@ -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.';
|
||||
|
||||
|
@ -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"
|
Loading…
x
Reference in New Issue
Block a user