diff --git a/question/bank/history/tests/behat/question_history_action.feature b/question/bank/history/tests/behat/question_history_action.feature index d6ecf6b3b0b..5ef7bf260ee 100644 --- a/question/bank/history/tests/behat/question_history_action.feature +++ b/question/bank/history/tests/behat/question_history_action.feature @@ -7,14 +7,19 @@ Feature: Use the qbank plugin manager page for question history | fullname | shortname | category | | Course 1 | C1 | 0 | And the following "activities" exist: - | activity | name | course | idnumber | - | quiz | Test quiz | C1 | quiz1 | + | activity | name | intro | course | idnumber | + | quiz | Test quiz | | C1 | quiz1 | + | qbank | Qbank 1 | Question bank 1 | C1 | qbank1 | + | qbank | Qbank 2 | Question bank 2 | C1 | qbank2 | And the following "question categories" exist: - | contextlevel | reference | name | - | Activity module | quiz1 | Test questions | + | contextlevel | reference | name | + | Activity module | quiz1 | Test questions | + | Activity module | qbank1 | Share questions | + | Activity module | qbank2 | Share questions 2 | And the following "questions" exist: - | questioncategory | qtype | name | questiontext | - | Test questions | truefalse | First question | Answer the first question | + | questioncategory | qtype | name | questiontext | + | Test questions | truefalse | First question | Answer the first question | + | Share questions | essay | Test question to be edited | Write about whatever you want | Scenario: Enable/disable question history column from the base view Given I log in as "admin" @@ -43,7 +48,7 @@ Feature: Use the qbank plugin manager page for question history Scenario: Viewing history for a question in a non-default category Given the following "question categories" exist: | contextlevel | reference | name | - | Activity module | quiz1 | Test questions 2 | + | Activity module | quiz1 | Test questions 2 | And the following "questions" exist: | questioncategory | qtype | name | questiontext | | Test questions 2 | truefalse | Second question | Answer the second question | @@ -109,3 +114,12 @@ Feature: Use the qbank plugin manager page for question history And "Last used" "qbank_columnsortorder > column header" should exist And "First question" "table_row" should exist And "Second question" "table_row" should not exist + + Scenario: Go History page in edit question page. + Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "admin" + When I choose "Edit question" action for "First question" in the question bank + And I click on "History" "link" + Then I should see "First question" + And I follow "Close" + And the following fields match these values: + | Question text | Answer the first question | diff --git a/question/bank/viewcreator/deprecated.txt b/question/bank/viewcreator/deprecated.txt new file mode 100644 index 00000000000..a414b44f86c --- /dev/null +++ b/question/bank/viewcreator/deprecated.txt @@ -0,0 +1 @@ +version,qbank_viewcreator diff --git a/question/bank/viewcreator/lang/en/qbank_viewcreator.php b/question/bank/viewcreator/lang/en/qbank_viewcreator.php index accadaeab4a..acb17bee976 100644 --- a/question/bank/viewcreator/lang/en/qbank_viewcreator.php +++ b/question/bank/viewcreator/lang/en/qbank_viewcreator.php @@ -23,8 +23,11 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['history'] = 'History'; $string['modifiedby'] = 'Modified by'; $string['timemodified'] = 'Time modified'; $string['pluginname'] = 'View creator'; $string['privacy:metadata'] = 'The View creator question bank plugin does not store any personal data.'; + +// Deprecated since Moodle 4.5. $string['version'] = 'Version {$a}'; diff --git a/question/bank/viewcreator/lib.php b/question/bank/viewcreator/lib.php index 68b83ca1944..c54c25b1a99 100644 --- a/question/bank/viewcreator/lib.php +++ b/question/bank/viewcreator/lib.php @@ -30,10 +30,35 @@ * @return string */ function qbank_viewcreator_edit_form_display($question): string { - global $DB, $PAGE; + global $DB, $PAGE, $OUTPUT; + $question = question_bank::load_question($question->id); + $versiondata = []; - $questionversion = $DB->get_record('question_versions', ['questionid' => $question->id])->version; - $versiondata['versionnumber'] = $questionversion; + $versioninfo = new \core_question\output\question_version_info($question, true); + $versiondata['versionnumber'] = $versioninfo->export_for_template($OUTPUT)['versioninfo']; + + // Currently the history only display the question versions for just only default category. + // To display question in the other category. + // So we need to add filter param so that we can display the question in different category. + $filterparam = json_encode([ + 'category' => [ + 'jointype' => 1, + 'values' => [$question->category], + 'filteroptions' => ['includesubcategories' => false], + ], + ]); + // We need a return url param so that click close button on history page should redirect back to edit question page. + // Set params filter to returnurl so that when we use the move feature It will not cause any error. + $returnurl = $PAGE->url; + $returnurl->param('filter', $filterparam); + $versiondata['historyurl'] = new moodle_url('/question/bank/history/history.php', [ + 'entryid' => $question->questionbankentryid, + 'returnurl' => $returnurl, + 'courseid' => $PAGE->course->id, + 'filter' => $filterparam, + 'cmid' => $PAGE->url->param('cmid'), + ]); + if (!empty($question->createdby)) { $a = new stdClass(); $a->time = userdate($question->timecreated); diff --git a/question/bank/viewcreator/templates/version_info.mustache b/question/bank/viewcreator/templates/version_info.mustache index 3898c4feb6f..00bdd32028f 100644 --- a/question/bank/viewcreator/templates/version_info.mustache +++ b/question/bank/viewcreator/templates/version_info.mustache @@ -22,16 +22,17 @@ "addquestiondata": [ { "versionnumber": 1, + "historyurl": "www.example.com/question/bank/history/history.php", "createdby": "Admin User on Wednesday, 20 October 2021, 5:33 AM" } ] } }}
- {{#str}} version, qbank_viewcreator, {{versionnumber}} {{/str}} + {{versionnumber}}. {{#pix}} t/log, core {{/pix}} {{#str}}history, qbank_viewcreator{{/str}}
{{#createdby}}
- {{{createdby}}} + {{{createdby}}}
{{/createdby}} diff --git a/question/bank/viewcreator/tests/behat/modified_by_column.feature b/question/bank/viewcreator/tests/behat/modified_by_column.feature index abefc6e49c3..130e503f467 100644 --- a/question/bank/viewcreator/tests/behat/modified_by_column.feature +++ b/question/bank/viewcreator/tests/behat/modified_by_column.feature @@ -54,7 +54,8 @@ Feature: Question bank Modified by column And I press "Apply filters" 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 "History" "link" should exist + And I should see "v1 (latest)" 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" @@ -65,7 +66,7 @@ Feature: Question bank Modified by column And I set the field "Category" to "Test questions" And I press "Apply filters" And I choose "Edit question" action for "Renamed question v2" in the question bank - Then I should see "Version 2" + Then I should see "v2 (latest)" 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" diff --git a/question/tests/behat/edit_question_versioning.feature b/question/tests/behat/edit_question_versioning.feature index 9717cf6b1cb..0f6d94be62f 100644 --- a/question/tests/behat/edit_question_versioning.feature +++ b/question/tests/behat/edit_question_versioning.feature @@ -31,18 +31,18 @@ Feature: Questions in the question bank have versions Scenario: Question version is displayed Given I am on the "Quiz 1" "mod_quiz > question bank" page logged in as "teacher1" When I choose "Edit question" action for "First question" in the question bank - Then I should see "Version 1" + Then I should see "v1 (latest)" @javascript Scenario: Question version change when question is altered Given I am on the "Quiz 1" "mod_quiz > question bank" page logged in as "teacher1" When I choose "Edit question" action for "First question" in the question bank - And I should see "Version 1" + And I should see "v1 (latest)" When 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" Then I should not see "First question" And I should see "Renamed question v2" When I choose "Edit question" action for "Renamed question v2" in the question bank - Then I should see "Version 2" - And I should not see "Version 1" + Then I should see "v2 (latest)" + And I should not see "v1 (latest)"