From 986effb653b7f4d1958de36d55b984974a348898 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Mon, 7 May 2007 05:53:20 +0000 Subject: [PATCH] pass the category list page param from page to page in question bank editing pages. --- lib/listlib.php | 7 ++- question/category.php | 6 +- question/category_class.php | 108 ++++++++++-------------------------- question/editlib.php | 7 +++ 4 files changed, 41 insertions(+), 87 deletions(-) diff --git a/lib/listlib.php b/lib/listlib.php index 7f6994f6c9..5d8bc55c56 100644 --- a/lib/listlib.php +++ b/lib/listlib.php @@ -109,10 +109,11 @@ class moodle_list{ if ($pageurl === null){ $this->pageurl = new moodle_url(); + $this->pageurl->params(array($this->pageparamname => $this->page)); } else { $this->pageurl = $pageurl; } - $this->pageurl->params(array($this->pageparamname => $this->page)); + } /** @@ -244,7 +245,7 @@ class moodle_list{ */ function display_page_numbers() { if (!empty($this->page) && ($this->pagecount>1)){ - echo "
".get_string($this->pageparamname).":\n"; + echo "
".get_string('page').":\n"; foreach (range(1,$this->pagecount) as $currentpage) { if ($this->page == $currentpage) { echo " $currentpage \n"; @@ -452,7 +453,7 @@ class list_item{ $this->set_parent($parent); $this->attributes = $attributes; $parentlistclass = get_class($parent); - $this->children =& new $parentlistclass($parent->type, $parent->attributes, $parent->editable, $parent->page, $parent->pageurl); + $this->children =& new $parentlistclass($parent->type, $parent->attributes, $parent->editable, $parent->page, $parent->pageurl, $parent->pageparamname); $this->children->set_parent($this); } /** diff --git a/question/category.php b/question/category.php index 8f3c79102a..56cc56f16e 100644 --- a/question/category.php +++ b/question/category.php @@ -20,8 +20,6 @@ // get values from form for actions on this page $param = new stdClass(); - $param->page = optional_param('page', 1, PARAM_INT); - $thispageurl->param('page', $param->page); $param->moveup = optional_param('moveup', 0, PARAM_INT); $param->movedown = optional_param('movedown', 0, PARAM_INT); @@ -46,7 +44,7 @@ require_capability('moodle/question:managecategory', $context); - $qcobject = new question_category_object($param->page, $thispageurl); + $qcobject = new question_category_object($pagevars['cpage'], $thispageurl); $streditingcategories = get_string('editcategories', 'quiz'); if ($qcobject->editlist->process_actions($param->left, $param->right, $param->moveup, $param->movedown)) { @@ -106,7 +104,7 @@ $qcobject->add_category($param->newparent, $param->newcategory, $param->newinfo, $param->newpublish, $course->id); } else if (!empty($param->edit)) { - $qcobject->edit_single_category($param->edit, $param->page); + $qcobject->edit_single_category($param->edit, $pagevars['cpage']); } else if (!empty($param->updateid)) { $param->updateparent = required_param('updateparent',PARAM_INT); $param->updatename = required_param('updatename',PARAM_NOTAGS); diff --git a/question/category_class.php b/question/category_class.php index 4d1625af01..baf7112565 100644 --- a/question/category_class.php +++ b/question/category_class.php @@ -8,16 +8,15 @@ */ // number of categories to display on page -define("QUESTION_PAGE_LENGTH", 25); +define("QUESTION_PAGE_LENGTH", 2); require_once("$CFG->libdir/listlib.php"); class question_category_list extends moodle_list { var $table = "question_categories"; var $listitemclassname = 'question_category_list_item'; - function question_category_list($type='ul', $attributes='', $editable = false, $page = 0){ - parent::moodle_list($type, $attributes, $editable, $page); - } + + function get_records() { global $COURSE, $CFG; $categories = get_records($this->table, 'course', "{$COURSE->id}", $this->sortby); @@ -47,15 +46,11 @@ class question_category_list_item extends list_item { $linkcss = $category->publish ? ' class="published" ' : ' class="unpublished" '; - if (!empty($parent->page)) { - $pagelink="&page=".$parent->page; - } else { - $pagelink=""; - } /// Each section adds html to be displayed as part of this list item + - $item = ' + $item = ' ' .$str->edit. ' ' . $category->name . '('.$category->questioncount.')'. ''; @@ -63,15 +58,15 @@ class question_category_list_item extends list_item { if (!empty($category->publish)) { - $item .= ' + $item .= ' ' .$str->hide. ' '; } else { - $item .= ' + $item .= ' ' .$str->publish. ' '; } if ($category->id != $extraargs['defaultcategory']->id) { - $item .= ' + $item .= ' ' .$str->delete. ' '; } @@ -105,15 +100,17 @@ class question_category_object { var $categorystrings; var $defaultcategory; //------------------------------------------------------ + /** + * @var moodle_url Object representing url for this page + */ var $pageurl; - var $pageparams = array(); /** * Constructor * * Gets necessary strings and sets relevant path information */ - function question_category_object($page) { + function question_category_object($page, $pageurl) { global $CFG, $COURSE; $this->tab = str_repeat(' ', $this->tabsize); @@ -141,62 +138,14 @@ class question_category_object { $this->str->page = get_string('page'); $this->pixpath = $CFG->pixpath; - $this->editlist = new question_category_list('ul', '', true, $page); + $this->editlist = new question_category_list('ul', '', true, $page, $pageurl, 'cpage'); - $this->add_page_params(array('courseid'=>$COURSE->id, 'page' => $this->page)); - $this->pageurl = strip_querystring(qualified_me());//default + $this->pageurl = $pageurl; $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 * @@ -284,7 +233,7 @@ class question_category_object { echo '
'; echo '
'; echo "sesskey\" />"; - echo ''; + echo $this->pageurl->hidden_params_out(); echo ''; print_table($this->newtable); echo '
'; @@ -297,7 +246,6 @@ class question_category_object { * * $this->initialize() must have already been called * - * @param int $page page to display (0=do not paginate) */ function output_edit_list() { print_box_start('boxwidthwide boxaligncenter generalbox'); @@ -329,7 +277,7 @@ class question_category_object { - function edit_single_category($categoryid, $page=1) { + function edit_single_category($categoryid) { /// Interface for adding a new category global $USER, $COURSE; @@ -340,12 +288,13 @@ class question_category_object { helpbutton("categories_edit", $this->str->editcategory, "quiz"); echo ''; echo '
'; - $this->output_edit_single_table($category, $page); + $this->output_edit_single_table($category); echo '
'; + //cancel button echo '

-
- - +
'; + echo $this->pageurl->hidden_params_out(); + echo '
@@ -363,8 +312,8 @@ class question_category_object { * @param object category * @param int page current page */ - function output_edit_single_table($category, $page=1) { - global $USER, $COURSE; + function output_edit_single_table($category) { + global $USER; $publishoptions[0] = get_string("no"); $publishoptions[1] = get_string("yes"); $strupdate = get_string('update'); @@ -408,9 +357,8 @@ class question_category_object { echo '

'; echo '
'; echo "sesskey\" />"; - echo ''; + echo $this->pageurl->hidden_params_out(); echo ''; - echo ""; print_table($edittable); echo '
'; echo '

'; @@ -534,7 +482,7 @@ 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 + redirect($this->pageurl->out());//always redirect after successful action } } @@ -555,7 +503,7 @@ class question_category_object { 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 + redirect($this->pageurl->out());//always redirect after successful action } } @@ -595,7 +543,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 + redirect($this->pageurl->out());//always redirect after successful action } } @@ -625,7 +573,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()); + redirect($this->pageurl->out()); } } } diff --git a/question/editlib.php b/question/editlib.php index c45cd4f23a..f6f817bdcd 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -632,6 +632,13 @@ function question_edit_setup($requirecmid = false, $requirecourseid = true){ } else { $pagevars['showquestiontext'] = 0; } + + //category list page + $pagevars['cpage'] = optional_param('cpage', 1, PARAM_INT); + if ($pagevars['cpage'] != 1){ + $thispageurl->param('cpage', $pagevars['cpage']); + } + return array($thispageurl, $courseid, $cmid, $cm, $module, $pagevars); } -- 2.39.5