MDL-61514 Quiz: Display unavailable tags when editing random questions

When editing a random question, the form will display the tags that the random question
is configured to get questions from even if those tags do not exist anymore.
This commit is contained in:
Shamim Rezaie
2018-03-12 13:40:20 +11:00
parent fb5343a00c
commit c907987844
2 changed files with 17 additions and 0 deletions
@@ -81,4 +81,20 @@ class randomquestion_form extends \moodleform {
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->closeHeaderBefore('buttonar');
}
public function set_data($defaultvalues) {
$mform = $this->_form;
if ($defaultvalues->fromtags) {
$fromtagselement = $mform->getElement('fromtags');
foreach ($defaultvalues->fromtags as $fromtag) {
if (!$fromtagselement->optionExists($fromtag)) {
$optionname = get_string('randomfromunavailabletag', 'mod_quiz', explode(',', $fromtag)[1]);
$fromtagselement->addOption($optionname, $fromtag);
}
}
}
parent::set_data($defaultvalues);
}
}
+1
View File
@@ -700,6 +700,7 @@ $string['randomcreate'] = 'Create random questions';
$string['randomediting'] = 'Editing a random question';
$string['randomfromcategory'] = 'Random question from category:';
$string['randomfromexistingcategory'] = 'Random question from an existing category';
$string['randomfromunavailabletag'] = '{$a} (unavailable)';
$string['randomnumber'] = 'Number of random questions';
$string['randomnosubcat'] = 'Questions from this category only, not its subcategories.';
$string['randomquestion'] = 'Random question';