1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created for monitoring-free. |
4
|
|
|
* User: jakim <[email protected]> |
5
|
|
|
* Date: 2019-05-14 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace app\components\visualizations\widgets; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
use app\components\stats\traits\StatsAttributesTrait; |
12
|
|
|
use app\components\traits\SetAccountTrait; |
13
|
|
|
use app\modules\admin\widgets\ChangeInfoBox; |
14
|
|
|
use Yii; |
15
|
|
|
use yii\base\Widget; |
16
|
|
|
use yii\helpers\ArrayHelper; |
17
|
|
|
use yii\helpers\Html; |
18
|
|
|
|
19
|
|
|
class ChangeRowWidget extends Widget |
20
|
|
|
{ |
21
|
|
|
use SetAccountTrait, StatsAttributesTrait; |
22
|
|
|
|
23
|
|
|
public $header; |
24
|
|
|
|
25
|
|
|
public $cellCssClass = 'col-lg-3'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Config \app\components\stats\diffs\AccountDiff |
29
|
|
|
* |
30
|
|
|
* @var array|\app\components\stats\diffs\AccountDiff |
31
|
|
|
*/ |
32
|
|
|
public $diff; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var \app\components\Formatter |
36
|
|
|
*/ |
37
|
|
|
protected $formatter; |
38
|
|
|
|
39
|
|
|
public function init() |
40
|
|
|
{ |
41
|
|
|
parent::init(); |
42
|
|
|
$this->diff = Yii::createObject(ArrayHelper::merge($this->diff, [ |
43
|
|
|
'account' => $this->account, |
44
|
|
|
'statsAttributes' => array_keys($this->statsAttributes), |
45
|
|
|
])); |
46
|
|
|
$this->formatter = Yii::$app->formatter; |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function run() |
50
|
|
|
{ |
51
|
|
|
$this->renderHeader(); |
52
|
|
|
$this->renderRow(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function renderCell($attribute, $format = 'integer') |
56
|
|
|
{ |
57
|
|
|
echo "<div class=\"{$this->cellCssClass}\">"; |
58
|
|
|
echo ChangeInfoBox::widget([ |
59
|
|
|
'header' => $this->account->getAttributeLabel($attribute), |
60
|
|
|
'number' => ArrayHelper::getValue($this->diff->getData(), $attribute), |
61
|
|
|
'format' => $format, |
62
|
|
|
]); |
63
|
|
|
echo '</div>'; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function renderHeader(): void |
67
|
|
|
{ |
68
|
|
|
echo '<h2 class="page-header">'; |
69
|
|
|
echo Html::encode($this->header); |
70
|
|
|
$subtitle = sprintf(' <small>%s - %s</small>', $this->formatter->asDate($this->diff->getFrom()->getTimestamp()), $this->formatter->asDate($this->diff->getTo()->getTimestamp())); |
71
|
|
|
echo $subtitle; |
72
|
|
|
// echo '<sup><span class="fa fa-question-circle-o text-muted"></span></sup>'; |
73
|
|
|
echo '</h2>'; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
protected function renderRow(): void |
77
|
|
|
{ |
78
|
|
|
echo '<div class="row">'; |
79
|
|
|
foreach ($this->statsAttributes as $attribute => $format) { |
80
|
|
|
$this->renderCell($attribute, $format); |
81
|
|
|
} |
82
|
|
|
echo '</div>'; |
83
|
|
|
} |
84
|
|
|
} |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.