From: jamiesensei Date: Mon, 7 May 2007 05:25:44 +0000 (+0000) Subject: added argument to constructor to specify the name of the page parameter used to pass... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=81be5cdec30f6ce19db3186ce012d144210c5b0f;p=moodle.git added argument to constructor to specify the name of the page parameter used to pass the page no of the list. Default to 'page' --- diff --git a/lib/listlib.php b/lib/listlib.php index 1fd34d5935..039a3af7f0 100644 --- a/lib/listlib.php +++ b/lib/listlib.php @@ -88,9 +88,8 @@ class moodle_list{ var $pagecount; //------------------------------------------------------ var $pageurl; - var $pageparams = array(); + var $pageparamname; - var $str; /** * Constructor function * @@ -98,62 +97,22 @@ class moodle_list{ * @param string $attributes * @param boolean $editable * @param integer $page if 0 no pagination. + * @param moodle_url $page if 0 no pagination. * @return moodle_list */ - function moodle_list($type='ul', $attributes='', $editable = false, $page = 0){ + function moodle_list($type='ul', $attributes='', $editable = false, $page = 0, $pageurl=null, $pageparamname = 'page'){ $this->editable = $editable; $this->attributes = $attributes; $this->type = $type; $this->page = $page; - $this->pageurl = strip_querystring(qualified_me());//default - if (!empty($this->page)){ - $this->add_page_params(array('page' => $this->page)); - } - } - /** - * 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; - } - - /** - * 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); + $this->pageparamname = $pageparamname; + + if ($pageurl === null){ + $this->pageurl = new moodle_url(); + $this->pageurl->params(array($this->pageparamname => $this->page)); + } else { + $this->pageurl = $pageurl; } - $params = implode($arr, "&"); - - return $this->pageurl.'?'.$params; } /** @@ -285,13 +244,13 @@ class moodle_list{ */ function display_page_numbers() { if (!empty($this->page) && ($this->pagecount>1)){ - echo "
".get_string('page').":\n"; + echo "
".get_string($this->pageparamname).":\n"; foreach (range(1,$this->pagecount) as $currentpage) { if ($this->page == $currentpage) { echo " $currentpage \n"; } else { - echo "get_url(array('page'=>$currentpage))."\">"; + echo "pageurl->out(false, array($this->pageparamname => $currentpage))."\">"; echo " $currentpage \n"; } } @@ -428,19 +387,19 @@ class moodle_list{ $this->move_item_up_down('up', $moveup); if ($moveup == $this->items[$this->firstitem -1]->id){//redirect to page that item has been moved to. $this->page --; - $this->add_page_params(array('page'=>$this->page)); + $this->pageurl->params(array($this->pageparamname => $this->page)); } } else if (!empty($movedown)) { $this->move_item_up_down('down', $movedown); if ($movedown == $this->items[$this->lastitem -1]->id){//redirect to page that item has been moved to. $this->page ++; - $this->add_page_params(array('page'=>$this->page)); + $this->pageurl->params(array($this->pageparamname => $this->page)); } } else { return false; } - redirect($this->get_url()); + redirect($this->pageurl->out()); } } @@ -493,9 +452,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); - $this->children->add_page_params($parent->pageparams); - $this->children->pageurl = $parent->pageurl; + $this->children =& new $parentlistclass($parent->type, $parent->attributes, $parent->editable, $parent->page, $parent->pageurl); $this->children->set_parent($this); } /** @@ -537,11 +494,7 @@ class list_item{ $strmovedown = get_string('movedown'); $pixpath = $CFG->pixpath; $icons = ' '; - if (!empty($this->parentlist->page)) { - $pagelink="&page={$this->parentlist->page}"; - } else { - $pagelink=""; - } + if (isset($this->parentlist->parentitem)) { $parentitem =& $this->parentlist->parentitem; if (isset($parentitem->parentlist->parentitem)){ @@ -549,21 +502,21 @@ class list_item{ } else { $action = get_string('maketoplevelitem', 'question'); } - $icons .= ' + $icons .= ' ' . $action. ' '; } else { $icons .= ''; } if (!$first) { - $icons .= ' + $icons .= ' ' . $strmoveup. ' '; } else { $icons .= ''; } if (!$last) { - $icons .= ' + $icons .= ' ' .$strmovedown. ' '; } else { $icons .= ''; @@ -571,7 +524,7 @@ class list_item{ if (!empty($lastitem)) { $makechildof = get_string('makechildof', 'question', $lastitem->name); - $icons .= ' + $icons .= ' ' . $makechildof. ' '; } else { $icons .= '';