Permalink
Browse files

first commit

  • Loading branch information...
juzna committed Jul 31, 2012
0 parents commit 34ecf370288ccb272c48d78faf0d78ead809d53f
Showing with 185 additions and 0 deletions.
  1. +92 −0 VisualPaginator.php
  2. +31 −0 composer.json
  3. +32 −0 example.css
  4. +30 −0 template.phtml
@@ -0,0 +1,92 @@
+<?php
+
+/**
+ * Nette Framework Extras
+ *
+ * This source file is subject to the New BSD License.
+ *
+ * For more information please see http://extras.nettephp.com
+ *
+ * @copyright Copyright (c) 2009 David Grudl
+ * @license New BSD License
+ * @link http://extras.nettephp.com
+ * @package Nette Extras
+ * @version $Id: VisualPaginator.php 4 2009-07-14 15:22:02Z david@grudl.com $
+ */
+
+use Nette\Application\UI\Control;
+use Nette\Utils\Paginator;
+
+
+/**
+ * Visual paginator control.
+ *
+ * @author David Grudl
+ * @copyright Copyright (c) 2009 David Grudl
+ * @package Nette Extras
+ */
+class VisualPaginator extends Control
+{
+ /** @var Paginator */
+ private $paginator;
+
+ /** @persistent */
+ public $page = 1;
+
+
+
+ /**
+ * @return Nette\Paginator
+ */
+ public function getPaginator()
+ {
+ if (!$this->paginator) {
+ $this->paginator = new Paginator;
+ }
+ return $this->paginator;
+ }
+
+
+
+ /**
+ * Renders paginator.
+ * @return void
+ */
+ public function render()
+ {
+ $paginator = $this->getPaginator();
+ $page = $paginator->page;
+ if ($paginator->pageCount < 2) {
+ $steps = array($page);
+
+ } else {
+ $arr = range(max($paginator->firstPage, $page - 3), min($paginator->lastPage, $page + 3));
+ $count = 4;
+ $quotient = ($paginator->pageCount - 1) / $count;
+ for ($i = 0; $i <= $count; $i++) {
+ $arr[] = round($quotient * $i) + $paginator->firstPage;
+ }
+ sort($arr);
+ $steps = array_values(array_unique($arr));
+ }
+
+ $this->template->steps = $steps;
+ $this->template->paginator = $paginator;
+ $this->template->setFile(dirname(__FILE__) . '/template.phtml');
+ $this->template->render();
+ }
+
+
+
+ /**
+ * Loads state informations.
+ * @param array
+ * @return void
+ */
+ public function loadState(array $params)
+ {
+ parent::loadState($params);
+ $this->getPaginator()->page = $this->page;
+ }
+
+}
@@ -0,0 +1,31 @@
+{
+ "name": "juzna/nette-VisualPaginator",
+ "description": "Simple paginator",
+ "keywords": ["paginator", "nette"],
+ "homepage": "http://addons.nette.org/cs/visualpaginator",
+ "license": "BSD-3",
+ "authors": [
+ {
+ "name": "David Grudl",
+ "email": "david@grudl.com"
+ },
+ {
+ "name": "Jan Dolecek",
+ "email": "juzna.cz@gmail.com"
+ }
+ ],
+ "autoload": {
+ "classmap": [ "VisualPaginator.php" ]
+ },
+ "require": {
+ "nette/nette": "2.0.*"
+ },
+ "extra": {
+ "nette": {
+ "assets": { },
+ "assets-optional": {
+ "css": [ "example.css" ]
+ }
+ }
+ }
+}
@@ -0,0 +1,32 @@
+/*
+ (c) 2009 David Grudl. All rights reserved.
+*/
+
+
+.paginator {
+ margin: 1em 0;
+ font-size: 90%;
+}
+
+.paginator a, .paginator span {
+ margin-right: 0.1em;
+ padding: 0.2em 0.5em;
+ color: #999999;
+}
+
+.paginator a {
+ border: 1px solid #9AAFE5;
+ text-decoration: none;
+ color: #105CB6;
+}
+
+.paginator span.button {
+ border: 1px solid #DDDDDD;
+}
+
+.paginator .current {
+ background: #2E6AB1;
+ border: 1px solid #2E6AB1;
+ color: white;
+ font-weight: bold;
+}
@@ -0,0 +1,30 @@
+{*
+ * @version $Id: template.phtml 2 2009-07-13 20:58:52Z david@grudl.com $
+ * @param Paginator $paginator
+ * @param array $steps
+ *}
+
+{if $paginator->pageCount > 1}
+<div class="paginator">
+ {if $paginator->isFirst()}
+ <span class="button">« Previous</span>
+ {else}
+ <a href="{link this, 'page' => $paginator->page - 1}">« Previous</a>
+ {/if}
+
+ {foreach $steps as $step}
+ {if $step == $paginator->page}
+ <span class="current">{$step}</span>
+ {else}
+ <a href="{link this, 'page' => $step}">{$step}</a>
+ {/if}
+ {if $iterator->nextValue > $step + 1}<span>…</span>{/if}
+ {/foreach}
+
+ {if $paginator->isLast()}
+ <span class="button">Next »</span>
+ {else}
+ <a href="{link this, 'page' => $paginator->page + 1}">Next »</a>
+ {/if}
+</div>
+{/if}

0 comments on commit 34ecf37

Please sign in to comment.