-
Notifications
You must be signed in to change notification settings - Fork 0
/
YiiTrivalent.php
163 lines (134 loc) · 4.63 KB
/
YiiTrivalent.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
<?php
/**
* @package yii2-grid
* @author Eduardo Silva <[email protected]> based in BooleanColumn
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015
* @version 1.0.0
*/
namespace openecommerce\yiikartiktrivalent;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
* A TrivalentColumn to convert 0-1-2 values as user friendly indicators
* with an automated drop down filter for the Grid widget [[\kartik\widgets\GridView]]
*
* @author Kartik Visweswaran <[email protected]>
* @since 1.0
*/
class TrivalentColumn extends DataColumn {
/**
* @var string the horizontal alignment of each column. Should be one of
* 'left', 'right', or 'center'. Defaults to `center`.
*/
public $hAlign = 'center';
/**
* @var string the width of each column (matches the CSS width property).
* Defaults to `90px`.
* @see http://www.w3schools.com/cssref/pr_dim_width.asp
*/
public $width = '90px';
/**
* @var string|array in which format should the value of each data model be displayed
* Defaults to `raw`.
* [[\yii\base\Formatter::format()]] or [[\yii\i18n\Formatter::format()]] is used.
*/
public $format = 'raw';
/**
* @var boolean|string|Closure the page summary that is displayed above the footer.
* Defaults to false.
*/
public $pageSummary = false;
/**
* @var integer value for the first value. Defaults to `0`.
*/
public $oneValue = 0;
/**
* @var integer value for the first value. Defaults to `1`.
*/
public $twoValue = 1;
/**
* @var integer value for the first value. Defaults to `2`.
*/
public $threeValue = 2;
/**
* @var string label for the true value. Defaults to `0`.
*/
public $oneLabel;
/**
* @var string label for the false value. Defaults to `1`.
*/
public $twoLabel;
/**
* @var string label for the false value. Defaults to `2`.
*/
public $threeLabel;
/**
* @var string icon/indicator for the true value. If this is not set, it will use the value from `trueLabel`.
* If GridView `bootstrap` property is set to true - it will default to [[GridView::ICON_ONE]]
* `<span class="glyphicon glyphicon-remove text-danger"></span>`
*/
public $oneIcon;
/**
* @var string icon/indicator for the false value. If this is null, it will use the value from `falseLabel`.
* If GridView `bootstrap` property is set to true - it will default to [[GridView::ICON_TWO]]
* `<span class="glyphicon glyphicon-pause text-danger"></span>`
*/
public $twoIcon;
/**
* @var string icon/indicator for the false value. If this is null, it will use the value from `falseLabel`.
* If GridView `bootstrap` property is set to true - it will default to [[GridView::ICON_THREE]]
* `<span class="glyphicon glyphicon-ok text-success"></span>`
*/
public $threeIcon;
/**
* @var integer whether to show null value as a one icon.
*/
public $showNullAsOne = false;
/**
* @inheritdoc
*/
public function init() {
if (empty($this->oneLabel)) {
$this->oneLabel = Yii::t('kvgrid', 'Not Started');
}
if (empty($this->twoLabel)) {
$this->twoLabel = Yii::t('kvgrid', 'In Progress');
}
if (empty($this->threeLabel)) {
$this->threeLabel = Yii::t('kvgrid', 'finished');
}
$this->filter = [$this->oneValue => $this->oneLabel, $this->twoValue => $this->twoLabel, $this->threeValue => $this->threeLabel];
if (empty($this->oneIcon)) {
$this->oneIcon = ($this->grid->bootstrap) ? GridView::ICON_TRIVALENT_ONE : $this->oneIcon;
}
if (empty($this->twoIcon)) {
$this->twoIcon = ($this->grid->bootstrap) ? GridView::ICON_TRIVALENT_TWO : $this->twoIcon;
}
if (empty($this->threeIcon)) {
$this->threeIcon = ($this->grid->bootstrap) ? GridView::ICON_TRIVALENT_THREE : $this->threeIcon;
}
parent::init();
}
/**
* @inheritdoc
*/
public function getDataCellValue($model, $key, $index) {
$value = parent::getDataCellValue($model, $key, $index);
switch ($value) {
case "0":
$response = $this->oneIcon;
break;
case "1":
$response = $this->twoIcon;
break;
case "2":
$response = $this->threeIcon;
break;
default:
$response = $this->oneIcon;
}
return $response;
}
}