-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basic.php
270 lines (239 loc) · 7.75 KB
/
Basic.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
/*
* @author Mirel Nicu Mitache <mirel.mitache@gmail.com>
* @package MPF Framework
* @link http://www.mpfframework.com
* @category core package
* @version 1.0
* @since MPF Framework Version 1.0
* @copyright Copyright © 2011 Mirel Mitache
* @license http://www.mpfframework.com/licence
*
* This file is part of MPF Framework.
*
* MPF Framework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MPF Framework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MPF Framework. If not, see <http://www.gnu.org/licenses/>.
*/
namespace mpf\widgets\datatable\columns;
use mpf\base\MPFObject;
use mpf\web\AssetsPublisher;
use mpf\web\helpers\Form;
use mpf\web\helpers\Html;
use mpf\widgets\datatable\Table;
/**
* Description of Text
*
* @author mirel
*/
class Basic extends MPFObject
{
/**
* Name of the model. Sent by Table widget.
* @var \mpf\datasources\DataProvider
*/
public $dataProvider;
/**
* Column name
* @var string
*/
public $name;
/**
* A filter to be used, can be false for no filter, null for default text input
* or an actuall HTML Code with that can be filled in the column.
* @var mixed
*/
public $filter;
/**
* Can be a php code to be evaluated by "eval()" method or a callback method that gets $row and $table as a param
* @var string|callback
*/
public $value;
/**
* List of html options for current column
* @var string[]
*/
public $htmlOptions = array();
/**
* List of html options for header column
* @var string[]
*/
public $headerHtmlOptions = array();
/**
* List of html options for filter column
* @var string[]
*/
public $filterHtmlOptions = array();
/**
* Used to add a global class for data, header and filters rows
* @var string
*/
public $htmlClass = '';
/**
* Show or hide current column
* @var boolean
*/
public $visible = true;
/**
* Column label to be used in header. If none is selected it will search in Model labels.
* @var string
*/
public $label;
/**
* Text to be shown when there is no value available
* @var string
*/
public $noValueText = ' ';
/**
* Set it to false to not allow order or to string to specify custom order column name.
* @var boolean|string
*/
public $order = true;
/**
* Arrow up icon used for order
* @var string
*/
public $iconArrowUp = '%MPF_ASSETS%images/oxygen/%SIZE%/actions/arrow-up.png';
/**
* Arrow down icon used for order.
* @var string
*/
public $iconArrowDown = '%MPF_ASSETS%images/oxygen/%SIZE%/actions/arrow-down.png';
/**
* Icons size in PX.
* @var int
*/
public $iconSize = 16;
/**
* Return true if column is visible, false if not.
* @return boolean
*/
public function isVisible()
{
return $this->visible;
}
/**
* Return string to be used in the header of the table for current column.
* If none is defined it will search in Model::getLabels() if none is found
* there it will generate one using the name of the column.
* @return string
*/
public function getLabel()
{
if ($this->label)
return $this->label;
return $this->dataProvider->getLabel($this->name);
}
/**
* Returns column value for the specific row
* @param string [string] $row
* @param Table $table
* @return string
*/
public function getValue($row, Table $table)
{
if (!$this->value)
return $row->{$this->name};
if (is_string($this->value)) {
$res = '';
eval("\$res = {$this->value};");
return $res;
} elseif (is_callable($this->value)) {
return call_user_func($this->value, $row, $table);
}
}
/**
* Get HTML table filter for selected column;
* @return string
*/
public function getFilter()
{
if (false === $this->filter) {
return '';
}
if (is_array($this->filter)) {
return Form::get()->select($this->dataProvider->filtersKey . '[' . $this->name . ']', $this->filter, null, array(), '');
}
if (is_string($this->filter) && (strlen($this->filter) > 10)){
return $this->filter;
}
return Form::get()->input($this->dataProvider->filtersKey . '[' . $this->name . ']');
}
/**
* Return html options for header;
* @return string
*/
public function getHeaderHtmlOptions()
{
$r = '';
if ($this->htmlClass) {
$this->headerHtmlOptions['class'] = (isset($this->headerHtmlOptions['class']) ? $this->headerHtmlOptions['class'] . ' ' : '') . $this->htmlClass;
}
foreach ($this->headerHtmlOptions as $k => $v)
$r .= "$k = '$v' ";
return $r;
}
/**
* Return html options for filter;
* @return string
*/
public function getFilterHtmlOptions()
{
$r = '';
if ($this->htmlClass) {
$this->filterHtmlOptions['class'] = (isset($this->filterHtmlOptions['class']) ? $this->filterHtmlOptions['class'] . ' ' : '') . $this->htmlClass;
}
foreach ($this->filterHtmlOptions as $k => $v)
$r .= "$k = '$v' ";
return $r;
}
/**
* Return html options for cell;
* @return string
*/
public function getHtmlOptions()
{
$r = '';
if ($this->htmlClass) {
$this->htmlOptions['class'] = (isset($this->htmlOptions['class']) ? $this->htmlOptions['class'] . ' ' : '') . $this->htmlClass;
}
foreach ($this->htmlOptions as $k => $v)
$r .= "$k = '$v' ";
return $r;
}
/**
* Get HTML code for header
* @param Table $table
* @return string
*/
public function getHeaderCode(\mpf\widgets\datatable\Table $table)
{
$label = $this->getLabel();
if (!$this->order) {
return $label;
}
$order = $this->dataProvider->getOrder();
$prefix = '';
$this->iconArrowUp = str_replace(array('%DATATABLE_ASSETS%', '%SIZE%'), array($table->getAssetsURL(), ($this->iconSize . 'x' . $this->iconSize)), $this->iconArrowUp);
$this->iconArrowDown = str_replace(array('%DATATABLE_ASSETS%', '%SIZE%'), array($table->getAssetsURL(), ($this->iconSize . 'x' . $this->iconSize)), $this->iconArrowDown);
if ('%MPF_ASSETS%' == substr($this->iconArrowUp, 0, 12)) {
$this->iconArrowUp = AssetsPublisher::get()->mpfAssetFile(substr($this->iconArrowUp, 12));
}
if ('%MPF_ASSETS%' == substr($this->iconArrowDown, 0, 12)) {
$this->iconArrowDown = AssetsPublisher::get()->mpfAssetFile(substr($this->iconArrowDown, 12));
}
if ($order[0] == (is_string($this->order) ? $this->order : '`' . $this->name . '`')) {
$prefix = ('ASC' == $order[1]) ? Html::get()->image($this->iconArrowUp, 'Order Descendent', ['class' => 'order-by-img']) : Html::get()->image($this->iconArrowDown, 'Order Ascendent', ['class' => 'order-by-img']);
}
return $this->dataProvider->getColumnOrderLink(is_string($this->order) ? $this->order : '`' . $this->name . '`', $prefix . $label);
}
}