diff --git a/question/bank/viewcreator/classes/modifier_name_column.php b/question/bank/viewcreator/classes/modifier_name_column.php new file mode 100644 index 00000000000..70a4f93bc9b --- /dev/null +++ b/question/bank/viewcreator/classes/modifier_name_column.php @@ -0,0 +1,77 @@ +. + +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 + * @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']; + } + +} diff --git a/question/bank/viewcreator/classes/plugin_feature.php b/question/bank/viewcreator/classes/plugin_feature.php index a5e0185aab9..850b1c5e746 100644 --- a/question/bank/viewcreator/classes/plugin_feature.php +++ b/question/bank/viewcreator/classes/plugin_feature.php @@ -30,7 +30,8 @@ class plugin_feature extends plugin_features_base { public function get_question_columns($qbank): array { return [ - new creator_name_column($qbank) + new creator_name_column($qbank), + new modifier_name_column($qbank), ]; } } diff --git a/question/bank/viewcreator/lang/en/qbank_viewcreator.php b/question/bank/viewcreator/lang/en/qbank_viewcreator.php index e39adae06fd..8fded1983d6 100644 --- a/question/bank/viewcreator/lang/en/qbank_viewcreator.php +++ b/question/bank/viewcreator/lang/en/qbank_viewcreator.php @@ -23,6 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['modifiedby'] = 'Modified by'; $string['pluginname'] = 'View creator'; $string['privacy:metadata'] = 'The View creator question bank plugin does not store any personal data.'; $string['version'] = 'Version {$a}'; diff --git a/question/bank/viewcreator/tests/behat/modified_by_column.feature b/question/bank/viewcreator/tests/behat/modified_by_column.feature new file mode 100644 index 00000000000..f478aa63f80 --- /dev/null +++ b/question/bank/viewcreator/tests/behat/modified_by_column.feature @@ -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" diff --git a/question/bank/viewcreator/version.php b/question/bank/viewcreator/version.php index 343e1d0fb5e..7e47f71e7f7 100644 --- a/question/bank/viewcreator/version.php +++ b/question/bank/viewcreator/version.php @@ -26,6 +26,6 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'qbank_viewcreator'; -$plugin->version = 2022041900; +$plugin->version = 2022080600; $plugin->requires = 2022041200; $plugin->maturity = MATURITY_STABLE;