1
|
|
|
<?php |
2
|
|
|
namespace Mezon\Gui\ListBuilder; |
3
|
|
|
|
4
|
|
|
use Mezon\Gui\WidgetsRegistry\BootstrapWidgets; |
5
|
|
|
use Mezon\TemplateEngine\TemplateEngine; |
6
|
|
|
use Mezon\Transport\Request; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class Simple |
10
|
|
|
* |
11
|
|
|
* @package GUI |
12
|
|
|
* @subpackage ListBuilder |
13
|
|
|
* @author Dodonov A.A. |
14
|
|
|
* @version v.1.0 (2020/12/19) |
15
|
|
|
* @copyright Copyright (c) 2020, http://aeon.su |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class constructs grids |
20
|
|
|
*/ |
21
|
|
|
class Simple extends Base |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Method compiles listing items cells |
26
|
|
|
* |
27
|
|
|
* @return string Compiled row |
28
|
|
|
*/ |
29
|
|
|
private function listingItemsCells(): string |
30
|
|
|
{ |
31
|
|
|
$content = ''; |
32
|
|
|
|
33
|
|
|
foreach (array_keys($this->getFields()) as $name) { |
34
|
|
|
if ($name == 'domain_id') { |
35
|
|
|
continue; |
36
|
|
|
} |
37
|
|
|
if ($name == 'id') { |
38
|
|
|
$content .= BootstrapWidgets::get('listing-row-centered-cell'); |
39
|
|
|
} else { |
40
|
|
|
$content .= BootstrapWidgets::get('listing-row-cell'); |
41
|
|
|
} |
42
|
|
|
$content = str_replace('{name}', '{' . $name . '}', $content); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $content; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Method compiles header cells |
50
|
|
|
* |
51
|
|
|
* @return string Compiled header |
52
|
|
|
*/ |
53
|
|
|
private function listingHeaderCells(): string |
54
|
|
|
{ |
55
|
|
|
$content = ''; |
56
|
|
|
|
57
|
|
|
foreach ($this->getFields() as $name => $data) { |
58
|
|
|
if ($name == 'domain_id') { |
59
|
|
|
continue; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$idStyle = $name == 'id' ? 'style="text-align: center; width:5%;"' : ''; |
63
|
|
|
|
64
|
|
|
$content .= BootstrapWidgets::get('listing-header-cell'); |
65
|
|
|
$content = str_replace([ |
66
|
|
|
'{id-style}', |
67
|
|
|
'{title}' |
68
|
|
|
], [ |
69
|
|
|
$idStyle, |
70
|
|
|
$data['title'] |
71
|
|
|
], $content); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $content; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Method compiles listing header |
79
|
|
|
* |
80
|
|
|
* @return string Compiled header |
81
|
|
|
*/ |
82
|
|
|
private function simpleListingHeader(): string |
83
|
|
|
{ |
84
|
|
|
$content = BootstrapWidgets::get('simple-listing-header'); |
85
|
|
|
|
86
|
|
|
$content = str_replace([ |
87
|
|
|
'{list-description}', |
88
|
|
|
'{list-title}' |
89
|
|
|
], [ |
90
|
|
|
Request::getParam('list-description', $this->listDescription), |
91
|
|
|
$this->listTitle |
92
|
|
|
], $content); |
93
|
|
|
|
94
|
|
|
return str_replace('{cells}', $this->listingHeaderCells(), $content); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Method compiles listing items |
99
|
|
|
* |
100
|
|
|
* @param array $records |
101
|
|
|
* List of records |
102
|
|
|
* @return string Compiled simple list |
103
|
|
|
*/ |
104
|
|
|
private function simpleListingItems(array $records): string |
105
|
|
|
{ |
106
|
|
|
$content = ''; |
107
|
|
|
|
108
|
|
|
foreach ($records as $record) { |
109
|
|
|
$content .= str_replace('{items}', $this->listingItemsCells(), BootstrapWidgets::get('listing-row')); |
110
|
|
|
|
111
|
|
|
$record = $this->transformRecord($record); |
112
|
|
|
|
113
|
|
|
$record = $this->getListBuilderAdapter()->preprocessListItem($record); |
114
|
|
|
|
115
|
|
|
$content = TemplateEngine::printRecord($content, $record); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return $content; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Method compiles simple_listing form |
123
|
|
|
* |
124
|
|
|
* @return string Compiled simple listing form |
125
|
|
|
*/ |
126
|
|
|
public function listingForm(): string |
127
|
|
|
{ |
128
|
|
|
$records = $this->getListBuilderAdapter()->all(); |
129
|
|
|
|
130
|
|
|
if (! empty($records)) { |
131
|
|
|
$header = $this->simpleListingHeader(); |
132
|
|
|
|
133
|
|
|
$items = $this->simpleListingItems($records); |
134
|
|
|
|
135
|
|
|
// they are the same with full feature listing |
136
|
|
|
$footer = BootstrapWidgets::get('listing-footer'); |
137
|
|
|
|
138
|
|
|
return $header . $items . $footer; |
139
|
|
|
} else { |
140
|
|
|
return $this->getNoItemsContent(); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|