API16

JPagination/ construct: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Constructor. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> </span> ...
 
m preparing for archive only
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
Constructor.
Constructor.


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JPagination/__construct|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JPagination/__construct}}
 
 


===Syntax===
===Syntax===
Line 91: Line 89:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JPagination/__construct|Edit See Also]]<nowiki>]</nowiki>
 
</span>
{{SeeAlso:JPagination/__construct}}


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=__construct
  category=__construct
  category=JPagination
  category=JPagination
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>

Latest revision as of 01:56, 25 March 2017

Description

Constructor.



Syntax

__construct($total, $limitstart, $limit, $prefix= '')
Parameter Name Default Value Description
$total The total number of items.
$limitstart The offset of the item to start at.
$limit The number of items to display per page.
$prefix The prefix used for request variables.

Defined in

libraries/joomla/html/pagination.php

Importing

jimport( 'joomla.html.pagination' );

Source Body

function __construct($total, $limitstart, $limit, $prefix = '')
{
        // Value/type checking.
        $this->total            = (int) $total;
        $this->limitstart       = (int) max($limitstart, 0);
        $this->limit            = (int) max($limit, 0);
        $this->prefix           = $prefix;

        if ($this->limit > $this->total) {
                $this->limitstart = 0;
        }

        if (!$this->limit)
        {
                $this->limit = $total;
                $this->limitstart = 0;
        }

        /*
         * If limitstart is greater than total (i.e. we are asked to display records that don't exist)
         * then set limitstart to display the last natural page of results
         */
        if ($this->limitstart > $this->total - $this->limit) {
                $this->limitstart = max(0, (int)(ceil($this->total / $this->limit) - 1) * $this->limit);
        }

        // Set the total pages and current page values.
        if ($this->limit > 0)
        {
                $this->set('pages.total', ceil($this->total / $this->limit));
                $this->set('pages.current', ceil(($this->limitstart + 1) / $this->limit));
        }

        // Set the pagination iteration loop values.
        $displayedPages = 10;
        $this->set('pages.start', (floor(($this->get('pages.current') -1) / $displayedPages)) * $displayedPages +1);
        if ($this->get('pages.start') + $displayedPages -1 < $this->get('pages.total')) {
                $this->set('pages.stop', $this->get('pages.start') + $displayedPages -1);
        }
        else {
                $this->set('pages.stop', $this->get('pages.total'));
        }

        // If we are viewing all records set the view all flag to true.
        if ($this->limit == $total) {
                $this->_viewall = true;
        }
}



Examples

Code Examples