Сменить вид пагинации?

Тема в разделе "K2", создана пользователем mrDobryj, 25.12.2009.

  1. Offline

    mrDobryj Недавно здесь

    Регистрация:
    23.12.2009
    Сообщения:
    18
    Симпатии:
    0
    Пол:
    Мужской
    Подскажите как сменить вид пагинации.
     
  2.  
  3. Offline

    botanist Активист => Cпециалист <=

    Регистрация:
    15.02.2009
    Сообщения:
    461
    Симпатии:
    49
    Пол:
    Мужской
    \libraries\joomla\html\pagination.php
    или
    твой_шаблон/html/pagination.php
     
  4. Offline

    mrDobryj Недавно здесь

    Регистрация:
    23.12.2009
    Сообщения:
    18
    Симпатии:
    0
    Пол:
    Мужской
    Это для К2?

    Мне надо вот такую пагинацию 1|2|3|4

    Я в коде слаб. Подскажите что нужно изменить и начто?
     
  5. Offline

    mrDobryj Недавно здесь

    Регистрация:
    23.12.2009
    Сообщения:
    18
    Симпатии:
    0
    Пол:
    Мужской
    Вот код моего pagination.php :

    Код (CODE):
    1. <?php
    2. /**
    3.  * @version     $Id: pagination.php 13242 2009-10-20 03:54:55Z ian $
    4.  * @package     Joomla.Framework
    5.  * @subpackage  HTML
    6.  * @copyright   Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
    7.  * @license     GNU/GPL, see LICENSE.php
    8.  * Joomla! is free software. This version may have been modified pursuant
    9.  * to the GNU General Public License, and as distributed it includes or
    10.  * is derivative of works licensed under the GNU General Public License or
    11.  * other free or open source software licenses.
    12.  * See COPYRIGHT.php for copyright notices and details.
    13.  */
    14.  
    15. // Check to ensure this file is within the rest of the framework
    16. defined('JPATH_BASE') or die();
    17.  
    18. /**
    19.  * Pagination Class.  Provides a common interface for content pagination for the
    20.  * Joomla! Framework
    21.  *
    22.  * @package     Joomla.Framework
    23.  * @subpackage  HTML
    24.  * @since       1.5
    25.  */
    26. class JPagination extends JObject
    27. {
    28.     /**
    29.      * The record number to start dislpaying from
    30.      *
    31.      * @access public
    32.      * @var int
    33.      */
    34.     var $limitstart = null;
    35.  
    36.     /**
    37.      * Number of rows to display per page
    38.      *
    39.      * @access public
    40.      * @var int
    41.      */
    42.     var $limit = null;
    43.  
    44.     /**
    45.      * Total number of rows
    46.      *
    47.      * @access public
    48.      * @var int
    49.      */
    50.     var $total = null;
    51.  
    52.     /**
    53.      * View all flag
    54.      *
    55.      * @access protected
    56.      * @var boolean
    57.      */
    58.     var $_viewall = false;
    59.  
    60.     /**
    61.      * Constructor
    62.      *
    63.      * @param   int     The total number of items
    64.      * @param   int     The offset of the item to start at
    65.      * @param   int     The number of items to display per page
    66.      */
    67.     function __construct($total, $limitstart, $limit)
    68.     {
    69.         // Value/Type checking
    70.         $this->total        = (int) $total;
    71.         $this->limitstart   = (int) max($limitstart, 0);
    72.         $this->limit        = (int) max($limit, 0);
    73.  
    74.         if ($this->limit > $this->total) {
    75.             $this->limitstart = 0;
    76.         }
    77.  
    78.         if (!$this->limit)
    79.         {
    80.             $this->limit = $total;
    81.             $this->limitstart = 0;
    82.         }
    83.  
    84.         if ($this->limitstart > $this->total) {
    85.             $this->limitstart -= $this->limitstart % $this->limit;
    86.         }
    87.  
    88.         // Set the total pages and current page values
    89.         if($this->limit > 0)
    90.         {
    91.             $this->set( 'pages.total', ceil($this->total / $this->limit));
    92.             $this->set( 'pages.current', ceil(($this->limitstart + 1) / $this->limit));
    93.         }
    94.  
    95.         // Set the pagination iteration loop values
    96.         $displayedPages = 10;
    97.         $this->set( 'pages.start', (floor(($this->get('pages.current') -1) / $displayedPages)) * $displayedPages +1);
    98.         if ($this->get('pages.start') + $displayedPages -1 < $this->get('pages.total')) {
    99.             $this->set( 'pages.stop', $this->get('pages.start') + $displayedPages -1);
    100.         } else {
    101.             $this->set( 'pages.stop', $this->get('pages.total'));
    102.         }
    103.  
    104.         // If we are viewing all records set the view all flag to true
    105.         if ($this->limit == $total) {
    106.             $this->_viewall = true;
    107.         }
    108.     }
    109.  
    110.     /**
    111.      * Return the rationalised offset for a row with a given index.
    112.      *
    113.      * @access  public
    114.      * @param   int     $index The row index
    115.      * @return  int     Rationalised offset for a row with a given index
    116.      * @since   1.5
    117.      */
    118.     function getRowOffset($index)
    119.     {
    120.         return $index +1 + $this->limitstart;
    121.     }
    122.  
    123.     /**
    124.      * Return the pagination data object, only creating it if it doesn't already exist
    125.      *
    126.      * @access  public
    127.      * @return  object  Pagination data object
    128.      * @since   1.5
    129.      */
    130.     function getData()
    131.     {
    132.         static $data;
    133.         if (!is_object($data)) {
    134.             $data = $this->_buildDataObject();
    135.         }
    136.         return $data;
    137.     }
    138.  
    139.     /**
    140.      * Create and return the pagination pages counter string, ie. Page 2 of 4
    141.      *
    142.      * @access  public
    143.      * @return  string  Pagination pages counter string
    144.      * @since   1.5
    145.      */
    146.     function getPagesCounter()
    147.     {
    148.         // Initialize variables
    149.         $html = null;
    150.         if ($this->get('pages.total') > 1) {
    151.             $html .= JText::sprintf('JPAGE_CURRENT_OF_TOTAL', $this->get('pages.current'), $this->get('pages.total'));
    152.         }
    153.         return $html;
    154.     }
    155.  
    156.     /**
    157.      * Create and return the pagination result set counter string, ie. Results 1-10 of 42
    158.      *
    159.      * @access  public
    160.      * @return  string  Pagination result set counter string
    161.      * @since   1.5
    162.      */
    163.     function getResultsCounter()
    164.     {
    165.         // Initialize variables
    166.         $html = null;
    167.         $fromResult = $this->limitstart + 1;
    168.  
    169.         // If the limit is reached before the end of the list
    170.         if ($this->limitstart + $this->limit < $this->total) {
    171.             $toResult = $this->limitstart + $this->limit;
    172.         } else {
    173.             $toResult = $this->total;
    174.         }
    175.  
    176.         // If there are results found
    177.         if ($this->total > 0) {
    178.             $msg = JText::sprintf('Results of', $fromResult, $toResult, $this->total);
    179.             $html .= "\n".$msg;
    180.         } else {
    181.             $html .= "\n".JText::_('No records found');
    182.         }
    183.  
    184.         return $html;
    185.     }
    186.  
    187.     /**
    188.      * Create and return the pagination page list string, ie. Previous, Next, 1 2 3 ... x
    189.      *
    190.      * @access  public
    191.      * @return  string  Pagination page list string
    192.      * @since   1.0
    193.      */
    194.     function getPagesLinks()
    195.     {
    196.         global $mainframe;
    197.  
    198.         $lang =& JFactory::getLanguage();
    199.  
    200.         // Build the page navigation list
    201.         $data = $this->_buildDataObject();
    202.  
    203.         $list = array();
    204.  
    205.         $itemOverride = false;
    206.         $listOverride = false;
    207.  
    208.         $chromePath = JPATH_THEMES.DS.$mainframe->getTemplate().DS.'html'.DS.'pagination.php';
    209.         if (file_exists($chromePath))
    210.         {
    211.             require_once ($chromePath);
    212.             if (function_exists('pagination_item_active') && function_exists('pagination_item_inactive')) {
    213.                 $itemOverride = true;
    214.             }
    215.             if (function_exists('pagination_list_render')) {
    216.                 $listOverride = true;
    217.             }
    218.         }
    219.  
    220.         // Build the select list
    221.         if ($data->all->base !== null) {
    222.             $list['all']['active'] = true;
    223.             $list['all']['data'] = ($itemOverride) ? pagination_item_active($data->all) : $this->_item_active($data->all);
    224.         } else {
    225.             $list['all']['active'] = false;
    226.             $list['all']['data'] = ($itemOverride) ? pagination_item_inactive($data->all) : $this->_item_inactive($data->all);
    227.         }
    228.  
    229.         if ($data->start->base !== null) {
    230.             $list['start']['active'] = true;
    231.             $list['start']['data'] = ($itemOverride) ? pagination_item_active($data->start) : $this->_item_active($data->start);
    232.         } else {
    233.             $list['start']['active'] = false;
    234.             $list['start']['data'] = ($itemOverride) ? pagination_item_inactive($data->start) : $this->_item_inactive($data->start);
    235.         }
    236.         if ($data->previous->base !== null) {
    237.             $list['previous']['active'] = true;
    238.             $list['previous']['data'] = ($itemOverride) ? pagination_item_active($data->previous) : $this->_item_active($data->previous);
    239.         } else {
    240.             $list['previous']['active'] = false;
    241.             $list['previous']['data'] = ($itemOverride) ? pagination_item_inactive($data->previous) : $this->_item_inactive($data->previous);
    242.         }
    243.  
    244.         $list['pages'] = array(); //make sure it exists
    245.         foreach ($data->pages as $i => $page)
    246.         {
    247.             if ($page->base !== null) {
    248.                 $list['pages'][$i]['active'] = true;
    249.                 $list['pages'][$i]['data'] = ($itemOverride) ? pagination_item_active($page) : $this->_item_active($page);
    250.             } else {
    251.                 $list['pages'][$i]['active'] = false;
    252.                 $list['pages'][$i]['data'] = ($itemOverride) ? pagination_item_inactive($page) : $this->_item_inactive($page);
    253.             }
    254.         }
    255.  
    256.         if ($data->next->base !== null) {
    257.             $list['next']['active'] = true;
    258.             $list['next']['data'] = ($itemOverride) ? pagination_item_active($data->next) : $this->_item_active($data->next);
    259.         } else {
    260.             $list['next']['active'] = false;
    261.             $list['next']['data'] = ($itemOverride) ? pagination_item_inactive($data->next) : $this->_item_inactive($data->next);
    262.         }
    263.         if ($data->end->base !== null) {
    264.             $list['end']['active'] = true;
    265.             $list['end']['data'] = ($itemOverride) ? pagination_item_active($data->end) : $this->_item_active($data->end);
    266.         } else {
    267.             $list['end']['active'] = false;
    268.             $list['end']['data'] = ($itemOverride) ? pagination_item_inactive($data->end) : $this->_item_inactive($data->end);
    269.         }
    270.  
    271.         if($this->total > $this->limit){
    272.             return ($listOverride) ? pagination_list_render($list) : $this->_list_render($list);
    273.         }
    274.         else{
    275.             return '';
    276.         }
    277.     }
    278.  
    279.     /**
    280.      * Return the pagination footer
    281.      *
    282.      * @access  public
    283.      * @return  string  Pagination footer
    284.      * @since   1.0
    285.      */
    286.     function getListFooter()
    287.     {
    288.         global $mainframe;
    289.  
    290.         $list = array();
    291.         $list['limit']          = $this->limit;
    292.         $list['limitstart']     = $this->limitstart;
    293.         $list['total']          = $this->total;
    294.         $list['limitfield']     = $this->getLimitBox();
    295.         $list['pagescounter']   = $this->getPagesCounter();
    296.         $list['pageslinks']     = $this->getPagesLinks();
    297.  
    298.         $chromePath     = JPATH_THEMES.DS.$mainframe->getTemplate().DS.'html'.DS.'pagination.php';
    299.         if (file_exists( $chromePath ))
    300.         {
    301.             require_once( $chromePath );
    302.             if (function_exists( 'pagination_list_footer' )) {
    303.                 return pagination_list_footer( $list );
    304.             }
    305.         }
    306.         return $this->_list_footer($list);
    307.     }
    308.  
    309.     /**
    310.      * Creates a dropdown box for selecting how many records to show per page
    311.      *
    312.      * @access  public
    313.      * @return  string  The html for the limit # input box
    314.      * @since   1.0
    315.      */
    316.     function getLimitBox()
    317.     {
    318.         global $mainframe;
    319.  
    320.         // Initialize variables
    321.         $limits = array ();
    322.  
    323.         // Make the option list
    324.         for ($i = 5; $i <= 30; $i += 5) {
    325.             $limits[] = JHTML::_('select.option', "$i");
    326.         }
    327.         $limits[] = JHTML::_('select.option', '50');
    328.         $limits[] = JHTML::_('select.option', '100');
    329.         $limits[] = JHTML::_('select.option', '0', JText::_('all'));
    330.  
    331.         $selected = $this->_viewall ? 0 : $this->limit;
    332.  
    333.         // Build the select list
    334.         if ($mainframe->isAdmin()) {
    335.             $html = JHTML::_('select.genericlist',  $limits, 'limit', 'class="inputbox" size="1" onchange="submitform();"', 'value', 'text', $selected);
    336.         } else {
    337.             $html = JHTML::_('select.genericlist',  $limits, 'limit', 'class="inputbox" size="1" onchange="this.form.submit()"', 'value', 'text', $selected);
    338.         }
    339.         return $html;
    340.     }
    341.  
    342.     /**
    343.      * Return the icon to move an item UP
    344.      *
    345.      * @access  public
    346.      * @param   int     $i The row index
    347.      * @param   boolean $condition True to show the icon
    348.      * @param   string  $task The task to fire
    349.      * @param   string  $alt The image alternate text string
    350.      * @return  string  Either the icon to move an item up or a space
    351.      * @since   1.0
    352.      */
    353.     function orderUpIcon($i, $condition = true, $task = 'orderup', $alt = 'Move Up', $enabled = true)
    354.     {
    355.         $alt = JText::_($alt);
    356.  
    357.         $html = '&nbsp;';
    358.         if (($i > 0 || ($i + $this->limitstart > 0)) && $condition)
    359.         {
    360.             if($enabled) {
    361.                 $html   = '<a href="#reorder" onclick="return listItemTask(\'cb'.$i.'\',\''.$task.'\')" title="'.$alt.'">';
    362.                 $html   .= '   <img src="images/uparrow.png" width="16" height="16" border="0" alt="'.$alt.'" />';
    363.                 $html   .= '</a>';
    364.             } else {
    365.                 $html   = '<img src="images/uparrow0.png" width="16" height="16" border="0" alt="'.$alt.'" />';
    366.             }
    367.         }
    368.  
    369.         return $html;
    370.     }
    371.  
    372.     /**
    373.      * Return the icon to move an item DOWN
    374.      *
    375.      * @access  public
    376.      * @param   int     $i The row index
    377.      * @param   int     $n The number of items in the list
    378.      * @param   boolean $condition True to show the icon
    379.      * @param   string  $task The task to fire
    380.      * @param   string  $alt The image alternate text string
    381.      * @return  string  Either the icon to move an item down or a space
    382.      * @since   1.0
    383.      */
    384.     function orderDownIcon($i, $n, $condition = true, $task = 'orderdown', $alt = 'Move Down', $enabled = true)
    385.     {
    386.         $alt = JText::_($alt);
    387.  
    388.         $html = '&nbsp;';
    389.         if (($i < $n -1 || $i + $this->limitstart < $this->total - 1) && $condition)
    390.         {
    391.             if($enabled) {
    392.                 $html   = '<a href="#reorder" onclick="return listItemTask(\'cb'.$i.'\',\''.$task.'\')" title="'.$alt.'">';
    393.                 $html   .= '  <img src="images/downarrow.png" width="16" height="16" border="0" alt="'.$alt.'" />';
    394.                 $html   .= '</a>';
    395.             } else {
    396.                 $html   = '<img src="images/downarrow0.png" width="16" height="16" border="0" alt="'.$alt.'" />';
    397.             }
    398.         }
    399.  
    400.         return $html;
    401.     }
    402.  
    403.     function _list_footer($list)
    404.     {
    405.         // Initialize variables
    406.         $html = "<div class=\"list-footer\">\n";
    407.  
    408.         $html .= "\n<div class=\"limit\">".JText::_('Display Num').$list['limitfield']."</div>";
    409.         $html .= $list['pageslinks'];
    410.         $html .= "\n<div class=\"counter\">".$list['pagescounter']."</div>";
    411.  
    412.         $html .= "\n<input type=\"hidden\" name=\"limitstart\" value=\"".$list['limitstart']."\" />";
    413.         $html .= "\n</div>";
    414.  
    415.         return $html;
    416.     }
    417.  
    418.     function _list_render($list)
    419.     {
    420.         // Initialize variables
    421.         $html = null;
    422.  
    423.         // Reverse output rendering for right-to-left display
    424.         $html .= '&lt;&lt; ';
    425.         $html .= $list['start']['data'];
    426.         $html .= ' &lt; ';
    427.         $html .= $list['previous']['data'];
    428.         foreach( $list['pages'] as $page ) {
    429.             $html .= ' '.$page['data'];
    430.         }
    431.         $html .= ' '. $list['next']['data'];
    432.         $html .= ' &gt;';
    433.         $html .= ' '. $list['end']['data'];
    434.         $html .= ' &gt;&gt;';
    435.  
    436.         return $html;
    437.     }
    438.  
    439.     function _item_active(&$item)
    440.     {
    441.         global $mainframe;
    442.         if ($mainframe->isAdmin())
    443.         {
    444.             if($item->base>0)
    445.                 return "<a title=\"".$item->text."\" onclick=\"javascript: document.adminForm.limitstart.value=".$item->base."; submitform();return false;\">".$item->text."</a>";
    446.             else
    447.                 return "<a title=\"".$item->text."\" onclick=\"javascript: document.adminForm.limitstart.value=0; submitform();return false;\">".$item->text."</a>";
    448.         } else {
    449.             return "<a title=\"".$item->text."\" href=\"".$item->link."\" class=\"pagenav\">".$item->text."</a>";
    450.         }
    451.     }
    452.  
    453.     function _item_inactive(&$item)
    454.     {
    455.         global $mainframe;
    456.         if ($mainframe->isAdmin()) {
    457.             return "<span>".$item->text."</span>";
    458.         } else {
    459.             return "<span class=\"pagenav\">".$item->text."</span>";
    460.         }
    461.     }
    462.  
    463.     /**
    464.      * Create and return the pagination data object
    465.      *
    466.      * @access  public
    467.      * @return  object  Pagination data object
    468.      * @since   1.5
    469.      */
    470.     function _buildDataObject()
    471.     {
    472.         // Initialize variables
    473.         $data = new stdClass();
    474.  
    475.         $data->all  = new JPaginationObject(JText::_('View All'));
    476.         if (!$this->_viewall) {
    477.             $data->all->base    = '0';
    478.             $data->all->link    = JRoute::_("&limitstart=");
    479.         }
    480.  
    481.         // Set the start and previous data objects
    482.         $data->start    = new JPaginationObject(JText::_('Start'));
    483.         $data->previous = new JPaginationObject(JText::_('Prev'));
    484.  
    485.         if ($this->get('pages.current') > 1)
    486.         {
    487.             $page = ($this->get('pages.current') -2) * $this->limit;
    488.  
    489.             $page = $page == 0 ? '' : $page; //set the empty for removal from route
    490.  
    491.             $data->start->base  = '0';
    492.             $data->start->link  = JRoute::_("&limitstart=");
    493.             $data->previous->base   = $page;
    494.             $data->previous->link   = JRoute::_("&limitstart=".$page);
    495.         }
    496.  
    497.         // Set the next and end data objects
    498.         $data->next = new JPaginationObject(JText::_('Next'));
    499.         $data->end  = new JPaginationObject(JText::_('End'));
    500.  
    501.         if ($this->get('pages.current') < $this->get('pages.total'))
    502.         {
    503.             $next = $this->get('pages.current') * $this->limit;
    504.             $end  = ($this->get('pages.total') -1) * $this->limit;
    505.  
    506.             $data->next->base   = $next;
    507.             $data->next->link   = JRoute::_("&limitstart=".$next);
    508.             $data->end->base    = $end;
    509.             $data->end->link    = JRoute::_("&limitstart=".$end);
    510.         }
    511.  
    512.         $data->pages = array();
    513.         $stop = $this->get('pages.stop');
    514.         for ($i = $this->get('pages.start'); $i <= $stop; $i ++)
    515.         {
    516.             $offset = ($i -1) * $this->limit;
    517.  
    518.             $offset = $offset == 0 ? '' : $offset;  //set the empty for removal from route
    519.  
    520.             $data->pages[$i] = new JPaginationObject($i);
    521.             if ($i != $this->get('pages.current') || $this->_viewall)
    522.             {
    523.                 $data->pages[$i]->base  = $offset;
    524.                 $data->pages[$i]->link  = JRoute::_("&limitstart=".$offset);
    525.             }
    526.         }
    527.         return $data;
    528.     }
    529. }
    530.  
    531. /**
    532.  * Pagination object representing a particular item in the pagination lists
    533.  *
    534.  * @package     Joomla.Framework
    535.  * @subpackage  HTML
    536.  * @since       1.5
    537.  */
    538. class JPaginationObject extends JObject
    539. {
    540.     var $text;
    541.     var $base;
    542.     var $link;
    543.  
    544.     function __construct($text, $base=null, $link=null)
    545.     {
    546.         $this->text = $text;
    547.         $this->base = $base;
    548.         $this->link = $link;
    549.     }
    550. }
     
    Последнее редактирование модератором: 27.12.2009

Поделиться этой страницей

Загрузка...