Subversion Repositories Applications.papyrus

Rev

Rev 848 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 848 Rev 1713
Line 69... Line 69...
69
     *                - 'optionText': text to show in each option.
69
     *                - 'optionText': text to show in each option.
70
     *                  Use '%d' where you want to see the number of pages selected.
70
     *                  Use '%d' where you want to see the number of pages selected.
71
     *                - 'attributes': (html attributes) Tag attributes or
71
     *                - 'attributes': (html attributes) Tag attributes or
72
     *                  HTML attributes (id="foo" pairs), will be inserted in the
72
     *                  HTML attributes (id="foo" pairs), will be inserted in the
73
     *                  <select> tag
73
     *                  <select> tag
-
 
74
     *                - 'checkMaxLimit': if true, Pager checks if $end is bigger
-
 
75
     *                  than $totalItems, and doesn't show the extra select options
74
     * @return string xhtml select box
76
     * @return string xhtml select box
75
     * @access public
77
     * @access public
76
     */
78
     */
77
    function getPerPageSelectBox($start=5, $end=30, $step=5, $showAllData=false, $extraParams=array())
79
    function getPerPageSelectBox($start=5, $end=30, $step=5, $showAllData=false, $extraParams=array())
78
    {
80
    {
79
        // FIXME: needs POST support
81
        // FIXME: needs POST support
80
        $optionText = '%d';
82
        $optionText = '%d';
81
        $attributes = '';
83
        $attributes = '';
-
 
84
        $checkMaxLimit = false;
82
        if (is_string($extraParams)) {
85
        if (is_string($extraParams)) {
83
            //old behavior, BC maintained
86
            //old behavior, BC maintained
84
            $optionText = $extraParams;
87
            $optionText = $extraParams;
85
        } else {
88
        } else {
86
            if (array_key_exists('optionText', $extraParams)) {
89
            if (array_key_exists('optionText', $extraParams)) {
87
                $optionText = $extraParams['optionText'];
90
                $optionText = $extraParams['optionText'];
88
            }
91
            }
89
            if (array_key_exists('attributes', $extraParams)) {
92
            if (array_key_exists('attributes', $extraParams)) {
90
                $attributes = $extraParams['attributes'];
93
                $attributes = $extraParams['attributes'];
91
            }
94
            }
-
 
95
            if (array_key_exists('checkMaxLimit', $extraParams)) {
-
 
96
                $checkMaxLimit = $extraParams['checkMaxLimit'];
-
 
97
            }
92
        }
98
        }
Line 93... Line 99...
93
 
99
 
94
        if (!strstr($optionText, '%d')) {
100
        if (!strstr($optionText, '%d')) {
95
            return $this->pager->raiseError(
101
            return $this->pager->raiseError(
Line 103... Line 109...
103
        if (!empty($_SESSION[$this->pager->_sessionVar])) {
109
        if (!empty($_SESSION[$this->pager->_sessionVar])) {
104
            $selected = (int)$_SESSION[$this->pager->_sessionVar];
110
            $selected = (int)$_SESSION[$this->pager->_sessionVar];
105
        } else {
111
        } else {
106
            $selected = $this->pager->_perPage;
112
            $selected = $this->pager->_perPage;
107
        }
113
        }
-
 
114
        
-
 
115
        if ($checkMaxLimit && $this->pager->_totalItems > 0 && $this->pager->_totalItems < $end) {
-
 
116
            $end = $this->pager->_totalItems;
-
 
117
        }
Line 108... Line 118...
108
 
118
 
109
        $tmp = '<select name="'.$this->pager->_sessionVar.'"';
119
        $tmp = '<select name="'.$this->pager->_sessionVar.'"';
110
        if (!empty($attributes)) {
120
        if (!empty($attributes)) {
111
            $tmp .= ' '.$attributes;
121
            $tmp .= ' '.$attributes;
112
        }
122
        }
-
 
123
        $tmp .= '>';
113
        $tmp .= '>';
124
        $last = $start;
-
 
125
        for ($i=$start; $i<=$end; $i+=$step) {
114
        for ($i=$start; $i<=$end; $i+=$step) {
126
            $last = $i;
115
            $tmp .= '<option value="'.$i.'"';
127
            $tmp .= '<option value="'.$i.'"';
116
            if ($i == $selected) {
128
            if ($i == $selected) {
117
                $tmp .= ' selected="selected"';
129
                $tmp .= ' selected="selected"';
118
            }
130
            }
119
            $tmp .= '>'.sprintf($optionText, $i).'</option>';
131
            $tmp .= '>'.sprintf($optionText, $i).'</option>';
120
        }
132
        }
121
        if ($showAllData && $end < $this->pager->_totalItems) {
133
        if ($showAllData && $last != $this->pager->_totalItems) {
122
            $tmp .= '<option value="'.$this->pager->_totalItems.'"';
134
            $tmp .= '<option value="'.$this->pager->_totalItems.'"';
123
            if ($this->pager->_totalItems == $selected) {
135
            if ($this->pager->_totalItems == $selected) {
124
                $tmp .= ' selected="selected"';
136
                $tmp .= ' selected="selected"';
125
            }
137
            }