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" } ] } }}