-
Notifications
You must be signed in to change notification settings - Fork 4
/
subpagelist.php
executable file
·158 lines (129 loc) · 3.86 KB
/
subpagelist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* Field plugin Subpagelist
*
* @package Kirby CMS
* @author Flo Kosiol <[email protected]>
* @link http://flokosiol.de
* @version 2.0.4
*/
use Kirby\Panel\Snippet;
class SubpagelistField extends BaseField {
/**
* Assets
*/
public static $assets = array(
'css' => array(
'subpagelist.css',
),
);
/**
* Set field property and default value if required
*
* @param string $option
* @param mixed $value
*/
public function __set($option, $value) {
/* Set given value */
$this->$option = $value;
/* Validation */
switch ($option) {
case 'flip':
if (!is_bool($value))
$this->flip = false;
break;
}
}
/**
* Generate label markup
*
* @return string
*/
public function label() {
return NULL;
}
/**
* Generate field content markup
*
* @return string
*/
public function content() {
$wrapper = new Brick('div');
$wrapper->addClass('subpagelist');
$children = $this->subpages();
// add pagination to the subpages
$limit = ($this->limit()) ? $this->limit() : 10000;
$children = $children->paginated('sidebar');
$pagination = new Snippet('pagination', array(
'pagination' => $children->pagination(),
'nextUrl' => $children->pagination()->nextPageUrl(),
'prevUrl' => $children->pagination()->prevPageUrl(),
));
// use existing snippet to build the list
// @see /panel/app/src/panel/models/page/sidebar.php
$subpages = new Snippet('pages/sidebar/subpages', array(
'title' => $this->i18n($this->label),
'page' => $this->page(),
'subpages' => $children,
'addbutton' => $this->page->addButton(),
'pagination' => $pagination,
));
// use template with defined vars
$wrapper->html(tpl::load(__DIR__ . DS . 'template.php', array('subpages' => $subpages)));
return $wrapper;
}
/**
* Get subpages
*
* @return object
*/
public function subpages() {
$field = &$this;
$subpages = $this->page()->children();
// Check for filters
if (isset($this->filter) && is_array($this->filter)) {
$filter = $this->filter();
// only visible subpages
if (isset($filter['visible']) && $filter['visible'] == TRUE) {
$subpages = $subpages->visible();
}
// only invisible subpages
if (isset($filter['visible']) && $filter['visible'] == FALSE) {
$subpages = $subpages->invisible();
}
// only specific template(s)
if (!empty($filter['template'])) {
if (is_array($filter['template'])) {
$filterTemplates = $filter['template'];
$subpages = $subpages->filter(function($child) use ($filterTemplates) {
return in_array($child->template(), $filterTemplates);
});
}
else {
$subpages = $subpages->filterBy('template',$filter['template']);
}
}
// only specific intendedTemplate(s)
if (!empty($filter['intendedTemplate'])) {
if (is_array($filter['intendedTemplate'])) {
$filterTemplates = $filter['intendedTemplate'];
$subpages = $subpages->filter(function($child) use ($filterTemplates) {
return in_array($child->intendedTemplate(), $filterTemplates);
});
}
else {
$subpages = $subpages->filterBy('intendedTemplate',$filter['intendedTemplate']);
}
}
// filterBy
if (!empty($filter['filterBy']) && !empty($filter['filterMethod']) && !empty($filter['filterValue'])) {
$subpages = $subpages->filterBy($filter['filterBy'],$filter['filterMethod'],$filter['filterValue']);
}
}
// reverse order
if (isset($this->flip) && $this->flip == TRUE) {
$subpages = $subpages->flip();
}
return $subpages;
}
}