Pager
[ class tree: Pager ] [ index: Pager ] [ all elements ]

Class: Pager_Common

Source Location: /main/inc/lib/pear/Pager/Common.php

Class Overview


Pager_Common - Common base class for [Sliding|Jumping] Window Pager Extend this class to write a custom paging class


Author(s):

Copyright:

  • 2003-2005 Lorenzo Alberton, Richard Heyes

Variables

Methods


Child classes:

Pager_Sliding
Pager_Sliding - Generic data paging class ("sliding window" style) Usage examples can be found in the PEAR manual
Pager_Jumping
Pager_Jumping - Generic data paging class ("jumping window" style) Handles paging a set of data. For usage see the example.php provided.

Class Details

[line 73]
Pager_Common - Common base class for [Sliding|Jumping] Window Pager Extend this class to write a custom paging class



Tags:

author:  Lorenzo Alberton <dot alberton at quipo dot it l dot alberton at quipo dot it>
author:  Richard Heyes <richard@phpguru.org>
copyright:  2003-2005 Lorenzo Alberton, Richard Heyes
link:  http://pear.php.net/package/Pager
license:  PHP License 3.0


[ Top ]


Class Variables

$links =  ''

[line 405]



Tags:

var:  Complete set of links
access:  public

Type:   string


[ Top ]

$linkTags =  ''

[line 411]



Tags:

var:  Complete set of link tags
access:  public

Type:   string


[ Top ]

$range = array()

[line 419]



Tags:

var:  Array with a key => value pair representing page# => bool value (true if key==currentPageNumber). can be used for extreme customization.
access:  public

Type:   array


[ Top ]

$_accesskey =  false

[line 195]



Tags:

var:  TRUE => show accesskey attribute on <a> tags
access:  private

Type:   boolean


[ Top ]

$_allowed_options = array(
        'totalItems',
        'perPage',
        'delta',
        'linkClass',
        'path',
        'fileName',
        'fixFileName',
        'append',
        'httpMethod',
        'formID',
        'importQuery',
        'urlVar',
        'altFirst',
        'altPrev',
        'altNext',
        'altLast',
        'altPage',
        'prevImg',
        'nextImg',
        'expanded',
        'accesskey',
        'attributes',
        'separator',
        'spacesBeforeSeparator',
        'spacesAfterSeparator',
        'curPageLinkClassName',
        'curPageSpanPre',
        'curPageSpanPost',
        'firstPagePre',
        'firstPageText',
        'firstPagePost',
        'lastPagePre',
        'lastPageText',
        'lastPagePost',
        'firstLinkTitle',
        'nextLinkTitle',
        'prevLinkTitle',
        'lastLinkTitle',
        'showAllText',
        'itemData',
        'clearIfVoid',
        'useSessions',
        'closeSession',
        'sessionVar',
        'pearErrorMode',
        'extraVars',
        'excludeVars',
        'currentPage',
    )

[line 425]



Tags:

var:  list of available options (safety check)
access:  private

Type:   array


[ Top ]

$_altFirst =  'first page'

[line 207]



Tags:

var:  alt text for "first page" (use "%d" placeholder for page number)
access:  private

Type:   string


[ Top ]

$_altLast =  'last page'

[line 225]



Tags:

var:  alt text for "last page" (use "%d" placeholder for page number)
access:  private

Type:   string


[ Top ]

$_altNext =  'next page'

[line 219]



Tags:

var:  alt text for "next page"
access:  private

Type:   string


[ Top ]

$_altPage =  'page'

[line 231]



Tags:

var:  alt text for "page"
access:  private

Type:   string


[ Top ]

$_altPrev =  'previous page'

[line 213]



Tags:

var:  alt text for "previous page"
access:  private

Type:   string


[ Top ]

$_append =  true

[line 141]



Tags:

var:  you have to use FALSE with mod_rewrite
access:  private

Type:   boolean


[ Top ]

$_attributes =  ''

[line 201]



Tags:

var:  extra attributes for the <a> tag
access:  private

Type:   string


[ Top ]

$_classString =  ''

[line 117]



Tags:

var:  wrapper for CSS class name
access:  private

Type:   string


[ Top ]

$_clearIfVoid =  true

[line 369]



Tags:

var:  If TRUE and there's only one page, links aren't shown
access:  private

Type:   boolean


[ Top ]

$_closeSession =  false

[line 381]



Tags:

var:  Close the session when finished reading/writing data
access:  private

Type:   boolean


[ Top ]

$_curPageLinkClassName =  ''

[line 267]



Tags:

var:  CSS class name for current page link
access:  private

Type:   string


[ Top ]

$_curPageSpanPost =  ''

[line 279]



Tags:

var:  Text after current page link
access:  private

Type:   string


[ Top ]

$_curPageSpanPre =  ''

[line 273]



Tags:

var:  Text before current page link
access:  private

Type:   string


[ Top ]

$_currentPage =  1

[line 99]



Tags:

var:  current page number
access:  private

Type:   integer


[ Top ]

$_delta =  10

[line 93]



Tags:

var:  number of page links for each window
access:  private

Type:   integer


[ Top ]

$_excludeVars = array()

[line 183]



Tags:

var:  URL vars to ignore
access:  private

Type:   array


[ Top ]

$_expanded =  true

[line 189]



Tags:

var:  TRUE => expanded mode (for Pager_Sliding)
access:  private

Type:   boolean


[ Top ]

$_extraVars = array()

[line 177]



Tags:

var:  additional URL vars
access:  private

Type:   array


[ Top ]

$_fileName =  CURRENT_FILENAME

[line 129]



Tags:

var:  file name
access:  private

Type:   string


[ Top ]

$_firstLinkTitle =  'first page'

[line 333]



Tags:

access:  private

Type:   string


[ Top ]

$_firstPagePost =  ']'

[line 297]



Tags:

var:  Text after first page link
access:  private

Type:   string


[ Top ]

$_firstPagePre =  '['

[line 285]



Tags:

var:  Text before first page link
access:  private

Type:   string


[ Top ]

$_firstPageText =  ''

[line 291]



Tags:

var:  Text to be used for first page link
access:  private

Type:   string


[ Top ]

$_fixFileName =  true

[line 135]



Tags:

var:  If false, don't override the fileName option. Use at your own risk.
access:  private

Type:   boolean


[ Top ]

$_formID =  ''

[line 153]



Tags:

var:  specifies which HTML form to use
access:  private

Type:   string


[ Top ]

$_httpMethod =  'GET'

[line 147]



Tags:

var:  specifies which HTTP method to use
access:  private

Type:   string


[ Top ]

$_importQuery =  true

[line 159]



Tags:

var:  whether or not to import submitted data
access:  private

Type:   boolean


[ Top ]

$_itemData =  null

[line 363]



Tags:

var:  data to be paged
access:  private

Type:   array


[ Top ]

$_lastLinkTitle =  'last page'

[line 351]



Tags:

access:  private

Type:   string


[ Top ]

$_lastPagePost =  ']'

[line 315]



Tags:

var:  Text after last page link
access:  private

Type:   string


[ Top ]

$_lastPagePre =  '['

[line 303]



Tags:

var:  Text before last page link
access:  private

Type:   string


[ Top ]

$_lastPageText =  ''

[line 309]



Tags:

var:  Text to be used for last page link
access:  private

Type:   string


[ Top ]

$_linkClass =  ''

[line 111]



Tags:

var:  CSS class for links
access:  private

Type:   string


[ Top ]

$_linkData = array()

[line 171]



Tags:

var:  data to pass through the link
access:  private

Type:   array


[ Top ]

$_nextImg =  'Next &gt;&gt;'

[line 243]



Tags:

var:  image/text to use as "next" link
access:  private

Type:   string


[ Top ]

$_nextLinkTitle =  'next page'

[line 339]



Tags:

access:  private

Type:   string


[ Top ]

$_path =  CURRENT_PATHNAME

[line 123]



Tags:

var:  path name
access:  private

Type:   string


[ Top ]

$_pearErrorMode =  null

[line 396]

Pear error mode (when raiseError is called) (see PEAR doc)



Tags:

access:  private

Type:   int


[ Top ]

$_perPage =  10

[line 87]



Tags:

var:  number of items per page
access:  private

Type:   integer


[ Top ]

$_prevImg =  '&lt;&lt; Back'

[line 237]



Tags:

var:  image/text to use as "prev" link
access:  private

Type:   string


[ Top ]

$_prevLinkTitle =  'previous page'

[line 345]



Tags:

access:  private

Type:   string


[ Top ]

$_separator =  ''

[line 249]



Tags:

var:  link separator
access:  private

Type:   string


[ Top ]

$_sessionVar =  'setPerPage'

[line 387]



Tags:

var:  name of the session var for number of items per page
access:  private

Type:   string


[ Top ]

$_showAllText =  ''

[line 357]



Tags:

var:  Text to be used for the 'show all' option in the select box
access:  private

Type:   string


[ Top ]

$_spacesAfter =  ''

[line 327]



Tags:

var:  Will contain the HTML code for the spaces
access:  private

Type:   string


[ Top ]

$_spacesAfterSeparator =  1

[line 261]



Tags:

var:  number of spaces after separator
access:  private

Type:   integer


[ Top ]

$_spacesBefore =  ''

[line 321]



Tags:

var:  Will contain the HTML code for the spaces
access:  private

Type:   string


[ Top ]

$_spacesBeforeSeparator =  0

[line 255]



Tags:

var:  number of spaces before separator
access:  private

Type:   integer


[ Top ]

$_totalItems =

[line 81]



Tags:

var:  number of items
access:  private

Type:   integer


[ Top ]

$_totalPages =  1

[line 105]



Tags:

var:  total pages number
access:  private

Type:   integer


[ Top ]

$_urlVar =  'pageID'

[line 165]



Tags:

var:  name of the querystring var for pageID
access:  private

Type:   string


[ Top ]

$_useSessions =  false

[line 375]



Tags:

var:  Use session for storing the number of items per page
access:  private

Type:   boolean


[ Top ]



Class Methods


method build [line 484]

void build( )

Generate or refresh the links and paged data after a call to setOptions()



Tags:

access:  public


Overridden in child classes as:

Pager_Sliding::build()
Generate or refresh the links and paged data after a call to setOptions()
Pager_Jumping::build()
Generate or refresh the links and paged data after a call to setOptions()

[ Top ]

method errorMessage [line 1486]

string errorMessage( int $code)

Return a textual error message for a PAGER error code



Tags:

return:  error message
access:  public


Parameters:

int   $code   error code

[ Top ]

method getCurrentPageID [line 608]

integer getCurrentPageID( )

Returns ID of current page



Tags:

return:  ID of current page


[ Top ]

method getLinks [line 593]

array getLinks( [integer $pageID = null], [string $next_html = ''])

Returns back/next/first/last and page links, both as ordered and associative array.

NB: in original PEAR::Pager this method accepted two parameters, $back_html and $next_html. Now the only parameter accepted is an integer ($pageID), since the html text for prev/next links can be set in the factory. If a second parameter is provided, then the method act as it previously did. This hack was done to mantain backward compatibility only.




Tags:

return:  back/next/first/last and page links


Overridden in child classes as:

Pager_Sliding::getLinks()
Returns back/next/first/last and page links, both as ordered and associative array.
Pager_Jumping::getLinks()
Returns back/next/first/last and page links, both as ordered and associative array.

Parameters:

integer   $pageID   Optional pageID. If specified, links for that page are provided instead of current one. [ADDED IN NEW PAGER VERSION]
string   $next_html   HTML to put inside the next link [deprecated: use the factory instead]

[ Top ]

method getNextPageID [line 622]

mixed getNextPageID( )

Returns next page ID. If current page is last page this function returns FALSE



Tags:

return:  Next page ID


[ Top ]

method getOffsetByPageId [line 543]

array getOffsetByPageId( [integer $pageid = null])

Returns offsets for given pageID. Eg, if you pass it pageID one and your perPage limit is 10 it will return (1, 10). PageID of 2 would give you (11, 20).



Tags:

return:  First and last offsets
access:  public


Parameters:

integer   $pageid   PageID to get offsets for

[ Top ]

method getOption [line 1449]

mixed getOption( string $name)

Return the current value of a given option



Tags:

return:  option value


Parameters:

string   $name   option name

[ Top ]

method getOptions [line 1467]

array getOptions( )

Return an array with all the current pager options



Tags:

return:  list of all the pager options


[ Top ]

method getPageData [line 501]

array getPageData( [$pageID $pageID = null])

Returns an array of current pages data



Tags:

return:  Page data
access:  public


Parameters:

$pageID   $pageID   Desired page ID (optional)

[ Top ]

method getPageIdByOffset [line 523]

int getPageIdByOffset( $index $index)

Returns pageID for given offset



Tags:

return:  PageID for given offset


Overridden in child classes as:

Pager_Sliding::getPageIdByOffset()
"Overload" PEAR::Pager method. VOID. Not needed here...
Pager_Jumping::getPageIdByOffset()
Returns pageID for given offset

Parameters:

$index   $index   Offset to get pageID for

[ Top ]

method getPageRangeByPageId [line 567]

array getPageRangeByPageId( integer $pageID)



Tags:

return:  First and last offsets


Overridden in child classes as:

Pager_Sliding::getPageRangeByPageId()
Given a PageId, it returns the limits of the range of pages displayed.
Pager_Jumping::getPageRangeByPageId()
Given a PageId, it returns the limits of the range of pages displayed.

Parameters:

integer   $pageID   PageID to get offsets for

[ Top ]

method getPageSelectBox [line 1171]

string getPageSelectBox( [array $params = array()], [string $extraAttributes = ''])

Returns a string with a XHTML SELECT menu with the page numbers, useful as an alternative to the links



Tags:

return:  xhtml select box
access:  public


Parameters:

string   $extraAttributes   (html attributes) Tag attributes or HTML attributes (id="foo" pairs), will be inserted in the <select> tag
array   $params   - 'optionText': text to show in each option. Use '%d' where you want to see the number of pages selected.
  • 'autoSubmit': if TRUE, add some js code to submit the form on the onChange event

[ Top ]

method getPerPageSelectBox [line 1147]

string getPerPageSelectBox( [integer $start = 5], [integer $end = 30], [integer $step = 5], [boolean $showAllData = false], [array $extraParams = array()])

Returns a string with a XHTML SELECT menu,

useful for letting the user choose how many items per page should be displayed. If parameter useSessions is TRUE, this value is stored in a session var. The string isn't echoed right now so you can use it with template engines.




Tags:

return:  xhtml select box
access:  public


Parameters:

integer   $start  
integer   $end  
integer   $step  
boolean   $showAllData   If true, perPage is set equal to totalItems.
array   $extraParams   (or string $optionText for BC reasons)
  • 'optionText': text to show in each option. Use '%d' where you want to see the number of pages selected.
  • 'attributes': (html attributes) Tag attributes or HTML attributes (id="foo" pairs), will be inserted in the <select> tag

[ Top ]

method getPreviousPageID [line 636]

mixed getPreviousPageID( )

Returns previous page ID. If current page is first page this function returns FALSE



Tags:

return:  Previous pages' ID


[ Top ]

method isFirstPage [line 675]

bool isFirstPage( )

Returns whether current page is first page



Tags:

return:  First page or not


[ Top ]

method isLastPage [line 688]

bool isLastPage( )

Returns whether current page is last page



Tags:

return:  Last page or not


[ Top ]

method isLastPageComplete [line 701]

bool isLastPageComplete( )

Returns whether last page is complete



Tags:

return:  Last age complete or not


[ Top ]

method numItems [line 649]

int numItems( )

Returns number of items



Tags:

return:  Number of items


[ Top ]

method numPages [line 662]

int numPages( )

Returns number of pages



Tags:

return:  Number of pages


[ Top ]

method raiseError [line 1342]

void raiseError( string $msg, int $code)

conditionally includes PEAR base class and raise an error



Tags:

access:  private


Parameters:

string   $msg   Error message
int   $code   Error code

[ Top ]

method setOptions [line 1362]

integer setOptions( mixed $options)

Set and sanitize options



Tags:

return:  error code (PAGER_OK on success)
access:  public


Parameters:

mixed   $options   An associative array of option names and their values.

[ Top ]

method _generateFormOnClick [line 801]

string _generateFormOnClick( string $formAction, array $data)

Mimics http_build_query() behavior in the way the data in $data will appear when it makes it back to the server.

For example: $arr = array('array' => array(array('hello', 'world'), 'things' => array('stuff', 'junk')); http_build_query($arr) and _generateFormOnClick('foo.php', $arr) will yield $_REQUEST['array'][0][0] === 'hello' $_REQUEST['array'][0][1] === 'world' $_REQUEST['array']['things'][0] === 'stuff' $_REQUEST['array']['things'][1] === 'junk'

However, instead of generating a query string, it generates Javascript to create and submit a form.




Tags:

return:  A string of javascript that generates a form and submits it
access:  private


Parameters:

string   $formAction   where the form should be submitted
array   $data   the associative array of names and values

[ Top ]

method _generateFormOnClickHelper [line 846]

string _generateFormOnClickHelper( data $data, [prev $prev = ''])

This is used by _generateFormOnClick().

Recursively processes the arrays, objects, and literal values.




Tags:

return:  A string of Javascript that creates form inputs representing the data
access:  private


Parameters:

data   $data   Data that should be rendered
prev   $prev   The name so far

[ Top ]

method _generatePageData [line 713]

void _generatePageData( )

Calculates all page data



Tags:

access:  private


[ Top ]

method _getBackLink [line 962]

string _getBackLink( [$url $url = ''], [$link $link = ''])

Returns back link



Tags:

return:  The link
access:  private


Parameters:

$url   $url   URL to use in the link [deprecated: use the factory instead]
$link   $link   HTML to use as the link [deprecated: use the factory instead]

[ Top ]

method _getFirstLinkTag [line 1036]

string _getFirstLinkTag( )



Tags:

access:  private


[ Top ]

method _getLastLinkTag [line 1094]

string _getLastLinkTag( )



Tags:

return:  the link tag
access:  private


[ Top ]

method _getLinksData [line 887]

array _getLinksData( )

Returns the correct link for the back/pages/next links



Tags:

return:  Data
access:  private


[ Top ]

method _getLinkTagUrl [line 1113]

string _getLinkTagUrl( $pageID)

Helper method



Tags:

return:  the link tag url
access:  private


Parameters:

   $pageID  

[ Top ]

method _getNextLink [line 1009]

string _getNextLink( [$url $url = ''], [$link $link = ''])

Returns next link



Tags:

return:  The link
access:  private


Parameters:

$url   $url   URL to use in the link [deprecated: use the factory instead]
$link   $link   HTML to use as the link [deprecated: use the factory instead]

[ Top ]

method _getNextLinkTag [line 1076]

string _getNextLinkTag( )

Returns next link tag



Tags:

return:  the link tag
access:  private


[ Top ]

method _getPageLinks [line 991]

string _getPageLinks( [$url $url = ''])

Returns pages link



Tags:

return:  Links
access:  private


Overridden in child classes as:

Pager_Sliding::_getPageLinks()
Returns pages link
Pager_Jumping::_getPageLinks()
Returns pages link

Parameters:

$url   $url   URL to use in the link [deprecated: use the factory instead]

[ Top ]

method _getPrevLinkTag [line 1056]

string _getPrevLinkTag( )

Returns previous link tag



Tags:

return:  the link tag
access:  private


[ Top ]

method _http_build_query_wrapper [line 1257]

string _http_build_query_wrapper( array $data)

This is a slightly modified version of the http_build_query() function; it heavily borrows code from PHP_Compat's http_build_query().

The main change is the usage of htmlentities instead of urlencode, since it's too aggressive




Tags:

author:  Stephan Schmidt <schst@php.net>
author:  Aidan Lister <aidan@php.net>
author:  Lorenzo Alberton <dot alberton at quipo dot it l dot alberton at quipo dot it>
access:  private


Parameters:

array   $data  

[ Top ]

method _isEncoded [line 1326]

boolean _isEncoded( string $string)

Helper function

Check if a string is an encoded multibyte string




Tags:

access:  private


Parameters:

string   $string  

[ Top ]

method _printFirstPage [line 1188]

string _printFirstPage( )

Print [1]



Tags:

return:  String with link to 1st page, or empty string if this is the 1st page.
access:  private


[ Top ]

method _printLastPage [line 1210]

string _printLastPage( )

Print [numPages()]



Tags:

return:  String with link to last page, or empty string if this is the 1st page.
access:  private


[ Top ]

method _recursive_stripslashes [line 920]

void _recursive_stripslashes( &$var, mixed $var)

Helper method



Tags:

access:  private


Parameters:

mixed   $var  
   &$var  

[ Top ]

method _recursive_urldecode [line 939]

void _recursive_urldecode( &$var, mixed $var)

Helper method



Tags:

access:  private


Parameters:

mixed   $var  
   &$var  

[ Top ]

method _renderLink [line 747]

string _renderLink( altText $altText, linkText $linkText)

Renders a link using the appropriate method



Tags:

return:  The link in string form
access:  private


Parameters:

altText   $altText   Alternative text for this link (title property)
linkText   $linkText   Text contained by this link

[ Top ]

method _setFirstLastText [line 1231]

void _setFirstLastText( )

sets the private _firstPageText, _lastPageText variables based on whether they were set in the options



Tags:

access:  private


[ Top ]

method __http_build_query [line 1293]

void __http_build_query( $array, $name)

Helper function



Tags:

author:  Aidan Lister <aidan@php.net>
author:  Stephan Schmidt <schst@php.net>
access:  private


Parameters:

   $array  
   $name  

[ Top ]


Documentation generated on Thu, 12 Jun 2008 13:08:32 -0500 by phpDocumentor 1.4.1