PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/control/code/trunk/administrator/components/com_control/libraries/jxtended/html/pagination.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 261 lines | 160 code | 31 blank | 70 comment | 39 complexity | afd515cd83ef81aa2f21c0a697170f2f MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: pagination.php 159 2009-07-08 05:49:57Z eddieajau $
  4. * @package JXtended.Libraries
  5. * @subpackage HTML
  6. * @copyright Copyright (C) 2008 - 2009 JXtended, LLC. All rights reserved.
  7. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  8. * @link http://jxtended.com
  9. */
  10. defined('JPATH_BASE') or die;
  11. jximport2('joomla.html.pagination');
  12. /**
  13. * @package JXtended
  14. * @subpackage HTML
  15. */
  16. class JXPagination extends JPagination
  17. {
  18. /**
  19. * View all flag
  20. *
  21. * @access protected
  22. * @var boolean
  23. */
  24. var $_mode = null;
  25. var $_requestVar = 'limitstart';
  26. var $_requestMode = 0;
  27. /**
  28. * Constructor
  29. *
  30. * @param int The total number of items
  31. * @param int The offset of the item to start at
  32. * @param int The number of items to display per page
  33. * @param int The mode: 0 = like frontend, 1 = like backend, null = auto-detect
  34. */
  35. function __construct($total, $limitstart, $limit, $mode = null)
  36. {
  37. if ($mode === null)
  38. {
  39. global $mainframe;
  40. $mode = $mainframe->isAdmin();
  41. }
  42. $this->_mode = (int) $mode;
  43. parent::__construct( $total, $limitstart, $limit );
  44. }
  45. function setRequestVariable($name='limitstart', $mode=0)
  46. {
  47. $this->_requestVar = $name;
  48. $this->_requestMode = $mode;
  49. }
  50. /**
  51. * Creates a dropdown box for selecting how many records to show per page
  52. *
  53. * @access public
  54. * @return string The html for the limit # input box
  55. * @since 1.0
  56. */
  57. function getLimitBox()
  58. {
  59. global $mainframe;
  60. // Initialize variables
  61. $limits = array ();
  62. // Make the option list
  63. for ($i = 5; $i <= 30; $i += 5) {
  64. $limits[] = JHTML::_('select.option', "$i");
  65. }
  66. $limits[] = JHTML::_('select.option', '50');
  67. $limits[] = JHTML::_('select.option', '100');
  68. $limits[] = JHTML::_('select.option', '0', JText::_('all'));
  69. $selected = $this->_viewall ? 0 : $this->limit;
  70. // Build the select list
  71. if ($this->_mode == 1) {
  72. $html = JHTML::_('select.genericlist', $limits, 'limit', 'class="inputbox" size="1" onchange="submitform();"', 'value', 'text', $selected);
  73. } else {
  74. $html = JHTML::_('select.genericlist', $limits, 'limit', 'class="inputbox" size="1" onchange="this.form.submit()"', 'value', 'text', $selected);
  75. }
  76. return $html;
  77. }
  78. function _item_active(&$item)
  79. {
  80. global $mainframe;
  81. if ($this->_mode == 1)
  82. {
  83. if($item->base>0)
  84. return "<a href=\"#\" title=\"".$item->text."\" onclick=\"javascript: document.adminForm.limitstart.value=".$item->base."; submitform();return false;\">".$item->text."</a>";
  85. else
  86. return "<a href=\"#\" title=\"".$item->text."\" onclick=\"javascript: document.adminForm.limitstart.value=0; submitform();return false;\">".$item->text."</a>";
  87. } else {
  88. return "<a title=\"".$item->text."\" href=\"".$item->link."\" class=\"pagenav\">".$item->text."</a>";
  89. }
  90. }
  91. function _item_inactive(&$item)
  92. {
  93. global $mainframe;
  94. if ($this->_mode == 1) {
  95. return "<span>".$item->text."</span>";
  96. } else {
  97. return "<span class=\"pagenav\">".$item->text."</span>";
  98. }
  99. }
  100. /**
  101. * Return the icon to move an item UP
  102. *
  103. * @access public
  104. * @param int $id The row index
  105. * @param int $order The ordering value for the item
  106. * @param string $task The task to fire
  107. * @param string $alt The image alternate text string
  108. * @return string Either the icon to move an item up or a space
  109. * @since 1.0
  110. */
  111. function orderUpIcon($id, $order, $task = 'orderup', $alt = '#')
  112. {
  113. // handling of default value
  114. if ($alt = '#') {
  115. $alt = JText::_('Move Up');
  116. }
  117. if ($order == 0) {
  118. $img = 'uparrow0.png';
  119. } else {
  120. if ($order < 0) {
  121. $img = 'uparrow-1.png';
  122. } else {
  123. $img = 'uparrow.png';
  124. }
  125. }
  126. $output = '<a href="javascript:void listItemTask(\'cb'.$id.'\',\''.$task.'\')" title="'.$alt.'">';
  127. $output .= '<img src="images/'.$img.'" width="16" height="16" border="0" alt="'.$alt.'" title="'.$alt.'" /></a>';
  128. return $output;
  129. }
  130. /**
  131. * Return the icon to move an item DOWN
  132. *
  133. * @access public
  134. * @param int $id The row index
  135. * @param int $order The ordering value for the item
  136. * @param string $task The task to fire
  137. * @param string $alt The image alternate text string
  138. * @return string Either the icon to move an item down or a space
  139. * @since 1.0
  140. */
  141. function orderDownIcon($id, $order, $task = 'orderdown', $alt = '#')
  142. {
  143. // handling of default value
  144. if ($alt = '#') {
  145. $alt = JText::_('Move Down');
  146. }
  147. if ($order == 0) {
  148. $img = 'downarrow0.png';
  149. } else {
  150. if ($order < 0) {
  151. $img = 'downarrow-1.png';
  152. } else {
  153. $img = 'downarrow.png';
  154. }
  155. }
  156. $output = '<a href="javascript:void listItemTask(\'cb'.$id.'\',\''.$task.'\')" title="'.$alt.'">';
  157. $output .= '<img src="images/'.$img.'" width="16" height="16" border="0" alt="'.$alt.'" title="'.$alt.'" /></a>';
  158. return $output;
  159. }
  160. /**
  161. * Create and return the pagination data object
  162. *
  163. * @access public
  164. * @return object Pagination data object
  165. * @since 1.5
  166. */
  167. function _buildDataObject()
  168. {
  169. // Initialize variables
  170. $data = new stdClass();
  171. $data->all = new JPaginationObject(JText::_('View All'));
  172. if (!$this->_viewall) {
  173. $data->all->base = '0';
  174. $data->all->link = JRoute::_('&'.$this->_requestVar.'=');
  175. }
  176. // Set the start and previous data objects
  177. $data->start = new JPaginationObject(JText::_('Start'));
  178. $data->previous = new JPaginationObject(JText::_('Prev'));
  179. if ($this->get('pages.current') > 1)
  180. {
  181. if ($this->_requestMode) {
  182. $page = ($this->get('pages.current') - 1);
  183. $start = 1;
  184. } else {
  185. $page = ($this->get('pages.current') -2) * $this->limit;
  186. $start = 0;
  187. }
  188. $page = $page == 0 ? '' : $page; //set the empty for removal from route
  189. $data->start->base = '0';
  190. $data->start->link = JRoute::_('&'.$this->_requestVar.'='.$start);
  191. $data->previous->base = $page;
  192. $data->previous->link = JRoute::_('&'.$this->_requestVar.'='.$page);
  193. }
  194. // Set the next and end data objects
  195. $data->next = new JPaginationObject(JText::_('Next'));
  196. $data->end = new JPaginationObject(JText::_('End'));
  197. if ($this->get('pages.current') < $this->get('pages.total'))
  198. {
  199. if ($this->_requestMode) {
  200. $next = ($this->get('pages.current') + 1);
  201. $end = $this->get('pages.total');
  202. } else {
  203. $next = $this->get('pages.current') * $this->limit;
  204. $end = ($this->get('pages.total') -1) * $this->limit;
  205. }
  206. $data->next->base = $next;
  207. $data->next->link = JRoute::_('&'.$this->_requestVar.'='.$next);
  208. $data->end->base = $end;
  209. $data->end->link = JRoute::_('&'.$this->_requestVar.'='.$end);
  210. }
  211. $data->pages = array();
  212. $stop = $this->get('pages.stop');
  213. for ($i = $this->get('pages.start'); $i <= $stop; $i ++)
  214. {
  215. if ($this->_requestMode) {
  216. $offset = $i;
  217. } else {
  218. $offset = ($i -1) * $this->limit;
  219. }
  220. $offset = $offset == 0 ? '' : $offset; //set the empty for removal from route
  221. $data->pages[$i] = new JPaginationObject($i);
  222. if ($i != $this->get('pages.current') || $this->_viewall)
  223. {
  224. $data->pages[$i]->base = $offset;
  225. $data->pages[$i]->link = JRoute::_('&'.$this->_requestVar.'='.$offset);
  226. }
  227. }
  228. return $data;
  229. }
  230. }