-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckColumn.php
113 lines (94 loc) · 2.55 KB
/
CheckColumn.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
<?php
namespace bvanleeuwen1995\checkColumn;
use yii\grid\DataColumn;
class CheckColumn extends DataColumn
{
/**
* @inherit doc
*/
public $format = 'raw';
/**
* The content of the success button
* @var string
*/
public $successContent = "<i class=\"fa fa-check\" aria-hidden=\"true\"></i>";
/**
* The classes of the success button
* @var string
*/
public $successClass = "btn btn-xs btn-success";
/**
* The content of the danger button
* @var string
*/
public $dangerContent = "<i class=\"fa fa-times\" aria-hidden=\"true\"></i>";
/**
* The classes of the danger button
* @var string
*/
public $dangerClass = "btn btn-xs btn-danger";
/**
* The value we expect when the attribute has a success value
* @var mixed
*/
public $successValue = 1;
/**
* The value we expect when the attribute has a danger value
* @var mixed
*/
public $dangerValue = 0;
/**
* The text the success label has
* @var string
*/
public $successLabel = 'Active';
/**
* The text the danger label has
* @var string
*/
public $dangerLabel = 'Inactive';
/**
* The prompt label
* @var string
*/
public $promptLabel = 'Choose status';
/**
* @inheritdoc
*/
public function init()
{
// Set the filter options based on the info we have
$this->filter = [
$this->successValue => $this->successLabel,
$this->dangerValue => $this->dangerLabel,
];
$this->filterInputOptions = [
'prompt' => $this->promptLabel,
'class' => 'form-control',
'id' => null
];
// Get the view
$view = $this->grid->getView();
ActiveCheckColumnAsset::register($view);
return parent::init(); // TODO: Change the autogenerated stub
}
/**
* Render the cell content with the checkboxes
*
* @param mixed $model
* @param mixed $key
* @param int $index
* @return string
*/
public function renderDataCellContent($model, $key, $index)
{
// Get the attribute for this cell
$sAttribute = $this->attribute;
// Check if we have the positive value
if ($model->$sAttribute == $this->successValue) {
return '<div class="'.$this->successClass.'">'.$this->successContent.'</div>';
} else {
return '<div class="'.$this->dangerClass.'">'.$this->dangerContent.'</div>';
}
}
}