1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) CJT TERABYTE INC |
5
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @link: https://gitlab.com/cjtterabytesoft/tadweb |
9
|
|
|
* @author: Wilmer Arámbula <[email protected]> |
10
|
|
|
* @copyright: (c) CJT TERABYTE INC |
11
|
|
|
* @widgets: [ToolBar] |
12
|
|
|
* @since: 1.0 |
13
|
|
|
* @yii: 3.0 |
14
|
|
|
**/ |
15
|
|
|
|
16
|
|
|
namespace cjtterabytesoft\widgets; |
17
|
|
|
|
18
|
|
|
use yii\base\Widget; |
19
|
|
|
use yii\bootstrap4\ButtonDropdown; |
20
|
|
|
use yii\helpers\ArrayHelper; |
21
|
|
|
use yii\helpers\Html; |
22
|
|
|
use yii\helpers\Url; |
23
|
|
|
|
24
|
|
|
class ToolBar extends Widget |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var string the tag to use to render panel title |
28
|
|
|
*/ |
29
|
|
|
public $_tag_container_panel_header = 'div'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array the options to use to render panel title |
33
|
|
|
*/ |
34
|
|
|
public $_options_container_panel_header = ['class' => 'peers bg-primary text-white align-content-center p-15']; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string the tag to use to render panel title left |
38
|
|
|
*/ |
39
|
|
|
public $_tag_left_panel_header = 'div'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var array the options to use to render panel title left |
43
|
|
|
*/ |
44
|
|
|
public $_options_left_panel_header = ['class' => 'float-left']; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string the tag to use to render panel title rigth |
48
|
|
|
*/ |
49
|
|
|
public $_tag_rigth_panel_header = 'div'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var array the options to use to render panel title rigth |
53
|
|
|
*/ |
54
|
|
|
public $_options_rigth_panel_header = ['class' => 'float-right ml-auto']; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string use to panel header title |
58
|
|
|
*/ |
59
|
|
|
public $_panel_header_title = ''; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var string the tag to use to render panel title icon |
63
|
|
|
*/ |
64
|
|
|
public $_tag_icon_panel = 'i'; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var string the label to use to render panel title icon |
68
|
|
|
*/ |
69
|
|
|
public $_label_icon_panel = ''; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var array the options to use to render panel title icons |
73
|
|
|
*/ |
74
|
|
|
public $_options_icon_panel = ['class' => 'fas fa-th']; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var string the label panel title |
78
|
|
|
*/ |
79
|
|
|
public $_title_panel = ''; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var bool Show/Hidden Summary Label |
83
|
|
|
*/ |
84
|
|
|
public $_summary = false; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var string the tag to use to render container panel button |
88
|
|
|
*/ |
89
|
|
|
public $_tag_container_panel_button = 'div'; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var array the options to use to render container panel button |
93
|
|
|
*/ |
94
|
|
|
public $_options_container_panel_button = ['class' => 'peers bd p-15']; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var string the tag to use to render panel button left |
98
|
|
|
*/ |
99
|
|
|
public $_tag_left_panel_button = 'div'; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var array the options to use to render panel button left |
103
|
|
|
*/ |
104
|
|
|
public $_options_left_panel_button = ['class' => 'float-left']; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @var string the tag to use to render panel button rigth |
108
|
|
|
*/ |
109
|
|
|
public $_tag_rigth_panel_button = 'div'; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @var array the options to use to render panel button rigth |
113
|
|
|
*/ |
114
|
|
|
public $_options_rigth_panel_button = ['class' => 'float-right ml-auto']; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @var array Templates |
118
|
|
|
*/ |
119
|
|
|
public $_templates = []; |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @var array Buttons |
123
|
|
|
*/ |
124
|
|
|
public $_toolbar = []; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @var bool show/hidden panel button pages |
128
|
|
|
*/ |
129
|
|
|
public $_button_pages = true; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @var bool whether the label should be HTML-encoded. |
133
|
|
|
*/ |
134
|
|
|
public $_encodeLabel = true; |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Initializes the widget. |
139
|
|
|
* If you override this method, make sure you call the parent implementation first. |
140
|
|
|
*/ |
141
|
|
|
public function init() |
142
|
|
|
{ |
143
|
|
|
parent::init(); |
144
|
|
|
|
145
|
|
|
$iconpanel = $this->renderIcon(); |
146
|
|
|
$titlepanel = $this->renderTitlePanel(); |
147
|
|
|
$this->_panel_header_title = $iconpanel . ' ' . '<b>' . $titlepanel . '</b>'; |
148
|
|
|
|
149
|
|
|
echo $this->renderPanelHeader() . $this->renderPanelBar(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
private function renderButtonPages() |
153
|
|
|
{ |
154
|
|
|
$button_pages = ''; |
155
|
|
|
|
156
|
|
|
if ($this->_button_pages) { |
157
|
|
|
$button_pages = ButtonDropdown::widget([ |
158
|
|
|
'buttonOptions' => ['class' => 'btn-primary ai-c mL-2'], |
159
|
|
|
'label' => '', |
160
|
|
|
'options' => ['class' => 'float-right'], |
161
|
|
|
'dropdown' => [ |
162
|
|
|
'items' => [ |
163
|
|
|
['label' => '1', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '1'])], |
164
|
|
|
['label' => '5', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '5'])], |
165
|
|
|
['label' => '10', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '10'])], |
166
|
|
|
['label' => '20', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '20'])], |
167
|
|
|
['label' => '25', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '25'])], |
168
|
|
|
['label' => '50', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '50'])], |
169
|
|
|
], |
170
|
|
|
], |
171
|
|
|
]); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
return $button_pages; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
private function renderIcon() |
178
|
|
|
{ |
179
|
|
|
return Html::tag($this->_tag_icon_panel, $this->_label_icon_panel, $this->_options_icon_panel); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
private function renderPanelBar() |
183
|
|
|
{ |
184
|
|
|
$panel_button = Html::begintag($this->_tag_container_panel_button, $this->_options_container_panel_button) . |
185
|
|
|
$this->renderToolBar() . |
186
|
|
|
Html::endTag($this->_tag_container_panel_button); |
187
|
|
|
return $panel_button; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
private function renderPanelHeader() |
191
|
|
|
{ |
192
|
|
|
$pageSize = \yii::$app->params['defaultPageSize']; |
193
|
|
|
|
194
|
|
|
if (\yii::$app->session->get('pageSize') !== null) { |
|
|
|
|
195
|
|
|
$pageSize = \yii::$app->session->get('pageSize'); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
$summary = ($this->_summary) ? '{summary}' . ' ' . 'Records per pages: ' . '<b>' . $pageSize . '</b>' : ' '; |
199
|
|
|
|
200
|
|
|
$panel_header = Html::begintag($this->_tag_container_panel_header, $this->_options_container_panel_header) . |
201
|
|
|
Html::begintag($this->_tag_left_panel_header, $this->_options_left_panel_header) . |
202
|
|
|
$this->_panel_header_title . |
203
|
|
|
Html::endTag($this->_tag_left_panel_header) . |
204
|
|
|
Html::begintag($this->_tag_rigth_panel_header, $this->_options_rigth_panel_header) . |
205
|
|
|
$summary . |
206
|
|
|
Html::endTag($this->_tag_rigth_panel_header) . |
207
|
|
|
Html::endTag($this->_tag_container_panel_header); |
208
|
|
|
return $panel_header; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
private function renderTitlePanel() |
212
|
|
|
{ |
213
|
|
|
if (empty($this->_title_panel)) { |
214
|
|
|
$this->_title_panel = \yii::t('toolbar', 'Gridview ToolBar'); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
return $this->_title_panel; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
private function renderToolBar() |
221
|
|
|
{ |
222
|
|
|
$buttons_left = ''; |
223
|
|
|
$buttons_rigth = ''; |
224
|
|
|
|
225
|
|
|
ArrayHelper::setValue($this->_toolbar, 'pages.0', $this->renderButtonPages()); |
226
|
|
|
|
227
|
|
|
foreach ($this->_templates as $items => $buttons) { |
228
|
|
|
foreach ($buttons as $item => $button) { |
229
|
|
|
if (!empty(ArrayHelper::getValue($this->_toolbar, $button, ''))) { |
230
|
|
|
switch ($items) { |
231
|
|
|
case 'left': |
232
|
|
|
$buttons_left .= implode(',', ArrayHelper::getValue($this->_toolbar, $button, '')); |
233
|
|
|
break; |
234
|
|
|
case 'rigth': |
235
|
|
|
$buttons_rigth .= implode(',', ArrayHelper::getValue($this->_toolbar, $button, '')); |
236
|
|
|
break; |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
return Html::tag($this->_tag_left_panel_button, $buttons_left, $this->_options_left_panel_button) . |
243
|
|
|
Html::tag($this->_tag_rigth_panel_button, $buttons_rigth, $this->_options_rigth_panel_button); |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.