Merge branch 'master_MDL-72957-modifiedby-41' of https://github.com/catalyst/moodle-MDL-72752

This commit is contained in:
Jun Pataleta 2022-11-11 11:39:58 +08:00
commit 0b2cff48ed
5 changed files with 146 additions and 2 deletions

View file

@ -0,0 +1,77 @@
<?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_question\local\bank\column_base;
/**
* A column for info of the question modifier.
*
* @package qbank_viewcreator
* @copyright 2022 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class modifier_name_column extends column_base {
public function get_name(): string {
return 'modifiername';
}
public function get_title(): string {
return get_string('modifiedby', 'qbank_viewcreator');
}
protected function display_content($question, $rowclasses): void {
global $PAGE;
$displaydata = [];
if (!empty($question->modifierfirstname) && !empty($question->modifierlastname)) {
$u = new \stdClass();
$u = username_load_fields_from_object($u, $question, 'modifier');
$displaydata['date'] = userdate($question->timemodified, get_string('strftimedatetime', 'langconfig'));
$displaydata['creator'] = fullname($u);
echo $PAGE->get_renderer('qbank_viewcreator')->render_creator_name($displaydata);
}
}
public function get_extra_joins(): array {
return ['um' => 'LEFT JOIN {user} um ON um.id = q.modifiedby'];
}
public function get_required_fields(): array {
$allnames = \core_user\fields::get_name_fields();
$requiredfields = [];
foreach ($allnames as $allname) {
$requiredfields[] = 'um.' . $allname . ' AS modifier' . $allname;
}
$requiredfields[] = 'q.timemodified';
return $requiredfields;
}
public function is_sortable(): array {
return [
'firstname' => ['field' => 'um.firstname', 'title' => get_string('firstname')],
'lastname' => ['field' => 'um.lastname', 'title' => get_string('lastname')],
'timemodified' => ['field' => 'q.timemodified', 'title' => get_string('date')]
];
}
public function get_extra_classes(): array {
return ['pr-3'];
}
}

View file

@ -30,7 +30,8 @@ class plugin_feature extends plugin_features_base {
public function get_question_columns($qbank): array { public function get_question_columns($qbank): array {
return [ return [
new creator_name_column($qbank) new creator_name_column($qbank),
new modifier_name_column($qbank),
]; ];
} }
} }

View file

@ -23,6 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
$string['modifiedby'] = 'Modified by';
$string['pluginname'] = 'View creator'; $string['pluginname'] = 'View creator';
$string['privacy:metadata'] = 'The View creator question bank plugin does not store any personal data.'; $string['privacy:metadata'] = 'The View creator question bank plugin does not store any personal data.';
$string['version'] = 'Version {$a}'; $string['version'] = 'Version {$a}';

View file

@ -0,0 +1,65 @@
@qbank @qbank_viewcreator
Feature: Question bank Modified by column
In order to help keep track of the changes of the question version in the question bank
As a teacher
I need to know who modified the question and when the modification made in the question bank
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher1 | 1 | teacher1@example.com |
| teacher2 | Teacher2 | 2 | teacher2@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| teacher2 | C1 | editingteacher |
And the following "activities" exist:
| activity | name | course | idnumber |
| quiz | Test quiz | C1 | quiz1 |
And the following "question categories" exist:
| contextlevel | reference | name |
| Activity module | quiz1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | First question | Answer the first question |
@javascript
Scenario: Enable/disable modified by column from the base view
Given I log in as "admin"
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I should see "View creator"
When I click on "Disable" "link" in the "View creator" "table_row"
And I am on the "Test quiz" "mod_quiz > question bank" page
And I set the field "Select a category" to "Test questions"
Then I should not see "Modified by"
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "View creator" "table_row"
And I am on the "Test quiz" "mod_quiz > question bank" page
And I set the field "Select a category" to "Test questions"
Then I should see "Modified by"
@javascript
Scenario: Editing a question shows the modifier of the question
And I log in as "teacher1"
And I am on the "Test quiz" "mod_quiz > question bank" page
And I set the field "Select a category" to "Test questions"
And I should see "First question"
And I choose "Edit question" action for "First question" in the question bank
And I should see "Version 1"
And I set the field "id_name" to "Renamed question v2"
And I set the field "id_questiontext" to "edited question"
And I press "id_submitbutton"
And I should see "Teacher1"
And I log in as "teacher2"
And I am on the "Test quiz" "mod_quiz > question bank" page
And I set the field "Select a category" to "Test questions"
And I choose "Edit question" action for "Renamed question v2" in the question bank
Then I should see "Version 2"
And I set the field "id_name" to "Renamed question v3"
And I set the field "id_questiontext" to "edited question v3"
And I press "id_submitbutton"
And I should not see "Teacher1"
And I should see "Teacher2"

View file

@ -26,6 +26,6 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->component = 'qbank_viewcreator'; $plugin->component = 'qbank_viewcreator';
$plugin->version = 2022041900; $plugin->version = 2022080600;
$plugin->requires = 2022041200; $plugin->requires = 2022041200;
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;