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 Loïc Frémont <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class SemanticUiTemplate extends Template |
18
|
|
|
{ |
19
|
|
|
static protected $defaultOptions = array( |
20
|
|
|
'prev_message' => '← Previous', |
21
|
|
|
'next_message' => 'Next →', |
22
|
|
|
'dots_message' => '…', |
23
|
|
|
'active_suffix' => '', |
24
|
|
|
'css_container_class' => 'ui stackable fluid pagination menu', |
25
|
|
|
'css_item_class' => 'item', |
26
|
|
|
'css_prev_class' => 'prev', |
27
|
|
|
'css_next_class' => 'next', |
28
|
|
|
'css_disabled_class' => 'disabled', |
29
|
|
|
'css_dots_class' => 'disabled', |
30
|
|
|
'css_active_class' => 'active', |
31
|
|
|
); |
32
|
|
|
|
33
|
10 |
|
public function container() |
34
|
|
|
{ |
35
|
10 |
|
return sprintf('<div class="%s">%%pages%%</div>', |
36
|
10 |
|
$this->option('css_container_class') |
37
|
10 |
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
10 |
|
public function page($page) |
41
|
|
|
{ |
42
|
10 |
|
$text = $page; |
43
|
|
|
|
44
|
10 |
|
return $this->pageWithText($page, $text); |
45
|
|
|
} |
46
|
|
|
|
47
|
10 |
|
public function pageWithText($page, $text) |
48
|
|
|
{ |
49
|
10 |
|
$class = null; |
50
|
|
|
|
51
|
10 |
|
return $this->pageWithTextAndClass($page, $text, $class); |
52
|
|
|
} |
53
|
|
|
|
54
|
10 |
|
private function pageWithTextAndClass($page, $text, $class) |
55
|
|
|
{ |
56
|
10 |
|
$href = $this->generateRoute($page); |
57
|
|
|
|
58
|
10 |
|
return $this->link($class, $href, $text); |
59
|
|
|
} |
60
|
|
|
|
61
|
2 |
|
public function previousDisabled() |
62
|
|
|
{ |
63
|
2 |
|
$class = $this->previousDisabledClass(); |
64
|
2 |
|
$text = $this->option('prev_message'); |
65
|
|
|
|
66
|
2 |
|
return $this->div($class, $text); |
67
|
|
|
} |
68
|
|
|
|
69
|
2 |
|
private function previousDisabledClass() |
70
|
|
|
{ |
71
|
2 |
|
return $this->option('css_prev_class').' '.$this->option('css_disabled_class'); |
72
|
|
|
} |
73
|
|
|
|
74
|
8 |
|
public function previousEnabled($page) |
75
|
|
|
{ |
76
|
8 |
|
$text = $this->option('prev_message'); |
77
|
8 |
|
$class = $this->option('css_prev_class'); |
78
|
|
|
|
79
|
8 |
|
return $this->pageWithTextAndClass($page, $text, $class); |
80
|
|
|
} |
81
|
|
|
|
82
|
1 |
|
public function nextDisabled() |
83
|
|
|
{ |
84
|
1 |
|
$class = $this->nextDisabledClass(); |
85
|
1 |
|
$text = $this->option('next_message'); |
86
|
|
|
|
87
|
1 |
|
return $this->div($class, $text); |
88
|
|
|
} |
89
|
|
|
|
90
|
1 |
|
private function nextDisabledClass() |
91
|
|
|
{ |
92
|
1 |
|
return $this->option('css_next_class').' '.$this->option('css_disabled_class'); |
93
|
|
|
} |
94
|
|
|
|
95
|
9 |
|
public function nextEnabled($page) |
96
|
|
|
{ |
97
|
9 |
|
$text = $this->option('next_message'); |
98
|
9 |
|
$class = $this->option('css_next_class'); |
99
|
|
|
|
100
|
9 |
|
return $this->pageWithTextAndClass($page, $text, $class); |
101
|
|
|
} |
102
|
|
|
|
103
|
7 |
|
public function first() |
104
|
|
|
{ |
105
|
7 |
|
return $this->page(1); |
106
|
|
|
} |
107
|
|
|
|
108
|
8 |
|
public function last($page) |
109
|
|
|
{ |
110
|
8 |
|
return $this->page($page); |
111
|
|
|
} |
112
|
|
|
|
113
|
10 |
|
public function current($page) |
114
|
|
|
{ |
115
|
10 |
|
$text = trim($page.' '.$this->option('active_suffix')); |
116
|
10 |
|
$class = $this->option('css_active_class'); |
117
|
|
|
|
118
|
10 |
|
return $this->div($class, $text); |
119
|
|
|
} |
120
|
|
|
|
121
|
10 |
|
public function separator() |
122
|
|
|
{ |
123
|
10 |
|
$class = $this->option('css_dots_class'); |
124
|
10 |
|
$text = $this->option('dots_message'); |
125
|
|
|
|
126
|
10 |
|
return $this->div($class, $text); |
127
|
|
|
} |
128
|
|
|
|
129
|
10 |
|
private function link($class, $href, $text) |
130
|
|
|
{ |
131
|
10 |
|
$item_class = $this->option('css_item_class'); |
132
|
|
|
|
133
|
10 |
|
return sprintf('<a class="%s %s" href="%s">%s</a>', $item_class, $class, $href, $text); |
134
|
|
|
} |
135
|
|
|
|
136
|
10 |
|
private function div($class, $text) |
137
|
|
|
{ |
138
|
10 |
|
$item_class = $this->option('css_item_class'); |
139
|
|
|
|
140
|
10 |
|
return sprintf('<div class="%s %s">%s</div>', $item_class, $class, $text); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|