VisualPaginator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 47
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPaginator() 0 7 2
A render() 0 20 2
1
<?php
2
3
namespace App\Component;
4
5
use Nette\Application\UI\Control;
6
use Nette\Utils\Paginator;
7
8
/**
9
 * Nette Framework Extras
10
 *
11
 * This source file is subject to the New BSD License.
12
 *
13
 * For more information please see http://extras.nettephp.com
14
 *
15
 * @copyright  Copyright (c) 2009 David Grudl
16
 * @license     New BSD License
17
 * @link       http://extras.nettephp.com
18
 * @package     Nette Extras
19
 * @version     $Id: VisualPaginator.php 4 2009-07-14 15:22:02Z [email protected] $
20
 */
21
22
/**
23
 * Visual paginator control.
24
 *
25
 * @author   David Grudl
26
 * @copyright  Copyright (c) 2009 David Grudl
27
 * @package     Nette Extras
28
 */
29
class VisualPaginator extends Control
30
{
31
    /** @var string     Defined template file */
32
    private $paginatorTemplate = 'default';
33
34
    /** @var Paginator */
35
    private $paginator;
36
37
    /** @persistent */
38
    public $page = 1;
39
    
40
    /**
41
     * @return Paginator
42
     */
43
    public function getPaginator()
44
    {
45
        if (!$this->paginator) {
46
            $this->paginator = new Paginator();
47
        }
48
        return $this->paginator;
49
    }
50
51
    /**
52
     * Renders paginator.
53
     * @return void
54
     */
55
    public function render()
56
    {
57
        $paginator = $this->getPaginator();
58
        $page = $paginator->page;
59
        if ($paginator->pageCount < 2) {
60
            $steps = array($page);
61
        } else {
62
            $arr = range(max($paginator->firstPage, $page - 3), min($paginator->lastPage, $page + 3));
63
            $arr[] = $paginator->firstPage;
64
            $arr[] = $paginator->lastPage;
65
66
            sort($arr);
67
            $steps = array_values(array_unique($arr));
68
        }
69
70
        $this->template->steps = $steps;
71
        $this->template->paginator = $paginator;
72
        $this->template->setFile(dirname(__FILE__) . '/' . $this->paginatorTemplate . '.latte');
73
        $this->template->render();
74
    }
75
}
76