Skip to content

Commit

Permalink
MDL-71696 qbank_preview: previewquestion plugin update
Browse files Browse the repository at this point in the history
This commit implements versioning and associated features
in the previewquestion plugin. There have been some major
changes in the random question and version selection for
questions. This commit made those changes as well as added
some more features in the preview for version selection
and adds more behat coverage.
  • Loading branch information
marcghaly authored and safatshahin committed Feb 3, 2022
1 parent 111951d commit b1ad75a
Show file tree
Hide file tree
Showing 23 changed files with 281 additions and 121 deletions.
10 changes: 9 additions & 1 deletion lib/questionlib.php
Expand Up @@ -1117,7 +1117,15 @@ function question_sort_tags($tagobjects, $categorycontext, $filtercourses = null
*/
function print_question_icon($question): string {
global $PAGE;
return $PAGE->get_renderer('question', 'bank')->qtype_icon($question->qtype);

if (gettype($question->qtype) == 'object') {
$qtype = $question->qtype->name();
} else {
// Assume string.
$qtype = $question->qtype;
}

return $PAGE->get_renderer('question', 'bank')->qtype_icon($qtype);
}

// CATEGORY FUNCTIONS.
Expand Down
1 change: 1 addition & 0 deletions mod/quiz/classes/output/edit_renderer.php
Expand Up @@ -28,6 +28,7 @@
use mod_quiz\question\bank\qbank_helper;
use \mod_quiz\structure;
use \html_writer;
use \qbank_previewquestion\helper;
use renderable;

/**
Expand Down
4 changes: 3 additions & 1 deletion mod/quiz/locallib.php
Expand Up @@ -1361,6 +1361,7 @@ function quiz_attempt_state_name($state) {
* @param object $question the question.
* @param string $returnurl url to return to after action is done.
* @param int $variant which question variant to preview (optional).
* @param bool $random if question is random, true.
* @return string html for a number of icons linked to action pages for a
* question - preview and edit / view icons depending on user capabilities.
*/
Expand Down Expand Up @@ -1448,9 +1449,10 @@ function quiz_question_preview_url($quiz, $question, $variant = null) {
* @param object $question the question
* @param bool $label if true, show the preview question label after the icon
* @param int $variant which question variant to preview (optional).
* @param bool $random if question is random, true.
* @return the HTML for a preview question icon.
*/
function quiz_question_preview_button($quiz, $question, $label = false, $variant = null) {
function quiz_question_preview_button($quiz, $question, $label = false, $variant = null, $random = null) {
global $PAGE;
if (!question_has_capability_on($question, 'use')) {
return '';
Expand Down
6 changes: 5 additions & 1 deletion mod/quiz/report/statistics/statistics_table.php
Expand Up @@ -202,8 +202,12 @@ protected function col_actions($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
return '';
} else {
$random = null;
if ($questionstat->question->qtype === 'random') {
$random = true;
}
return quiz_question_action_icons($this->quiz, $this->cmid,
$questionstat->question, $this->baseurl, $questionstat->variant);
$questionstat->question, $this->baseurl, $questionstat->variant, $random);
}
}

Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/report/statistics/tests/behat/basic.feature
Expand Up @@ -59,7 +59,7 @@ Feature: Basic use of the Statistics report
| 1 | False |
| 2 | False |
| 3 | False |
And I press "Go back"
And I am on the "Quiz 1" "quiz activity" page logged in as teacher1
And I navigate to "Results > Statistics" in current page administration
And I press "Show report"
Then I should not see "No questions have been attempted yet"
Expand Down
2 changes: 1 addition & 1 deletion question/bank/previewquestion/amd/build/preview.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion question/bank/previewquestion/amd/build/preview.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions question/bank/previewquestion/amd/src/preview.js
Expand Up @@ -29,12 +29,17 @@ import $ from 'jquery';
*
* @method init
* @param {bool} redirect Redirect.
* @param {string} url url to redirect.
*/
export const init = (redirect) => {
export const init = (redirect, url) => {
if (!redirect) {
let closeButton = document.getElementById('close-previewquestion-page');
closeButton.onclick = () => {
window.close();
if (window.opener === null) {
location.href = url;
} else {
window.close();
}
};
}
// Set up the form to be displayed.
Expand Down
Expand Up @@ -42,8 +42,12 @@ public function definition() {
question_display_options::VISIBLE => get_string('shown', 'question'),
];

$mform->addElement('header', 'attemptoptionsheader', get_string('attemptoptions', 'question'));

$mform->addElement('header', 'attemptoptionsheader', get_string('previewoptions', 'qbank_previewquestion'));
$mform->setExpanded('attemptoptionsheader', false);
$versions = $this->_customdata['versions'];
$currentversion = $this->_customdata['questionversion'];
$select = $mform->addElement('select', 'version', get_string('questionversion', 'qbank_previewquestion'), $versions);
$select->setSelected($currentversion);
$behaviours = question_engine::get_behaviour_options(
$this->_customdata['quba']->get_preferred_behaviour());
$mform->addElement('select', 'behaviour',
Expand All @@ -63,6 +67,7 @@ public function definition() {
get_string('restartwiththeseoptions', 'question'));

$mform->addElement('header', 'displayoptionsheader', get_string('displayoptions', 'question'));
$mform->setExpanded('displayoptionsheader', false);

$mform->addElement('select', 'correctness', get_string('whethercorrect', 'question'),
$hiddenorvisible);
Expand Down

0 comments on commit b1ad75a

Please sign in to comment.