MDL-61132 Quiz: "Random" question from "Top" categories

* Support for adding ranodm questions from "Top" categories
This commit is contained in:
Shamim Rezaie 2018-01-30 13:46:39 +11:00
parent 9275220de3
commit 3b8f3198de
6 changed files with 68 additions and 7 deletions

View file

@ -85,6 +85,10 @@ if ($data = $mform->get_data()) {
if (!empty($data->existingcategory)) {
list($categoryid) = explode(',', $data->category);
$includesubcategories = !empty($data->includesubcategories);
if (!$includesubcategories) {
// If the chosen category is a top category.
$includesubcategories = $DB->record_exists('question_categories', ['id' => $categoryid, 'parent' => 0]);
}
$returnurl->param('cat', $data->category);
} else if (!empty($data->newcategory)) {

View file

@ -37,7 +37,6 @@ require_once($CFG->libdir.'/formslib.php');
class quiz_add_random_form extends moodleform {
protected function definition() {
global $CFG, $DB;
$mform =& $this->_form;
$mform->setDisableShortforms();
@ -49,11 +48,14 @@ class quiz_add_random_form extends moodleform {
get_string('randomfromexistingcategory', 'quiz'));
$mform->addElement('questioncategory', 'category', get_string('category'),
array('contexts' => $usablecontexts, 'top' => false));
array('contexts' => $usablecontexts, 'top' => true));
$mform->setDefault('category', $this->_customdata['cat']);
$mform->addElement('checkbox', 'includesubcategories', '', get_string('recurse', 'quiz'));
$tops = question_get_top_categories_for_contexts(array_column($contexts->all(), 'id'));
$mform->hideIf('includesubcategories', 'category', 'in', $tops);
$mform->addElement('select', 'numbertoadd', get_string('randomnumber', 'quiz'),
$this->get_number_of_questions_to_add_choices());