forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-83861 qbank: Add question idnumber filter
- Loading branch information
1 parent
2c93e16
commit c07e85f
Showing
5 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
question/bank/viewquestionname/classes/question_idnumber_condition.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?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_viewquestionname; | ||
|
||
/** | ||
* Filter condition for filtering on the question idnumber | ||
* | ||
* @package qbank_viewquestionname | ||
* @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net} | ||
* @author Mark Johnson <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class question_idnumber_condition extends question_name_condition { | ||
#[\Override] | ||
public function get_title() { | ||
return get_string('questionidnumbercondition', 'qbank_viewquestionname'); | ||
} | ||
|
||
#[\Override] | ||
public static function get_condition_key() { | ||
return 'questionidnumber'; | ||
} | ||
|
||
#[\Override] | ||
protected static function get_filter_field(): string { | ||
return 'qbe.idnumber'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
question/bank/viewquestionname/tests/behat/filter_condition_question_idnumber.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
@qbank @qbank_viewquestionnname @javascript | ||
Feature: Filter questions by idnumber | ||
As a teacher | ||
In order to organise my questions | ||
I want to filter the list of questions by idnumber | ||
|
||
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 | idnumber | | ||
| Test questions | truefalse | a | Answer the first question | First question | | ||
| Test questions | numerical | b | Answer the second question | Second question | | ||
| Test questions | essay | c | Answer the third question | Third Question | | ||
And 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" | ||
|
||
Scenario: Filter by a single word | ||
When I apply question bank filter "Question ID number" with value "First" | ||
Then I should see "First question" | ||
And I should not see "Second question" | ||
And I should not see "Third Question" | ||
|
||
Scenario: Filter by any word | ||
When I apply question bank filter "Question ID number" with value "First, Third" | ||
Then I should see "First question" | ||
And I should not see "Second question" | ||
And I should see "Third Question" | ||
|
||
Scenario: Filter by all words | ||
When I add question bank filter "Question ID number" | ||
And I set the field "Question ID number" to "question, d" | ||
And I set the field "Match" in the "Filter 3" "fieldset" to "All" | ||
And I press "Apply filters" | ||
Then I should not see "First question" | ||
And I should see "Second question" | ||
# Filter should be case-insensitive. | ||
And I should see "Third Question" | ||
|
||
Scenario: Exclude idnumbers by filter | ||
When I add question bank filter "Question ID number" | ||
And I set the field "Question ID number" to "First, Third" | ||
And I set the field "Match" in the "Filter 3" "fieldset" to "None" | ||
And I press "Apply filters" | ||
Then I should not see "First question" | ||
And I should see "Second question" | ||
And I should not see "Third Question" |