Guest User

Untitled

a guest
Jan 21st, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Nette Framework Extras
  5. *
  6. * This source file is subject to the New BSD License.
  7. *
  8. * For more information please see http://extras.nettephp.com
  9. *
  10. * @copyright Copyright (c) 2009 David Grudl
  11. * @license New BSD License
  12. * @link http://extras.nettephp.com
  13. * @package Nette Extras
  14. * @version $Id: VisualPaginator.php 4 2009-07-14 15:22:02Z [email protected] $
  15. */
  16.  
  17. namespace TachoScan\Addons;
  18.  
  19. use Nette\Application\UI\Control;
  20. use Nette\Utils\Paginator;
  21.  
  22.  
  23.  
  24.  
  25. /**
  26. * Visual paginator control.
  27. *
  28. * @author David Grudl
  29. * @copyright Copyright (c) 2009 David Grudl
  30. * @package Nette Extras
  31. */
  32. class VisualPaginator extends Control
  33. {
  34. /** @var Paginator */
  35. private $paginator;
  36.  
  37. /** @persistent */
  38. public $page = 1;
  39.  
  40.  
  41.  
  42. /**
  43. * @return Nette\Paginator
  44. */
  45. public function getPaginator()
  46. {
  47. if (!$this->paginator) {
  48. $this->paginator = new Paginator;
  49. }
  50. return $this->paginator;
  51. }
  52.  
  53.  
  54.  
  55. /**
  56. * Renders paginator.
  57. * @return void
  58. */
  59. public function render()
  60. {
  61. $paginator = $this->getPaginator();
  62. $page = $paginator->page;
  63. if ($paginator->pageCount < 2) {
  64. $steps = array($page);
  65.  
  66. } else {
  67. $arr = range(max($paginator->firstPage, $page - 3), min($paginator->lastPage, $page + 3));
  68. $count = 4;
  69. $quotient = ($paginator->pageCount - 1) / $count;
  70. for ($i = 0; $i <= $count; $i++) {
  71. $arr[] = round($quotient * $i) + $paginator->firstPage;
  72. }
  73. sort($arr);
  74. $steps = array_values(array_unique($arr));
  75. }
  76.  
  77. $this->template->steps = $steps;
  78. $this->template->paginator = $paginator;
  79. $this->template->setFile(dirname(__FILE__) . '/template.phtml');
  80. $this->template->render();
  81. }
  82.  
  83.  
  84.  
  85. /**
  86. * Loads state informations.
  87. * @param array
  88. * @return void
  89. */
  90. public function loadState(array $params)
  91. {
  92. parent::loadState($params);
  93. $this->getPaginator()->page = $this->page;
  94. }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment