From 99231022af446812a68aa718a02b8c4c870812ea Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Mon, 15 Oct 2012 11:13:39 +0100 Subject: [PATCH 1/2] MDL-32245 question bank: fix moving categories between contexts. --- question/category.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/question/category.php b/question/category.php index 5ad3de94049..b3052cbce55 100644 --- a/question/category.php +++ b/question/category.php @@ -61,10 +61,17 @@ $qcobject = new question_category_object($pagevars['cpage'], $thispageurl, $cont $streditingcategories = get_string('editcategories', 'question'); if ($param->left || $param->right || $param->moveup || $param->movedown|| $param->moveupcontext || $param->movedowncontext){ require_sesskey(); - foreach ($qcobject->editlists as $list){ - //processing of these actions is handled in the method where appropriate and page redirects. - $list->process_actions($param->left, $param->right, $param->moveup, $param->movedown, - $param->moveupcontext, $param->movedowncontext, $param->tocontext); + + if ($param->moveupcontext || $param->movedowncontext) { + $catid = ($param->moveupcontext > 0) ? $param->moveupcontext : $param->movedowncontext; + $oldcat = $DB->get_record('question_categories', array('id' => $catid)); + $qcobject->update_category($catid, '0,'.$param->tocontext, $oldcat->name, $oldcat->info); + } else { + foreach ($qcobject->editlists as $list){ + //processing of these actions is handled in the method where appropriate and page redirects. + $list->process_actions($param->left, $param->right, $param->moveup, $param->movedown, + $param->moveupcontext, $param->movedowncontext, $param->tocontext); + } } } if ($param->delete && ($questionstomove = $DB->count_records("question", array("category" => $param->delete)))){ From c49b83bcccc4469a21ff83592d8624bef72f6ec3 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Wed, 12 Dec 2012 18:15:48 +0000 Subject: [PATCH 2/2] MDL-32245 question bank: fix coding style in categories.php --- question/category.php | 48 +++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/question/category.php b/question/category.php index b3052cbce55..596abddab2d 100644 --- a/question/category.php +++ b/question/category.php @@ -31,7 +31,7 @@ require_once($CFG->dirroot."/question/category_class.php"); list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('categories', '/question/category.php'); -// get values from form for actions on this page +// Get values from form for actions on this page. $param = new stdClass(); $param->moveup = optional_param('moveup', 0, PARAM_INT); $param->movedown = optional_param('movedown', 0, PARAM_INT); @@ -55,26 +55,33 @@ foreach ((array)$param as $key=>$value) { } $PAGE->set_url($url); -$qcobject = new question_category_object($pagevars['cpage'], $thispageurl, $contexts->having_one_edit_tab_cap('categories'), $param->edit, $pagevars['cat'], $param->delete, - $contexts->having_cap('moodle/question:add')); +$qcobject = new question_category_object($pagevars['cpage'], $thispageurl, + $contexts->having_one_edit_tab_cap('categories'), $param->edit, + $pagevars['cat'], $param->delete, $contexts->having_cap('moodle/question:add')); -$streditingcategories = get_string('editcategories', 'question'); -if ($param->left || $param->right || $param->moveup || $param->movedown|| $param->moveupcontext || $param->movedowncontext){ +if ($param->left || $param->right || $param->moveup || $param->movedown) { require_sesskey(); - if ($param->moveupcontext || $param->movedowncontext) { - $catid = ($param->moveupcontext > 0) ? $param->moveupcontext : $param->movedowncontext; - $oldcat = $DB->get_record('question_categories', array('id' => $catid)); - $qcobject->update_category($catid, '0,'.$param->tocontext, $oldcat->name, $oldcat->info); - } else { - foreach ($qcobject->editlists as $list){ - //processing of these actions is handled in the method where appropriate and page redirects. - $list->process_actions($param->left, $param->right, $param->moveup, $param->movedown, - $param->moveupcontext, $param->movedowncontext, $param->tocontext); - } + foreach ($qcobject->editlists as $list) { + // Processing of these actions is handled in the method where appropriate and page redirects. + $list->process_actions($param->left, $param->right, $param->moveup, $param->movedown); } } -if ($param->delete && ($questionstomove = $DB->count_records("question", array("category" => $param->delete)))){ + +if ($param->moveupcontext || $param->movedowncontext) { + require_sesskey(); + + if ($param->moveupcontext) { + $catid = $param->moveupcontext; + } else { + $catid = $param->movedowncontext; + } + $oldcat = $DB->get_record('question_categories', array('id' => $catid), '*', MUST_EXIST); + $qcobject->update_category($catid, '0,'.$param->tocontext, $oldcat->name, $oldcat->info); + // The previous line does a redirect(). +} + +if ($param->delete && ($questionstomove = $DB->count_records("question", array("category" => $param->delete)))) { if (!$category = $DB->get_record("question_categories", array("id" => $param->delete))) { // security print_error('nocate', 'question', $thispageurl->out(), $param->delete); } @@ -93,6 +100,7 @@ if ($param->delete && ($questionstomove = $DB->count_records("question", array(" } else { $questionstomove = 0; } + if ($qcobject->catform->is_cancelled()) { redirect($thispageurl); } else if ($catformdata = $qcobject->catform->get_data()) { @@ -108,21 +116,21 @@ if ($qcobject->catform->is_cancelled()) { redirect($thispageurl); } -if ($param->edit){ +if ($param->edit) { $PAGE->navbar->add(get_string('editingcategory', 'question')); } -$PAGE->set_title($streditingcategories); +$PAGE->set_title(get_string('editcategories', 'question')); $PAGE->set_heading($COURSE->fullname); echo $OUTPUT->header(); -// display UI +// Display the UI. if (!empty($param->edit)) { $qcobject->edit_single_category($param->edit); } else if ($questionstomove){ $qcobject->display_move_form($questionstomove, $category); } else { - // display the user interface + // Display the user interface. $qcobject->display_user_interface(); } echo $OUTPUT->footer();