From 3e27d19008249b35bf865dcf8e4b9c568ae77099 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 2 Oct 2014 21:45:15 +0100 Subject: [PATCH 1/2] MDL-28075 question editing: sort out nav bar when editing in a quiz If you edited a question from the Edit quiz page in a quiz, the navigation bar was far too long. This was due to some odd code that was trying too hard to be clever. Instead, editing a question is now always treated as being logically within the question bank for the purposes of navigation. That is, even if the returnurl will end up taking you back to where you where when you have finished. --- question/addquestion.php | 25 +++++++++---------------- question/question.php | 31 ++++++++++--------------------- 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/question/addquestion.php b/question/addquestion.php index 02e6224280a..1861439bf84 100644 --- a/question/addquestion.php +++ b/question/addquestion.php @@ -72,29 +72,22 @@ if (!empty($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); -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(); -} +$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); echo $OUTPUT->box_end(); - echo $OUTPUT->footer(); - diff --git a/question/question.php b/question/question.php index 7577dc28fec..d4aa30f83fb 100644 --- a/question/question.php +++ b/question/question.php @@ -79,15 +79,20 @@ if ($scrollpos) { } $PAGE->set_url($url); +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); + if ($originalreturnurl) { if (strpos($originalreturnurl, '/') !== 0) { throw new coding_exception("returnurl must be a local URL starting with '/'. $originalreturnurl was given."); } $returnurl = new moodle_url($originalreturnurl); -} else if ($cmid) { - $returnurl = new moodle_url('/question/edit.php', array('cmid' => $cmid)); } else { - $returnurl = new moodle_url('/question/edit.php', array('courseid' => $courseid)); + $returnurl = $questionbankurl; } if ($scrollpos) { $returnurl->param('scrollpos', $scrollpos); @@ -322,27 +327,11 @@ if ($mform->is_cancelled()) { $streditingquestion = $qtypeobj->get_heading(); $PAGE->set_title($streditingquestion); $PAGE->set_heading($COURSE->fullname); - if ($cm !== null) { - $strmodule = get_string('modulename', $cm->modname); - $streditingmodule = get_string('editinga', 'moodle', $strmodule); - $PAGE->navbar->add(get_string('modulenameplural', $cm->modname), new moodle_url('/mod/'.$cm->modname.'/index.php', array('id'=>$cm->course))); - $PAGE->navbar->add(format_string($module->name), new moodle_url('/mod/'.$cm->modname.'/view.php', array('id'=>$cm->id))); - if (stripos($returnurl, "$CFG->wwwroot/mod/{$cm->modname}/view.php")!== 0){ - //don't need this link if returnurl returns to view.php - $PAGE->navbar->add($streditingmodule, $returnurl); - } - $PAGE->navbar->add($streditingquestion); - echo $OUTPUT->header(); - - } else { - $strediting = ''.get_string('editquestions', 'question').' -> '.$streditingquestion; - $PAGE->navbar->add(get_string('editquestions', 'question'), $returnurl); - $PAGE->navbar->add($streditingquestion); - echo $OUTPUT->header(); - } + $PAGE->navbar->add($streditingquestion); // Display a heading, question editing form and possibly some extra content needed for // for this question type. + echo $OUTPUT->header(); $qtypeobj->display_question_editing_page($mform, $question, $wizardnow); echo $OUTPUT->footer(); } From f4016690450bc496547fb8b554540c1bf3f6253b Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 2 Oct 2014 21:48:40 +0100 Subject: [PATCH 2/2] MDL-28075 question editing: tidy code Remove an unnecessary else (the if, and else if, always end in a redirect) and unindent that code. --- question/question.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/question/question.php b/question/question.php index d4aa30f83fb..d41a565561b 100644 --- a/question/question.php +++ b/question/question.php @@ -323,15 +323,15 @@ if ($mform->is_cancelled()) { redirect($nexturl); } -} else { - $streditingquestion = $qtypeobj->get_heading(); - $PAGE->set_title($streditingquestion); - $PAGE->set_heading($COURSE->fullname); - $PAGE->navbar->add($streditingquestion); - - // Display a heading, question editing form and possibly some extra content needed for - // for this question type. - echo $OUTPUT->header(); - $qtypeobj->display_question_editing_page($mform, $question, $wizardnow); - echo $OUTPUT->footer(); } + +$streditingquestion = $qtypeobj->get_heading(); +$PAGE->set_title($streditingquestion); +$PAGE->set_heading($COURSE->fullname); +$PAGE->navbar->add($streditingquestion); + +// Display a heading, question editing form and possibly some extra content needed for +// for this question type. +echo $OUTPUT->header(); +$qtypeobj->display_question_editing_page($mform, $question, $wizardnow); +echo $OUTPUT->footer();