require_capability('moodle/question:add', $categorycontext); // Ensure other optional params get passed on to question.php. if (!empty($returnurl)) { $hiddenparams['returnurl'] = $returnurl; } if (!empty($appendqnumstring)) { $hiddenparams['appendqnumstring'] = $appendqnumstring; } $PAGE->set_url('/question/addquestion.php', $hiddenparams); $chooseqtype = get_string('chooseqtypetoadd', 'question'); $PAGE->set_heading($COURSE->fullname); if ($cm !== null) { // Nasty hack, but we don't want this link if returnurl returns to view.php if (stripos($returnurl, "/mod/{$cm->modname}/view.php") !== 0) { $PAGE->navbar->add(get_string('editinga', 'moodle', get_string('modulename', $cm->modname)), $returnurl); } $PAGE->navbar->add($chooseqtype); $PAGE->set_title($chooseqtype); echo $OUTPUT->header(); } else { $PAGE->navbar->add(get_string('questionbank', 'question'), $returnurl); $PAGE->navbar->add($chooseqtype); $PAGE->set_title($chooseqtype); echo $OUTPUT->header(); } // Display a form to choose the question type. echo $OUTPUT->notification(get_string('youmustselectaqtype', 'question')); echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox'); print_choose_qtype_to_add_form($hiddenparams); echo $OUTPUT->box_end(); echo $OUTPUT->footer();
/** * Print a button for creating a new question. This will open question/addquestion.php, * which in turn goes to question/question.php before getting back to $params['returnurl'] * (by default the question bank screen). * * @param int $categoryid The id of the category that the new question should be added to. * @param array $params Other paramters to add to the URL. You need either $params['cmid'] or * $params['courseid'], and you should probably set $params['returnurl'] * @param string $caption the text to display on the button. * @param string $tooltip a tooltip to add to the button (optional). * @param bool $disabled if true, the button will be disabled. */ function create_new_question_button($categoryid, $params, $caption, $tooltip = '', $disabled = false) { global $CFG, $PAGE, $OUTPUT; static $choiceformprinted = false; $params['category'] = $categoryid; $url = new moodle_url('/question/addquestion.php', $params); echo $OUTPUT->single_button($url, $caption, 'get', array('disabled' => $disabled, 'title' => $tooltip)); if (!$choiceformprinted) { echo '<div id="qtypechoicecontainer">'; echo print_choose_qtype_to_add_form(array()); echo "</div>\n"; $choiceformprinted = true; } }
print_error('missingcourseorcmid', 'question'); } } // Check permissions. $categorycontext = context::instance_by_id($category->contextid); require_capability('moodle/question:add', $categorycontext); // Ensure other optional params get passed on to question.php. if (!empty($returnurl)) { $hiddenparams['returnurl'] = $returnurl; } if (!empty($appendqnumstring)) { $hiddenparams['appendqnumstring'] = $appendqnumstring; } $PAGE->set_url('/question/addquestion.php', $hiddenparams); if ($cmid) { $questionbankurl = new moodle_url('/question/edit.php', array('cmid' => $cmid)); } else { $questionbankurl = new moodle_url('/question/edit.php', array('courseid' => $courseid)); } navigation_node::override_active_url($questionbankurl); $chooseqtype = get_string('chooseqtypetoadd', 'question'); $PAGE->set_heading($COURSE->fullname); $PAGE->navbar->add($chooseqtype); $PAGE->set_title($chooseqtype); // Display a form to choose the question type. echo $OUTPUT->header(); echo $OUTPUT->notification(get_string('youmustselectaqtype', 'question')); echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox'); print_choose_qtype_to_add_form($hiddenparams, null, false); echo $OUTPUT->box_end(); echo $OUTPUT->footer();
/** * Render the question type chooser dialogue. * @return string HTML to output. */ public function question_chooser() { $container = html_writer::div(print_choose_qtype_to_add_form(array(), null, false), '', array('id' => 'qtypechoicecontainer')); return html_writer::div($container, 'createnewquestion'); }
/** * Print a button for creating a new question. This will open question/addquestion.php, * which in turn goes to question/question.php before getting back to $params['returnurl'] * (by default the question bank screen). * * @param integer $categoryid The id of the category that the new question should be added to. * @param array $params Other paramters to add to the URL. You need either $params['cmid'] or * $params['courseid'], and you should probably set $params['returnurl'] * @param string $caption the text to display on the button. * @param string $tooltip a tooltip to add to the button (optional). * @param boolean $disabled if true, the button will be disabled. */ function create_new_question_button($categoryid, $params, $caption, $tooltip = '', $disabled = false) { global $CFG; static $choiceformprinted = false; $params['category'] = $categoryid; print_single_button($CFG->wwwroot . '/question/addquestion.php', $params, $caption, 'get', '', false, $tooltip, $disabled); helpbutton('types', get_string('createnewquestion', 'question'), 'question'); require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_dragdrop', 'yui_container')); if (!$choiceformprinted) { echo '<div id="qtypechoicecontainer">'; print_choose_qtype_to_add_form(array()); echo "</div>\n"; $choiceformprinted = true; } }
/** * Print a button for creating a new question. This will open question/addquestion.php, * which in turn goes to question/question.php before getting back to $params['returnurl'] * (by default the question bank screen). * * @param integer $categoryid The id of the category that the new question should be added to. * @param array $params Other paramters to add to the URL. You need either $params['cmid'] or * $params['courseid'], and you should probably set $params['returnurl'] * @param string $caption the text to display on the button. * @param string $tooltip a tooltip to add to the button (optional). * @param boolean $disabled if true, the button will be disabled. */ function create_new_question_button($categoryid, $params, $caption, $tooltip = '', $disabled = false) { global $CFG, $PAGE, $OUTPUT; static $choiceformprinted = false; $params['category'] = $categoryid; $form = html_form::make_button($CFG->wwwroot . '/question/addquestion.php', $params, $caption, 'get'); $form->button->title = $tooltip; $form->button->disabled = $disabled; echo $OUTPUT->button($form); echo $OUTPUT->help_icon(moodle_help_icon::make('types', get_string('createnewquestion', 'question'), 'question')); $PAGE->requires->yui_lib('dragdrop'); $PAGE->requires->yui_lib('container'); if (!$choiceformprinted) { echo '<div id="qtypechoicecontainer">'; print_choose_qtype_to_add_form(array()); echo "</div>\n"; $choiceformprinted = true; } }