Subversion Repositories Applications.referentiel

Rev

Rev 344 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 344 Rev 387
1
<?php
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
 
3
 
4
/**
4
/**
5
 * Contains the Pager_Sliding class
5
 * Contains the Pager_Sliding class
6
 *
6
 *
7
 * PHP versions 4 and 5
7
 * PHP versions 4 and 5
8
 *
8
 *
9
 * LICENSE: Redistribution and use in source and binary forms, with or without
9
 * LICENSE: Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
10
 * modification, are permitted provided that the following conditions are met:
11
 * 1. Redistributions of source code must retain the above copyright
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
15
 *    documentation and/or other materials provided with the distribution.
16
 * 3. The name of the author may not be used to endorse or promote products
16
 * 3. The name of the author may not be used to endorse or promote products
17
 *    derived from this software without specific prior written permission.
17
 *    derived from this software without specific prior written permission.
18
 *
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
20
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
23
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 *
29
 *
30
 * @category   HTML
30
 * @category   HTML
31
 * @package    Pager
31
 * @package    Pager
32
 * @author     Lorenzo Alberton <l dot alberton at quipo dot it>
32
 * @author     Lorenzo Alberton <l dot alberton at quipo dot it>
33
 * @copyright  2003-2006 Lorenzo Alberton
33
 * @copyright  2003-2006 Lorenzo Alberton
34
 * @license    http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
34
 * @license    http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
35
 * @version    CVS: $Id: Sliding.php 62 2010-05-06 13:21:56Z jpm $
35
 * @version    CVS: $Id: Sliding.php 62 2010-05-06 13:21:56Z jpm $
36
 * @link       http://pear.php.net/package/Pager
36
 * @link       http://pear.php.net/package/Pager
37
 */
37
 */
38
 
38
 
39
/**
39
/**
40
 * require PEAR::Pager_Common base class
40
 * require PEAR::Pager_Common base class
41
 */
41
 */
42
require_once dirname(__FILE__).'/Common.php';
42
require_once dirname(__FILE__).'/Common.php';
43
 
43
 
44
/**
44
/**
45
 * Pager_Sliding - Generic data paging class  ("sliding window" style)
45
 * Pager_Sliding - Generic data paging class  ("sliding window" style)
46
 * Usage examples can be found in the PEAR manual
46
 * Usage examples can be found in the PEAR manual
47
 *
47
 *
48
 * @category   HTML
48
 * @category   HTML
49
 * @package    Pager
49
 * @package    Pager
50
 * @author     Lorenzo Alberton <l dot alberton at quipo dot it>
50
 * @author     Lorenzo Alberton <l dot alberton at quipo dot it>
51
 * @copyright  2003-2005 Lorenzo Alberton
51
 * @copyright  2003-2005 Lorenzo Alberton
52
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
52
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
53
 * @link       http://pear.php.net/package/Pager
53
 * @link       http://pear.php.net/package/Pager
54
 */
54
 */
55
class Pager_Sliding extends Pager_Common
55
class Pager_Sliding extends Pager_Common
56
{
56
{
57
    // {{{ Pager_Sliding()
57
    // {{{ Pager_Sliding()
58
 
58
 
59
    /**
59
    /**
60
     * Constructor
60
     * Constructor
61
     *
61
     *
62
     * @param array $options    An associative array of option names
62
     * @param array $options    An associative array of option names
63
     *                          and their values
63
     *                          and their values
64
     * @access public
64
     * @access public
65
     */
65
     */
66
    function Pager_Sliding($options = array())
66
    function Pager_Sliding($options = array())
67
    {
67
    {
68
        //set default Pager_Sliding options
68
        //set default Pager_Sliding options
69
        $this->_delta                 = 2;
69
        $this->_delta                 = 2;
70
        $this->_prevImg               = '&laquo;';
70
        $this->_prevImg               = '&laquo;';
71
        $this->_nextImg               = '&raquo;';
71
        $this->_nextImg               = '&raquo;';
72
        $this->_separator             = '|';
72
        $this->_separator             = '|';
73
        $this->_spacesBeforeSeparator = 3;
73
        $this->_spacesBeforeSeparator = 3;
74
        $this->_spacesAfterSeparator  = 3;
74
        $this->_spacesAfterSeparator  = 3;
75
        $this->_curPageSpanPre        = '<b><u>';
75
        $this->_curPageSpanPre        = '<b><u>';
76
        $this->_curPageSpanPost       = '</u></b>';
76
        $this->_curPageSpanPost       = '</u></b>';
77
 
77
 
78
        //set custom options
78
        //set custom options
79
        $err = $this->setOptions($options);
79
        $err = $this->setOptions($options);
80
        if ($err !== PAGER_OK) {
80
        if ($err !== PAGER_OK) {
81
            return $this->raiseError($this->errorMessage($err), $err);
81
            return $this->raiseError($this->errorMessage($err), $err);
82
        }
82
        }
83
        $this->build();
83
        $this->build();
84
    }
84
    }
85
 
85
 
86
    // }}}
86
    // }}}
87
    // {{{ getPageIdByOffset()
87
    // {{{ getPageIdByOffset()
88
 
88
 
89
    /**
89
    /**
90
     * "Overload" PEAR::Pager method. VOID. Not needed here...
90
     * "Overload" PEAR::Pager method. VOID. Not needed here...
91
     * @param integer $index Offset to get pageID for
91
     * @param integer $index Offset to get pageID for
92
     * @deprecated
92
     * @deprecated
93
     * @access public
93
     * @access public
94
     */
94
     */
95
    function getPageIdByOffset($index=null) { }
95
    function getPageIdByOffset($index=null) { }
96
 
96
 
97
    // }}}
97
    // }}}
98
    // {{{ getPageRangeByPageId()
98
    // {{{ getPageRangeByPageId()
99
 
99
 
100
    /**
100
    /**
101
     * Given a PageId, it returns the limits of the range of pages displayed.
101
     * Given a PageId, it returns the limits of the range of pages displayed.
102
     * While getOffsetByPageId() returns the offset of the data within the
102
     * While getOffsetByPageId() returns the offset of the data within the
103
     * current page, this method returns the offsets of the page numbers interval.
103
     * current page, this method returns the offsets of the page numbers interval.
104
     * E.g., if you have pageId=5 and delta=2, it will return (3, 7).
104
     * E.g., if you have pageId=5 and delta=2, it will return (3, 7).
105
     * PageID of 9 would give you (4, 8).
105
     * PageID of 9 would give you (4, 8).
106
     * If the method is called without parameter, pageID is set to currentPage#.
106
     * If the method is called without parameter, pageID is set to currentPage#.
107
     *
107
     *
108
     * @param integer PageID to get offsets for
108
     * @param integer PageID to get offsets for
109
     * @return array  First and last offsets
109
     * @return array  First and last offsets
110
     * @access public
110
     * @access public
111
     */
111
     */
112
    function getPageRangeByPageId($pageid = null)
112
    function getPageRangeByPageId($pageid = null)
113
    {
113
    {
114
        $pageid = isset($pageid) ? (int)$pageid : $this->_currentPage;
114
        $pageid = isset($pageid) ? (int)$pageid : $this->_currentPage;
115
        if (!isset($this->_pageData)) {
115
        if (!isset($this->_pageData)) {
116
            $this->_generatePageData();
116
            $this->_generatePageData();
117
        }
117
        }
118
        if (isset($this->_pageData[$pageid]) || is_null($this->_itemData)) {
118
        if (isset($this->_pageData[$pageid]) || is_null($this->_itemData)) {
119
            if ($this->_expanded) {
119
            if ($this->_expanded) {
120
                $min_surplus = ($pageid <= $this->_delta) ? ($this->_delta - $pageid + 1) : 0;
120
                $min_surplus = ($pageid <= $this->_delta) ? ($this->_delta - $pageid + 1) : 0;
121
                $max_surplus = ($pageid >= ($this->_totalPages - $this->_delta)) ?
121
                $max_surplus = ($pageid >= ($this->_totalPages - $this->_delta)) ?
122
                                ($pageid - ($this->_totalPages - $this->_delta)) : 0;
122
                                ($pageid - ($this->_totalPages - $this->_delta)) : 0;
123
            } else {
123
            } else {
124
                $min_surplus = $max_surplus = 0;
124
                $min_surplus = $max_surplus = 0;
125
            }
125
            }
126
            return array(
126
            return array(
127
                max($pageid - $this->_delta - $max_surplus, 1),
127
                max($pageid - $this->_delta - $max_surplus, 1),
128
                min($pageid + $this->_delta + $min_surplus, $this->_totalPages)
128
                min($pageid + $this->_delta + $min_surplus, $this->_totalPages)
129
            );
129
            );
130
        }
130
        }
131
        return array(0, 0);
131
        return array(0, 0);
132
    }
132
    }
133
 
133
 
134
    // }}}
134
    // }}}
135
    // {{{ getLinks()
135
    // {{{ getLinks()
136
 
136
 
137
    /**
137
    /**
138
     * Returns back/next/first/last and page links,
138
     * Returns back/next/first/last and page links,
139
     * both as ordered and associative array.
139
     * both as ordered and associative array.
140
     *
140
     *
141
     * @param integer $pageID Optional pageID. If specified, links
141
     * @param integer $pageID Optional pageID. If specified, links
142
     *                for that page are provided instead of current one.
142
     *                for that page are provided instead of current one.
143
     * @return array back/pages/next/first/last/all links
143
     * @return array back/pages/next/first/last/all links
144
     * @access public
144
     * @access public
145
     */
145
     */
146
    function getLinks($pageID = null)
146
    function getLinks($pageID = null, $next_html = '')
147
    {
147
    {
148
        if ($pageID != null) {
148
        if ($pageID != null) {
149
            $_sav = $this->_currentPage;
149
            $_sav = $this->_currentPage;
150
            $this->_currentPage = $pageID;
150
            $this->_currentPage = $pageID;
151
 
151
 
152
            $this->links = '';
152
            $this->links = '';
153
            if ($this->_totalPages > (2 * $this->_delta + 1)) {
153
            if ($this->_totalPages > (2 * $this->_delta + 1)) {
154
                $this->links .= $this->_printFirstPage();
154
                $this->links .= $this->_printFirstPage();
155
            }
155
            }
156
            $this->links .= $this->_getBackLink();
156
            $this->links .= $this->_getBackLink();
157
            $this->links .= $this->_getPageLinks();
157
            $this->links .= $this->_getPageLinks();
158
            $this->links .= $this->_getNextLink();
158
            $this->links .= $this->_getNextLink();
159
            if ($this->_totalPages > (2 * $this->_delta + 1)) {
159
            if ($this->_totalPages > (2 * $this->_delta + 1)) {
160
                $this->links .= $this->_printLastPage();
160
                $this->links .= $this->_printLastPage();
161
            }
161
            }
162
        }
162
        }
163
 
163
 
164
        $back  = str_replace('&nbsp;', '', $this->_getBackLink());
164
        $back  = str_replace('&nbsp;', '', $this->_getBackLink());
165
        $next  = str_replace('&nbsp;', '', $this->_getNextLink());
165
        $next  = str_replace('&nbsp;', '', $this->_getNextLink());
166
        $pages = $this->_getPageLinks();
166
        $pages = $this->_getPageLinks();
167
        $first = $this->_printFirstPage();
167
        $first = $this->_printFirstPage();
168
        $last  = $this->_printLastPage();
168
        $last  = $this->_printLastPage();
169
        $all   = $this->links;
169
        $all   = $this->links;
170
        $linkTags = $this->linkTags;
170
        $linkTags = $this->linkTags;
171
 
171
 
172
        if ($pageID != null) {
172
        if ($pageID != null) {
173
            $this->_currentPage = $_sav;
173
            $this->_currentPage = $_sav;
174
        }
174
        }
175
 
175
 
176
        return array(
176
        return array(
177
            $back,
177
            $back,
178
            $pages,
178
            $pages,
179
            trim($next),
179
            trim($next),
180
            $first,
180
            $first,
181
            $last,
181
            $last,
182
            $all,
182
            $all,
183
            $linkTags,
183
            $linkTags,
184
            'back'  => $back,
184
            'back'  => $back,
185
            'pages' => $pages,
185
            'pages' => $pages,
186
            'next'  => $next,
186
            'next'  => $next,
187
            'first' => $first,
187
            'first' => $first,
188
            'last'  => $last,
188
            'last'  => $last,
189
            'all'   => $all,
189
            'all'   => $all,
190
            'linktags' => $linkTags
190
            'linktags' => $linkTags
191
        );
191
        );
192
    }
192
    }
193
 
193
 
194
    // }}}
194
    // }}}
195
    // {{{ _getPageLinks()
195
    // {{{ _getPageLinks()
196
 
196
 
197
    /**
197
    /**
198
     * Returns pages link
198
     * Returns pages link
199
     *
199
     *
200
     * @return string Links
200
     * @return string Links
201
     * @access private
201
     * @access private
202
     */
202
     */
203
    function _getPageLinks($url = '')
203
    function _getPageLinks($url = '')
204
    {
204
    {
205
        //legacy setting... the preferred way to set an option now
205
        //legacy setting... the preferred way to set an option now
206
        //is adding it to the constuctor
206
        //is adding it to the constuctor
207
        if (!empty($url)) {
207
        if (!empty($url)) {
208
            $this->_path = $url;
208
            $this->_path = $url;
209
        }
209
        }
210
        
210
        
211
        //If there's only one page, don't display links
211
        //If there's only one page, don't display links
212
        if ($this->_clearIfVoid && ($this->_totalPages < 2)) {
212
        if ($this->_clearIfVoid && ($this->_totalPages < 2)) {
213
            return '';
213
            return '';
214
        }
214
        }
215
 
215
 
216
        $links = '';
216
        $links = '';
217
        if ($this->_totalPages > (2 * $this->_delta + 1)) {
217
        if ($this->_totalPages > (2 * $this->_delta + 1)) {
218
            if ($this->_expanded) {
218
            if ($this->_expanded) {
219
                if (($this->_totalPages - $this->_delta) <= $this->_currentPage) {
219
                if (($this->_totalPages - $this->_delta) <= $this->_currentPage) {
220
                    $expansion_before = $this->_currentPage - ($this->_totalPages - $this->_delta);
220
                    $expansion_before = $this->_currentPage - ($this->_totalPages - $this->_delta);
221
                } else {
221
                } else {
222
                    $expansion_before = 0;
222
                    $expansion_before = 0;
223
                }
223
                }
224
                for ($i = $this->_currentPage - $this->_delta - $expansion_before; $expansion_before; $expansion_before--, $i++) {
224
                for ($i = $this->_currentPage - $this->_delta - $expansion_before; $expansion_before; $expansion_before--, $i++) {
225
                    $print_separator_flag = ($i != $this->_currentPage + $this->_delta); // && ($i != $this->_totalPages - 1)
225
                    $print_separator_flag = ($i != $this->_currentPage + $this->_delta); // && ($i != $this->_totalPages - 1)
226
                    
226
                    
227
                    $this->range[$i] = false;
227
                    $this->range[$i] = false;
228
                    $this->_linkData[$this->_urlVar] = $i;
228
                    $this->_linkData[$this->_urlVar] = $i;
229
                    $links .= $this->_renderLink($this->_altPage.' '.$i, $i)
229
                    $links .= $this->_renderLink($this->_altPage.' '.$i, $i)
230
                           . $this->_spacesBefore
230
                           . $this->_spacesBefore
231
                           . ($print_separator_flag ? $this->_separator.$this->_spacesAfter : '');
231
                           . ($print_separator_flag ? $this->_separator.$this->_spacesAfter : '');
232
                }
232
                }
233
            }
233
            }
234
 
234
 
235
            $expansion_after = 0;
235
            $expansion_after = 0;
236
            for ($i = $this->_currentPage - $this->_delta; ($i <= $this->_currentPage + $this->_delta) && ($i <= $this->_totalPages); $i++) {
236
            for ($i = $this->_currentPage - $this->_delta; ($i <= $this->_currentPage + $this->_delta) && ($i <= $this->_totalPages); $i++) {
237
                if ($i < 1) {
237
                if ($i < 1) {
238
                    ++$expansion_after;
238
                    ++$expansion_after;
239
                    continue;
239
                    continue;
240
                }
240
                }
241
 
241
 
242
                // check when to print separator
242
                // check when to print separator
243
                $print_separator_flag = (($i != $this->_currentPage + $this->_delta) && ($i != $this->_totalPages));
243
                $print_separator_flag = (($i != $this->_currentPage + $this->_delta) && ($i != $this->_totalPages));
244
 
244
 
245
                if ($i == $this->_currentPage) {
245
                if ($i == $this->_currentPage) {
246
                    $this->range[$i] = true;
246
                    $this->range[$i] = true;
247
                    $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost;
247
                    $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost;
248
                } else {
248
                } else {
249
                    $this->range[$i] = false;
249
                    $this->range[$i] = false;
250
                    $this->_linkData[$this->_urlVar] = $i;
250
                    $this->_linkData[$this->_urlVar] = $i;
251
                    $links .= $this->_renderLink($this->_altPage.' '.$i, $i);
251
                    $links .= $this->_renderLink($this->_altPage.' '.$i, $i);
252
                }
252
                }
253
                $links .= $this->_spacesBefore
253
                $links .= $this->_spacesBefore
254
                        . ($print_separator_flag ? $this->_separator.$this->_spacesAfter : '');
254
                        . ($print_separator_flag ? $this->_separator.$this->_spacesAfter : '');
255
            }
255
            }
256
 
256
 
257
            if ($this->_expanded && $expansion_after) {
257
            if ($this->_expanded && $expansion_after) {
258
                $links .= $this->_separator . $this->_spacesAfter;
258
                $links .= $this->_separator . $this->_spacesAfter;
259
                for ($i = $this->_currentPage + $this->_delta +1; $expansion_after; $expansion_after--, $i++) {
259
                for ($i = $this->_currentPage + $this->_delta +1; $expansion_after; $expansion_after--, $i++) {
260
                    $print_separator_flag = ($expansion_after != 1);
260
                    $print_separator_flag = ($expansion_after != 1);
261
                    $this->range[$i] = false;
261
                    $this->range[$i] = false;
262
                    $this->_linkData[$this->_urlVar] = $i;
262
                    $this->_linkData[$this->_urlVar] = $i;
263
                    $links .= $this->_renderLink($this->_altPage.' '.$i, $i)
263
                    $links .= $this->_renderLink($this->_altPage.' '.$i, $i)
264
                      . $this->_spacesBefore
264
                      . $this->_spacesBefore
265
                      . ($print_separator_flag ? $this->_separator.$this->_spacesAfter : '');
265
                      . ($print_separator_flag ? $this->_separator.$this->_spacesAfter : '');
266
                }
266
                }
267
            }
267
            }
268
 
268
 
269
        } else {
269
        } else {
270
            //if $this->_totalPages <= (2*Delta+1) show them all
270
            //if $this->_totalPages <= (2*Delta+1) show them all
271
            for ($i=1; $i<=$this->_totalPages; $i++) {
271
            for ($i=1; $i<=$this->_totalPages; $i++) {
272
                if ($i != $this->_currentPage) {
272
                if ($i != $this->_currentPage) {
273
                    $this->range[$i] = false;
273
                    $this->range[$i] = false;
274
                    $this->_linkData[$this->_urlVar] = $i;
274
                    $this->_linkData[$this->_urlVar] = $i;
275
                    $links .= $this->_renderLink($this->_altPage.' '.$i, $i);
275
                    $links .= $this->_renderLink($this->_altPage.' '.$i, $i);
276
                } else {
276
                } else {
277
                    $this->range[$i] = true;
277
                    $this->range[$i] = true;
278
                    $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost;
278
                    $links .= $this->_curPageSpanPre . $i . $this->_curPageSpanPost;
279
                }
279
                }
280
                $links .= $this->_spacesBefore
280
                $links .= $this->_spacesBefore
281
                       . (($i != $this->_totalPages) ? $this->_separator.$this->_spacesAfter : '');
281
                       . (($i != $this->_totalPages) ? $this->_separator.$this->_spacesAfter : '');
282
            }
282
            }
283
        }
283
        }
284
        return $links;
284
        return $links;
285
    }
285
    }
286
 
286
 
287
    // }}}
287
    // }}}
288
}
288
}
289
?>
-
 
290
289
?>
-
 
290