Merge branch 'MDL-83881_main' of https://github.com/marxjohnson/moodle
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?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_viewcreator;
|
||||
|
||||
use core\output\datafilter;
|
||||
use core_question\local\bank\condition;
|
||||
|
||||
/**
|
||||
* Filter condition for filtering on creator name
|
||||
*
|
||||
* @package qbank_viewcreator
|
||||
* @copyright 2025 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 createdby_condition extends user_condition {
|
||||
#[\Override]
|
||||
public function get_title() {
|
||||
return get_string('createdby', 'question');
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public static function get_condition_key() {
|
||||
return 'createdby';
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected static function get_table_alias(): string {
|
||||
return 'uc';
|
||||
}
|
||||
}
|
||||
@@ -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_viewcreator;
|
||||
|
||||
/**
|
||||
* Filter condition for filtering on modifier name
|
||||
*
|
||||
* @package qbank_viewcreator
|
||||
* @copyright 2025 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 modifiedby_condition extends user_condition {
|
||||
#[\Override]
|
||||
public function get_title() {
|
||||
return get_string('modifiedby', 'qbank_viewcreator');
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public static function get_condition_key() {
|
||||
return 'modifiername';
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected static function get_table_alias(): string {
|
||||
return 'um';
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,8 @@ class plugin_feature extends plugin_features_base {
|
||||
public function get_question_filters(?view $qbank = null): array {
|
||||
return [
|
||||
new timemodified_condition($qbank),
|
||||
new createdby_condition($qbank),
|
||||
new modifiedby_condition($qbank),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?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_viewcreator;
|
||||
|
||||
use core\output\datafilter;
|
||||
use core_question\local\bank\condition;
|
||||
|
||||
/**
|
||||
* Abstract class for conditions filtering by user.
|
||||
*
|
||||
* @package qbank_viewcreator
|
||||
* @copyright 2025 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
|
||||
*/
|
||||
abstract class user_condition extends condition {
|
||||
|
||||
/**
|
||||
* Return the alias for the instance of the user table to filter on.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected static function get_table_alias(): string;
|
||||
|
||||
#[\Override]
|
||||
public function get_filter_class() {
|
||||
return 'core/datafilter/filtertypes/keyword';
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public static function build_query_from_filter(array $filter): array {
|
||||
global $DB;
|
||||
|
||||
$conditions = [];
|
||||
$params = [];
|
||||
$notlike = $filter['jointype'] === datafilter::JOINTYPE_NONE;
|
||||
$tablealias = static::get_table_alias();
|
||||
$allnames = array_map(fn($field) => "{$tablealias}.{$field}", \core_user\fields::get_name_fields());
|
||||
$allnames = $DB->sql_concat(...$allnames);
|
||||
$conditionkey = static::get_condition_key();
|
||||
foreach ($filter['values'] as $key => $value) {
|
||||
$params["{$conditionkey}{$key}"] = "%$value%";
|
||||
$conditions[] = $DB->sql_like($allnames, ":{$conditionkey}{$key}", casesensitive: false, notlike: $notlike);
|
||||
}
|
||||
$delimiter = $filter['jointype'] === datafilter::JOINTYPE_ANY ? ' OR ' : ' AND ';
|
||||
return [
|
||||
implode($delimiter, $conditions),
|
||||
$params,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@
|
||||
* @author Ghaly Marc-Alexandre <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['history'] = 'History';
|
||||
$string['modifiedby'] = 'Modified by';
|
||||
$string['timemodified'] = 'Time modified';
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
@qbank @qbank_viewcreator @javascript
|
||||
Feature: Filter questions by creator name
|
||||
As a teacher
|
||||
In order to organise my questions
|
||||
I want to filter the list of questions by creator name
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | firstnamephonetic | lastnamephonetic | middlename | alternatename |
|
||||
| aa | Aaron | Aaronson | Aron | Aronsun | Andrew | Andy |
|
||||
| bb | Bob | Bobson | | | | |
|
||||
| cc | Clare | Clareson | | | | |
|
||||
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 "course enrolments" exist:
|
||||
| course | user | role |
|
||||
| C1 | aa | editingteacher |
|
||||
| C1 | bb | editingteacher |
|
||||
| C1 | cc | editingteacher |
|
||||
And the following "questions" exist:
|
||||
| qtype | questioncategory | name | user |
|
||||
| truefalse | Test questions | First question | aa |
|
||||
| truefalse | Test questions | Second question | bb |
|
||||
| truefalse | Test questions | Third question | cc |
|
||||
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 "Created by" with value "Aaron"
|
||||
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 "Created by" with value "Aaron, Clare"
|
||||
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 "Created by"
|
||||
And I set the field "Created by" to "son, Aar"
|
||||
And I set the field "Match" in the "Filter 3" "fieldset" to "All"
|
||||
And I press "Apply filters"
|
||||
Then I should see "First question"
|
||||
And I should not see "Second question"
|
||||
And I should not see "Third question"
|
||||
|
||||
Scenario: Filter by additional name fields
|
||||
When I apply question bank filter "Created by" with value "Aron"
|
||||
Then I should see "First question"
|
||||
And I should not see "Second question"
|
||||
And I should not see "Third question"
|
||||
When I apply question bank filter "Created by" with value "sun"
|
||||
Then I should see "First question"
|
||||
And I should not see "Second question"
|
||||
And I should not see "Third question"
|
||||
When I apply question bank filter "Created by" with value "drew"
|
||||
Then I should see "First question"
|
||||
And I should not see "Second question"
|
||||
And I should not see "Third question"
|
||||
When I apply question bank filter "Created by" with value "Andy"
|
||||
Then I should see "First question"
|
||||
And I should not see "Second question"
|
||||
And I should not see "Third question"
|
||||
|
||||
Scenario: Exclude names by filter
|
||||
When I add question bank filter "Created by"
|
||||
And I set the field "Created by" to "Aron, Clare"
|
||||
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"
|
||||
@@ -0,0 +1,88 @@
|
||||
@qbank @qbank_viewcreator @javascript
|
||||
Feature: Filter questions by modifier name
|
||||
As a teacher
|
||||
In order to organise my questions
|
||||
I want to filter the list of questions by modifier name
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | firstnamephonetic | lastnamephonetic | middlename | alternatename |
|
||||
| aa | Aaron | Aaronson | Aron | Aronsun | Andrew | Andy |
|
||||
| bb | Bob | Bobson | | | | |
|
||||
| cc | Clare | Clareson | | | | |
|
||||
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 "course enrolments" exist:
|
||||
| course | user | role |
|
||||
| C1 | aa | editingteacher |
|
||||
| C1 | bb | editingteacher |
|
||||
| C1 | cc | editingteacher |
|
||||
And the following "questions" exist:
|
||||
| qtype | questioncategory | name |
|
||||
| truefalse | Test questions | First question |
|
||||
| truefalse | Test questions | Second question |
|
||||
| truefalse | Test questions | Third question |
|
||||
And the following "core_question > updated questions" exist:
|
||||
| questioncategory | question | name | modifiedbyuser |
|
||||
| Test questions | First question | First question | aa |
|
||||
| Test questions | Second question | Second question | bb |
|
||||
| Test questions | Third question | Third question | cc |
|
||||
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 "Modified by" with value "Aaron"
|
||||
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 "Modified by" with value "Aaron, Clare"
|
||||
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 "Modified by"
|
||||
And I set the field "Modified by" to "son, Aar"
|
||||
And I set the field "Match" in the "Filter 3" "fieldset" to "All"
|
||||
And I press "Apply filters"
|
||||
Then I should see "First question"
|
||||
And I should not see "Second question"
|
||||
And I should not see "Third question"
|
||||
|
||||
Scenario: Filter by additional name fields
|
||||
When I apply question bank filter "Modified by" with value "Aron"
|
||||
Then I should see "First question"
|
||||
And I should not see "Second question"
|
||||
And I should not see "Third question"
|
||||
When I apply question bank filter "Modified by" with value "sun"
|
||||
Then I should see "First question"
|
||||
And I should not see "Second question"
|
||||
And I should not see "Third question"
|
||||
When I apply question bank filter "Modified by" with value "drew"
|
||||
Then I should see "First question"
|
||||
And I should not see "Second question"
|
||||
And I should not see "Third question"
|
||||
When I apply question bank filter "Modified by" with value "Andy"
|
||||
Then I should see "First question"
|
||||
And I should not see "Second question"
|
||||
And I should not see "Third question"
|
||||
|
||||
Scenario: Exclude names by filter
|
||||
When I add question bank filter "Modified by"
|
||||
And I set the field "Modified by" to "Aron, Clare"
|
||||
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"
|
||||
@@ -45,7 +45,12 @@ class behat_core_question_generator extends behat_generator_base {
|
||||
'singular' => 'question',
|
||||
'datagenerator' => 'updated_question',
|
||||
'required' => ['question', 'questioncategory'],
|
||||
'switchids' => ['question' => 'id', 'questioncategory' => 'category'],
|
||||
'switchids' => [
|
||||
'question' => 'id',
|
||||
'questioncategory' => 'category',
|
||||
'modifiedbyuser' => 'modifiedby',
|
||||
'createdbyuser' => 'createdby',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -65,6 +70,26 @@ class behat_core_question_generator extends behat_generator_base {
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up the id of the createdby user from their username
|
||||
*
|
||||
* @param string $username The username for the createdby user.
|
||||
* @return int The user ID.
|
||||
*/
|
||||
protected function get_createdbyuser_id(string $username): int {
|
||||
return $this->get_user_id($username);
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up the id of the modifiedby user from their username
|
||||
*
|
||||
* @param string $username The username for the modifiedby user.
|
||||
* @return int The user ID.
|
||||
*/
|
||||
protected function get_modifiedbyuser_id(string $username): int {
|
||||
return $this->get_user_id($username);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a question
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user