PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/Croogo/View/Helper/CroogoPaginatorHelper.php

https://github.com/kareypowell/croogo
PHP | 79 lines | 55 code | 13 blank | 11 comment | 4 complexity | 6bf0fceb14459d6efccf88b41157d404 MD5 | raw file
  1. <?php
  2. App::uses('PaginatorHelper', 'View/Helper');
  3. /**
  4. * Croogo Paginator Helper
  5. *
  6. * @package Croogo.Croogo.View.Helper
  7. */
  8. class CroogoPaginatorHelper extends PaginatorHelper {
  9. /**
  10. * doesn't use parent::numbers()
  11. *
  12. * @param type $options
  13. * @return boolean
  14. */
  15. public function numbers($options = array()) {
  16. $defaults = array(
  17. 'tag' => 'li',
  18. 'model' => $this->defaultModel(),
  19. 'modulus' => '8',
  20. 'class' => null
  21. );
  22. $options = array_merge($defaults, $options);
  23. extract($options);
  24. $params = $this->params($options['model']);
  25. extract($params);
  26. $begin = $page - floor($modulus / 2);
  27. $end = $begin + $modulus;
  28. if ($end > $pageCount) {
  29. $end = $pageCount + 1;
  30. $begin = $pageCount - $modulus;
  31. }
  32. $begin = $begin <= 0 ? 1 : $begin;
  33. $output = '';
  34. for ($i = $begin; $i < $end; $i++) {
  35. $class = ($i == $page) ? 'active' : '';
  36. $output .= $this->Html->tag($tag, $this->link($i, array('page' => $i), compact('class')));
  37. }
  38. return $output;
  39. }
  40. protected function _defaultOptions($options) {
  41. if (!isset($options['tag'])) {
  42. $options['tag'] = 'li';
  43. }
  44. return $options;
  45. }
  46. public function prev($title = '<< Previous', $options = array(), $disabledTitle = null, $disabledOptions = array()) {
  47. $options['escape'] = isset($options['escape']) ? $options['escape'] : false;
  48. $options = $this->_defaultOptions($options, false);
  49. return parent::prev($title, $options, $this->link($title), $disabledOptions);
  50. }
  51. public function next($title = 'Next >>', $options = array(), $disabledTitle = null, $disabledOptions = array()) {
  52. $options['escape'] = isset($options['escape']) ? $options['escape'] : false;
  53. $options = $this->_defaultOptions($options, false);
  54. return parent::next($title, $options, $this->link($title), $disabledOptions);
  55. }
  56. public function first($first = '<< first', $options = array()) {
  57. $options['escape'] = isset($options['escape']) ? $options['escape'] : true;
  58. $options = $this->_defaultOptions($options);
  59. return parent::first($first, $options);
  60. }
  61. public function last($last = 'last >>', $options = array()) {
  62. $options['escape'] = isset($options['escape']) ? $options['escape'] : true;
  63. $options = $this->_defaultOptions($options);
  64. return parent::last($last, $options);
  65. }
  66. }