Passed
Push — 1.10.x ( 021894...0e6d9a )
by
unknown
51:25
created

Pager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
c 1
b 1
f 0
lcom 0
cbo 0
dl 0
loc 131
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B factory() 0 22 4
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
4
/**
5
 * Contains the Pager class
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * LICENSE: Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
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
17
 *    derived from this software without specific prior written permission.
18
 *
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
21
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
23
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * @category  HTML
31
 * @package   Pager
32
 * @author    Lorenzo Alberton <[email protected]>
33
 * @author    Richard Heyes <[email protected]>
34
 * @copyright 2003-2008 Lorenzo Alberton, Richard Heyes
35
 * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
36
 * @version   CVS: $Id: Pager.php,v 1.26 2008/02/02 16:55:04 quipo Exp $
37
 * @link      http://pear.php.net/package/Pager
38
 */
39
40
/**
41
 * Pager - Wrapper class for [Sliding|Jumping]-window Pager
42
 * Usage examples can be found in the PEAR manual
43
 *
44
 * @category  HTML
45
 * @package   Pager
46
 * @author    Lorenzo Alberton <[email protected]>
47
 * @author    Richard Heyes <[email protected]>
48
 * @copyright 2003-2008 Lorenzo Alberton, Richard Heyes
49
 * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
50
 * @link      http://pear.php.net/package/Pager
51
 */
52
class Pager
53
{
54
    // {{{ Pager()
55
56
    /**
57
     * Constructor
58
     *
59
     * -------------------------------------------------------------------------
60
     * VALID options are (default values are set some lines before):
61
     *  - mode       (string): "Jumping" or "Sliding"  -window - It determines
62
     *                         pager behaviour. See the manual for more details
63
     *  - totalItems (int):    # of items to page.
64
     *  - perPage    (int):    # of items per page.
65
     *  - delta      (int):    # of page #s to show before and after the current
66
     *                         one
67
     *  - linkClass  (string): name of CSS class used for link styling.
68
     *  - append     (bool):   if true pageID is appended as GET value to the
69
     *                         URL - if false it is embedded in the URL
70
     *                         according to "fileName" specs
71
     *  - httpMethod (string): Specifies the HTTP method to use. Valid values
72
     *                         are 'GET' or 'POST'
73
     *                         according to "fileName" specs
74
     *  - importQuery (bool):  if true (default behaviour), variables and
75
     *                         values are imported from the submitted data
76
     *                         (query string) and used in the generated links
77
     *                         otherwise they're ignored completely
78
     *  - path       (string): complete path to the page (without the page name)
79
     *  - fileName   (string): name of the page, with a %d if append=true
80
     *  - urlVar     (string): name of pageNumber URL var, for example "pageID"
81
     *  - altPrev    (string): alt text to display for prev page, on prev link.
82
     *  - altNext    (string): alt text to display for next page, on next link.
83
     *  - altPage    (string): alt text to display before the page number.
84
     *  - prevImg    (string): sth (it can be text such as "<< PREV" or an
85
     *                         <img/> as well...) to display instead of "<<".
86
     *  - nextImg    (string): same as prevImg, used for NEXT link, instead of
87
     *                         the default value, which is ">>".
88
     *  - separator  (string): what to use to separate numbers (can be an
89
     *                         <img/>, a comma, an hyphen, or whatever.
90
     *  - spacesBeforeSeparator
91
     *               (int):    number of spaces before the separator.
92
     *  - firstPagePre (string):
93
     *                         string used before first page number (can be an
94
     *                         <img/>, a "{", an empty string, or whatever.
95
     *  - firstPageText (string):
96
     *                         string used in place of first page number
97
     *  - firstPagePost (string):
98
     *                         string used after first page number (can be an
99
     *                         <img/>, a "}", an empty string, or whatever.
100
     *  - lastPagePre (string):
101
     *                         similar to firstPagePre.
102
     *  - lastPageText (string):
103
     *                         similar to firstPageText.
104
     *  - lastPagePost (string):
105
     *                         similar to firstPagePost.
106
     *  - spacesAfterSeparator
107
     *               (int):    number of spaces after the separator.
108
     *  - firstLinkTitle (string):
109
     *                          string used as title in <link rel="first"> tag
110
     *  - lastLinkTitle (string):
111
     *                          string used as title in <link rel="last"> tag
112
     *  - prevLinkTitle (string):
113
     *                          string used as title in <link rel="prev"> tag
114
     *  - nextLinkTitle (string):
115
     *                          string used as title in <link rel="next"> tag
116
     *  - curPageLinkClassName
117
     *               (string): name of CSS class used for current page link.
118
     *  - clearIfVoid(bool):   if there's only one page, don't display pager.
119
     *  - extraVars (array):   additional URL vars to be added to the querystring
120
     *  - excludeVars (array): URL vars to be excluded in the querystring
121
     *  - itemData   (array):  array of items to page.
122
     *  - useSessions (bool):  if true, number of items to display per page is
123
     *                         stored in the $_SESSION[$_sessionVar] var.
124
     *  - closeSession (bool): if true, the session is closed just after R/W.
125
     *  - sessionVar (string): name of the session var for perPage value.
126
     *                         A value != from default can be useful when
127
     *                         using more than one Pager istance in the page.
128
     *  - pearErrorMode (constant):
129
     *                         PEAR_ERROR mode for raiseError().
130
     *                         Default is PEAR_ERROR_RETURN.
131
     * -------------------------------------------------------------------------
132
     * REQUIRED options are:
133
     *  - fileName IF append==false (default is true)
134
     *  - itemData OR totalItems (if itemData is set, totalItems is overwritten)
135
     * -------------------------------------------------------------------------
136
     *
137
     * @param mixed $options Associative array of option names and their values
138
     *
139
     * @access public
140
     */
141
    public function __construct($options = array())
142
    {
143
144
    }
145
146
    // }}}
147
    // {{{ factory()
148
149
    /**
150
     * Return a pager based on $mode and $options
151
     *
152
     * @param array $options Optional parameters for the storage class
153
     *
154
     * @return object Storage object
155
     * @static
156
     * @access public
157
     */
158
    static function &factory($options = array())
159
    {
160
        $mode = (isset($options['mode']) ? ucfirst($options['mode']) : 'Jumping');
161
        $classname = 'Pager_' . $mode;
162
        $classfile = 'Pager' . DIRECTORY_SEPARATOR . $mode . '.php';
163
164
        // Attempt to include a custom version of the named class, but don't treat
165
        // a failure as fatal.  The caller may have already included their own
166
        // version of the named class.
167
        if (!class_exists($classname)) {
168
            include_once $classfile;
169
        }
170
171
        // If the class exists, return a new instance of it.
172
        if (class_exists($classname)) {
173
            $pager = new $classname($options);
174
            return $pager;
175
        }
176
177
        $null = null;
178
        return $null;
179
    }
180
181
    // }}}
182
}
183
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...