From a982d582c4f5918cf5b1c1c10961a0dba74873c5 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Wed, 25 Apr 2007 14:06:37 +0000 Subject: [PATCH] Added redirects after all actions. Added methods to category class to generate a url from an array of parameters stored in the object. Cleaned up some old redundant code for actions now processed in list class. --- question/category.php | 2 - question/category_class.php | 129 ++++++++++++++++-------------------- 2 files changed, 58 insertions(+), 73 deletions(-) diff --git a/question/category.php b/question/category.php index 761127340c..5a89f0bec2 100644 --- a/question/category.php +++ b/question/category.php @@ -79,8 +79,6 @@ } } else if (!empty($param->hide)) { $qcobject->publish_category(false, $param->hide); - } else if (!empty($param->move)) { - $qcobject->move_category($param->move, $param->moveto); } else if (!empty($param->publish)) { $qcobject->publish_category(true, $param->publish); } else if (!empty($param->addcategory)) { diff --git a/question/category_class.php b/question/category_class.php index 566df1f44d..9eb424041b 100644 --- a/question/category_class.php +++ b/question/category_class.php @@ -104,6 +104,9 @@ class question_category_object { var $categories; var $categorystrings; var $defaultcategory; +//------------------------------------------------------ + var $pageurl; + var $pageparams = array(); /** * Constructor @@ -139,12 +142,60 @@ class question_category_object { $this->pixpath = $CFG->pixpath; $this->editlist = new question_category_list('ul', '', true, $page); - $this->editlist->add_page_params(array('id'=>$COURSE->id)); + + $this->add_page_params(array('id'=>$COURSE->id)); + $this->pageurl = strip_querystring(qualified_me());//default + $this->initialize(); } + + /** + * Add an array of params to the params for this page. + * + * @param unknown_type $params + */ + function add_page_params($params){ + $this->pageparams = $params + $this->pageparams; + $this->editlist->add_page_params($params); + } + + /** + * Get url and query string for an action on this page (get_url() + sesskey) + * + * @param array $overrideparams an array of params which override $this->pageparams + * @return string + */ + function get_action_url($overrideparams = array()){ + global $USER; + $arr = array(); + $paramarray = $overrideparams + $this->pageparams + array('sesskey'=>$USER->sesskey); + foreach ($paramarray as $key => $val){ + $arr[] = urlencode($key)."=".urlencode($val); + } + $params = implode($arr, "&"); + return $this->pageurl.'?'.$params; + } + + /** + * Get url and query string for this page + * + * @param array $overrideparams an array of params which override $this->pageparams + * @return string + */ + function get_url($overrideparams = array()){ + + $arr = array(); + $paramarray = $overrideparams + $this->pageparams; + foreach ($paramarray as $key => $val){ + $arr[] = urlencode($key)."=".urlencode($val); + } + $params = implode($arr, "&"); + + return $this->pageurl.'?'.$params; + } /** * Displays the user interface @@ -483,80 +534,11 @@ class question_category_object { /// Finally delete the category itself if (delete_records("question_categories", "id", $category->id)) { notify(get_string("categorydeleted", "quiz", format_string($category->name)), 'notifysuccess'); + redirect($this->get_url());//always redirect after successful action } } - /** - * Moves a category up or down in the display order - * - * @param string direction up|down - * @param int categoryid id of category to move - */ - function move_category_up_down ($direction, $categoryid) { - /// Move a category up or down - $swapcategory = NULL; - $movecategory = NULL; - - if ($direction == 'up') { - if ($movecategory = get_record("question_categories", "id", $categoryid)) { - $categories = $this->get_question_categories("$movecategory->parent", 'parent, sortorder, name'); - - foreach ($categories as $category) { - if ($category->id == $movecategory->id) { - break; - } - $swapcategory = $category; - } - } - } - if ($direction == 'down') { - if ($movecategory = get_record("question_categories", "id", $categoryid)) { - $categories = $this->get_question_categories("$movecategory->parent", 'parent, sortorder, name'); - $choosenext = false; - foreach ($categories as $category) { - if ($choosenext) { - $swapcategory = $category; - break; - } - if ($category->id == $movecategory->id) { - $choosenext = true; - } - } - } - } - if ($swapcategory and $movecategory) { // Renumber everything for robustness - $count=0; - foreach ($categories as $category) { - $count++; - if ($category->id == $swapcategory->id) { - $category = $movecategory; - } else if ($category->id == $movecategory->id) { - $category = $swapcategory; - } - if (! set_field("question_categories", "sortorder", $count, "id", $category->id)) { - notify("Could not update that category!"); - } - } - } - } - - /** - * Changes the parent of a category - * - * @param int categoryid - * @param int parentid - */ - function move_category($categoryid, $parentid) { - /// Move a category to a new parent - if ($tempcat = get_record("question_categories", "id", $categoryid)) { - if ($tempcat->parent != $parentid) { - if (! set_field("question_categories", "parent", $parentid, "id", $tempcat->id)) { - notify("Could not update that category!"); - } - } - } - } /** * Changes the published status of a category @@ -572,7 +554,10 @@ class question_category_object { if ($tempcat) { if (! set_field("question_categories", "publish", $publish, "id", $tempcat->id)) { notify("Could not update that category!"); + } else { + redirect($this->get_url());//always redirect after successful action } + } } @@ -610,6 +595,7 @@ class question_category_object { error("Could not insert the new question category '$newcategory'", "category.php?id={$newcourse}"); } else { notify(get_string("categoryadded", "quiz", $newcategory), 'notifysuccess'); + redirect($this->get_url());//always redirect after successful action } } @@ -639,6 +625,7 @@ class question_category_object { error("Could not update the category '$updatename'", "category.php?id={$courseid}"); } else { notify(get_string("categoryupdated", 'quiz'), 'notifysuccess'); + redirect($this->get_url()); } } } -- 2.39.5