mirror of
https://github.com/moodle/moodle.git
synced 2025-03-19 15:10:05 +01:00
MDL-83860 qbank_viewquestionname: Add question name filter condition
This commit is contained in:
parent
a798b1db39
commit
c87cffac88
@ -17,6 +17,7 @@
|
||||
namespace qbank_viewquestionname;
|
||||
|
||||
use core_question\local\bank\plugin_features_base;
|
||||
use core_question\local\bank\view;
|
||||
|
||||
/**
|
||||
* Plugin entrypoint for columns.
|
||||
@ -27,10 +28,17 @@ use core_question\local\bank\plugin_features_base;
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class plugin_feature extends plugin_features_base {
|
||||
|
||||
#[\Override]
|
||||
public function get_question_columns($qbank): array {
|
||||
return [
|
||||
new question_name_idnumber_tags_column($qbank)
|
||||
];
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function get_question_filters(?view $qbank = null): array {
|
||||
return [
|
||||
new question_name_condition($qbank),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
<?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;
|
||||
|
||||
use core\output\datafilter;
|
||||
|
||||
/**
|
||||
* Filter condition for filtering on the question name
|
||||
*
|
||||
* @package qbank_viewquestionname
|
||||
* @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 question_name_condition extends \core_question\local\bank\condition {
|
||||
#[\Override]
|
||||
public function get_title() {
|
||||
return get_string('questionnamecondition', 'qbank_viewquestionname');
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public static function get_condition_key() {
|
||||
return 'questionname';
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function get_filter_class() {
|
||||
return 'core/datafilter/filtertypes/keyword';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an SQL condition and parameters for filtering on q.name.
|
||||
*
|
||||
* This will search for the terms provided anywhere in the name.
|
||||
*
|
||||
* @param array $filter
|
||||
* @return array
|
||||
*/
|
||||
public static function build_query_from_filter(array $filter): array {
|
||||
global $DB;
|
||||
|
||||
$conditions = [];
|
||||
$params = [];
|
||||
$notlike = $filter['jointype'] === datafilter::JOINTYPE_NONE;
|
||||
foreach ($filter['values'] as $key => $value) {
|
||||
$params["questionname{$key}"] = "%{$value}%";
|
||||
$conditions[] = $DB->sql_like('q.name', ":questionname{$key}", casesensitive: false, notlike: $notlike);
|
||||
}
|
||||
$delimiter = $filter['jointype'] === datafilter::JOINTYPE_ANY ? ' OR ' : ' AND ';
|
||||
return [
|
||||
implode($delimiter, $conditions),
|
||||
$params,
|
||||
];
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
|
||||
$string['pluginname'] = 'View question name';
|
||||
$string['privacy:metadata'] = 'The View question name question bank plugin does not store any personal data.';
|
||||
$string['questionnamecondition'] = 'Question name';
|
||||
// In place editing.
|
||||
$string['edit_question_name_hint'] = 'Edit question name';
|
||||
$string['edit_question_name_label'] = 'New value for {$a->name}';
|
||||
|
@ -0,0 +1,56 @@
|
||||
@qbank @qbank_viewquestionnname @javascript
|
||||
Feature: Filter questions by name
|
||||
As a teacher
|
||||
In order to organise my questions
|
||||
I want to filter the list of questions by name
|
||||
|
||||
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 |
|
||||
| Test questions | truefalse | First question | Answer the first question |
|
||||
| Test questions | numerical | Second question | Answer the second question |
|
||||
| Test questions | essay | Third Question | Answer the 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 name" 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 name" 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 name"
|
||||
And I set the field "Question name" 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 names by filter
|
||||
When I add question bank filter "Question name"
|
||||
And I set the field "Question name" 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"
|
Loading…
x
Reference in New Issue
Block a user