-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbase.php
108 lines (75 loc) · 2.21 KB
/
base.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
<?php
class BaseLayout {
public $type;
public function root() {
$obj = new ReflectionClass($this);
return dirname($obj->getFileName());
}
public function __construct($type) {
$this->type = $type;
}
public function __call($method, $arguments) {
return isset($this->$method) ? $this->$method : null;
}
public function type() {
return $this->type;
}
public function input() {
return $this->field()->input($this->page()->uid());
}
public function counter() {
$page = $this->page();
if(!$page->isVisible() || !$this->limit()) {
return null;
}
$entries = $this->field()->entries()->filterBy('template', $page->intendedTemplate());
$index = $entries->visible()->indexOf($page) + 1;
$limit = $this->limit();
$counter = new Brick('span');
$counter->addClass('sortable-layout__counter');
$counter->html('( ' . $index . ' / ' . $limit . ' )');
return $counter;
}
public function l($key, $variant = null) {
return $this->field()->l($key, $variant);
}
public function icon($position = '') {
return $this->page()->icon($position);
}
public function blueprint() {
return $this->page()->blueprint();
}
public function title() {
return $this->page()->title();
}
public function action($type, $data = array()) {
$data = a::update($data, array(
'layout' => $this,
'page' => $this->page(),
));
return $this->field()->action($type, $data);
}
public function content() {
$template = $this->root() . DS . 'template.php';
if(!is_file($template)) {
$template = __DIR__ . DS . 'template.php';
}
return tpl::load($template, ['layout' => $this], true);
}
public function template() {
$template = new Brick('div');
$template->addClass('sortable__layout');
$template->attr('data-uid', $this->page()->uid());
$template->attr('data-visible', $this->page()->isVisible() ? 'true' : 'false');
$template->append($this->content());
$template->append($this->input());
return $template;
}
public function __toString() {
try {
return (string)$this->template();
} catch(Exception $e) {
return (string)$e->getMessage();
}
}
}