print_error('invalidgroupnumber', 'offlinequiz'); } if ($returnurl) { $returnurl = new moodle_url($returnurl); } else { $returnurl = new moodle_url('/mod/offlinequiz/edit.php', array('cmid' => $cmid, 'groupnumber' => $offlinequiz->groupnumber)); } if ($scrollpos) { $returnurl->param('scrollpos', $scrollpos); } $thispageurl->param('groupnumber', $offlinequiz->groupnumber); $PAGE->set_url($thispageurl); $defaultcategoryobj = question_make_default_categories($contexts->all()); $defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid; $qcobject = new question_category_object($pagevars['cpage'], $thispageurl, $contexts->having_one_edit_tab_cap('categories'), $defaultcategoryobj->id, $defaultcategory, null, $contexts->having_cap('moodle/question:add')); $mform = new offlinequiz_add_random_form(new moodle_url('/mod/offlinequiz/addrandom.php'), array('contexts' => $contexts, 'cat' => $pagevars['cat'], 'groupnumber' => $offlinequiz->groupnumber)); if ($mform->is_cancelled()) { redirect($returnurl); } if ($data = $mform->get_data()) { if (!empty($data->existingcategory)) { list($categoryid) = explode(',', $data->category); $includesubcategories = !empty($data->includesubcategories); $returnurl->param('cat', $data->category); } else { if (!empty($data->newcategory)) { list($parentid, $contextid) = explode(',', $data->parent); $categoryid = $qcobject->add_category($data->parent, $data->name, '', true); $includesubcategories = 0; $returnurl->param('cat', $categoryid . ',' . $contextid); } else {
/** * Return random question form. * @param \moodle_url $thispageurl the canonical URL of this page. * @param \question_edit_contexts $contexts the relevant question bank contexts. * @param array $pagevars the variables from {@link \question_edit_setup()}. * @return string HTML to output. */ protected function random_question_form(\moodle_url $thispageurl, \question_edit_contexts $contexts, array $pagevars) { if (!$contexts->have_cap('moodle/question:useall')) { return ''; } $randomform = new \offlinequiz_add_random_form(new \moodle_url('/mod/offlinequiz/addrandom.php'), array('contexts' => $contexts, 'cat' => $pagevars['cat'], 'groupnumber' => $thispageurl->get_param('groupnumber'))); $randomform->set_data(array('category' => $pagevars['cat'], 'returnurl' => $thispageurl->out_as_local_url(true), 'randomnumber' => 1, 'cmid' => $thispageurl->param('cmid'))); return html_writer::div($randomform->render(), 'randomquestionformforpopup'); }