DefaultTemplate::nextEnabled()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Pagerfanta package.
5
 *
6
 * (c) Pablo Díez <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Pagerfanta\View\Template;
13
14
/**
15
 * @author Pablo Díez <[email protected]>
16
 */
17
class DefaultTemplate extends Template
18
{
19
    static protected $defaultOptions = array(
20
        'prev_message'   => 'Previous',
21
        'next_message'       => 'Next',
22
        'css_disabled_class' => 'disabled',
23
        'css_dots_class'     => 'dots',
24
        'css_current_class'  => 'current',
25
        'dots_text'          => '...',
26
        'container_template' => '<nav>%pages%</nav>',
27
        'page_template'      => '<a href="%href%"%rel%>%text%</a>',
28
        'span_template'      => '<span class="%class%">%text%</span>',
29
        'rel_previous'        => 'prev',
30
        'rel_next'            => 'next'
31
    );
32
33 11
    public function container()
34
    {
35 11
        return $this->option('container_template');
36
    }
37
38 11
    public function page($page)
39
    {
40 11
        $text = $page;
41
42 11
        return $this->pageWithText($page, $text);
43
    }
44
45 11
    public function pageWithText($page, $text, $rel = null)
46
    {
47 11
        $search = array('%href%', '%text%', '%rel%');
48
49 11
        $href = $this->generateRoute($page);
50 11
        $replace = $rel ? array($href, $text, ' rel="' . $rel . '"') : array($href, $text, '');
51
52 11
        return str_replace($search, $replace, $this->option('page_template'));
53
    }
54
55 3
    public function previousDisabled()
56
    {
57 3
        return $this->generateSpan($this->option('css_disabled_class'), $this->option('prev_message'));
58
    }
59
60 8
    public function previousEnabled($page)
61
    {
62 8
        return $this->pageWithText($page, $this->option('prev_message'), $this->option('rel_previous'));
63
    }
64
65 1
    public function nextDisabled()
66
    {
67 1
        return $this->generateSpan($this->option('css_disabled_class'), $this->option('next_message'));
68
    }
69
70 10
    public function nextEnabled($page)
71
    {
72 10
        return $this->pageWithText($page, $this->option('next_message'), $this->option('rel_next'));
73
    }
74
75 8
    public function first()
76
    {
77 8
        return $this->page(1);
78
    }
79
80 10
    public function last($page)
81
    {
82 10
        return $this->page($page);
83
    }
84
85 11
    public function current($page)
86
    {
87 11
        return $this->generateSpan($this->option('css_current_class'), $page);
88
    }
89
90 11
    public function separator()
91
    {
92 11
        return $this->generateSpan($this->option('css_dots_class'), $this->option('dots_text'));
93
    }
94
95 11
    private function generateSpan($class, $page)
96
    {
97 11
        $search = array('%class%', '%text%');
98 11
        $replace = array($class, $page);
99
100 11
        return str_replace($search, $replace, $this->option('span_template'));
101
    }
102
}
103