1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace carono\exchange1c\widgets; |
5
|
|
|
|
6
|
|
|
use carono\exchange1c\models\TestingClass; |
7
|
|
|
use yii\grid\ActionColumn; |
8
|
|
|
use yii\grid\GridView; |
9
|
|
|
use yii\helpers\Html; |
10
|
|
|
|
11
|
|
|
class TestingGridView extends GridView |
12
|
|
|
{ |
13
|
|
|
public function init() |
14
|
|
|
{ |
15
|
|
|
$this->rowOptions = function ($data) { |
16
|
|
|
/** |
17
|
|
|
* @var TestingClass $data |
18
|
|
|
*/ |
19
|
|
|
$result = $data->testing(); |
20
|
|
|
if (($result === true || $data->hasResult()) && !$data->hasErrors()) { |
21
|
|
|
return ['class' => 'success']; |
22
|
|
|
} elseif ($result === false || $data->hasErrors()) { |
23
|
|
|
return ['class' => 'danger']; |
24
|
|
|
} else { |
25
|
|
|
return ['class' => 'warning']; |
26
|
|
|
} |
27
|
|
|
}; |
28
|
|
|
|
29
|
|
|
$this->columns = [ |
30
|
|
|
'name', |
31
|
|
|
'expect', |
32
|
|
|
[ |
33
|
|
|
'attribute' => 'comment', |
34
|
|
|
'value' => function ($data) { |
35
|
|
|
/** |
36
|
|
|
* @var TestingClass $data |
37
|
|
|
*/ |
38
|
|
|
if ($data->hasErrors()) { |
39
|
|
|
return Html::errorSummary($data); |
40
|
|
|
} |
41
|
|
|
return $data->comment; |
42
|
|
|
} |
43
|
|
|
], |
44
|
|
|
[ |
45
|
|
|
'class' => ActionColumn::className(), |
46
|
|
|
'header' => 'Result', |
47
|
|
|
'template' => '{view}', |
48
|
|
|
'buttons' => [ |
49
|
|
|
'view' => function ($url, $data) { |
50
|
|
|
/** |
51
|
|
|
* @var TestingClass $data |
52
|
|
|
*/ |
53
|
|
|
if ($data->method && !$data->isAutoTest()) { |
54
|
|
|
$span = Html::tag('i', '', [ |
55
|
|
|
'class' => 'glyphicon glyphicon-eye-open', |
56
|
|
|
'title' => "Выполнить метод {$data->method}" |
57
|
|
|
]); |
58
|
|
|
return Html::a($span, [ |
59
|
|
|
'testing/index', |
60
|
|
|
'class' => (new \ReflectionClass($data))->getShortName(), |
61
|
|
|
'result' => $data->method |
62
|
|
|
]); |
63
|
|
|
} else { |
64
|
|
|
return $data->result; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
] |
68
|
|
|
] |
69
|
|
|
]; |
70
|
|
|
parent::init(); |
71
|
|
|
} |
72
|
|
|
} |