]> git.mjollnir.org Git - moodle.git/commitdiff
pass the category list page param from page to page in question bank editing pages.
authorjamiesensei <jamiesensei>
Mon, 7 May 2007 05:53:20 +0000 (05:53 +0000)
committerjamiesensei <jamiesensei>
Mon, 7 May 2007 05:53:20 +0000 (05:53 +0000)
lib/listlib.php
question/category.php
question/category_class.php
question/editlib.php

index 7f6994f6c9ffd045eac9c72d6cd5c23b0923c832..5d8bc55c560294ac74d658c00ec36ebe8b36da48 100644 (file)
@@ -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 "<div class=\"paging\">".get_string($this->pageparamname).":\n";
+            echo "<div class=\"paging\">".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);
     }
     /**
index 8f3c79102a16cd4060fb50f1b959e765068929fe..56cc56f16e9187c4597a54143022dbcb40a242c4 100644 (file)
@@ -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)) {
             $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);
index 4d1625af01874c49d82ee14d284e5bbde6732202..baf7112565faf21e81a0e2906057397c15473417 100644 (file)
@@ -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="&amp;page=".$parent->page;
-        } else {
-            $pagelink="";
-        }
 
         /// Each section adds html to be displayed as part of this list item
+        
 
-        $item = '<a ' . $linkcss . ' title="' . $str->edit. '" href="'.$this->parentlist->get_action_url().'&amp;edit=' . $this->id .'">
+        $item = '<a ' . $linkcss . ' title="' . $str->edit. '" href="'.$this->parentlist->pageurl->out_action(array('edit'=>$this->id)).'">
             <img src="' . $pixpath . '/t/edit.gif" class="iconsmall"
             alt="' .$str->edit. '" /> ' . $category->name . '('.$category->questioncount.')'. '</a>';
 
@@ -63,15 +58,15 @@ class question_category_list_item extends list_item {
 
 
         if (!empty($category->publish)) {
-            $item .= '<a title="' . $str->hide . '" href="'.$this->parentlist->get_action_url().'&amp;hide=' . $this->id .'">
+            $item .= '<a title="' . $str->hide . '" href="'.$this->parentlist->pageurl->out_action(array('hide'=>$this->id)).'">
               <img src="' . $pixpath . '/t/hide.gif" class="iconsmall" alt="' .$str->hide. '" /></a> ';
         } else {
-            $item .= '<a title="' . $str->publish . '" href="'.$this->parentlist->get_action_url().'&amp;publish=' . $this->id .'">
+            $item .= '<a title="' . $str->publish . '" href="'.$this->parentlist->pageurl->out_action(array('publish'=>$this->id)).'">
               <img src="' . $pixpath . '/t/show.gif" class="iconsmall" alt="' .$str->publish. '" /></a> ';
         }
 
         if ($category->id != $extraargs['defaultcategory']->id) {
-            $item .=  '<a title="' . $str->delete . '"href="'.$this->parentlist->get_action_url().'&amp;delete=' . $this->id .'">
+            $item .=  '<a title="' . $str->delete . '" href="'.$this->parentlist->pageurl->out_action(array('delete'=>$this->id)).'">
                     <img src="' . $pixpath . '/t/delete.gif" class="iconsmall" alt="' .$str->delete. '" /></a> ';
         }
 
@@ -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('&nbsp;', $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, "&amp;");
-
-        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, "&amp;");
-
-        return $this->pageurl.'?'.$params;
-    }
-
     /**
      * Displays the user interface
      *
@@ -284,7 +233,7 @@ class question_category_object {
         echo '<form action="category.php" method="post">';
         echo '<fieldset class="invisiblefieldset" style="display: block">';
         echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
-        echo '<input type="hidden" name="courseid" value="'. $COURSE->id . '" />';
+        echo $this->pageurl->hidden_params_out();
         echo '<input type="hidden" name="addcategory" value="true" />';
         print_table($this->newtable);
         echo '</fieldset>';
@@ -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 '</h2>';
             echo '<table width="100%"><tr><td>';
-            $this->output_edit_single_table($category, $page);
+            $this->output_edit_single_table($category);
             echo '</td></tr></table>';
+            //cancel button
             echo '<p><div align="center"><form action="category.php" method="get">
-                <div>
-                <input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />
-                <input type="hidden" name="id" value="' . $COURSE->id . '" />
+                <div>';
+            echo $this->pageurl->hidden_params_out();
+            echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />
                 <input type="submit" value="' . $this->str->cancel . '" />
                 </div>
                 </form>
@@ -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 '<p><form action="category.php" method="post">';
         echo '<fieldset class="invisiblefieldset">';
         echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
-        echo '<input type="hidden" name="id" value="'. $COURSE->id . '" />';
+        echo $this->pageurl->hidden_params_out();
         echo '<input type="hidden" name="updateid" value="' . $category->id . '" />';
-        echo "<input type=\"hidden\" name=\"page\" value=\"$page\" />";
         print_table($edittable);
         echo '</fieldset>';
         echo '</form></p>';
@@ -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());
         }
     }
 }
index c45cd4f23abd70c5694a2e5244327da6227e8b3e..f6f817bdcd03f24ae64191f6e27177a445709c54 100644 (file)
@@ -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);
 }