1 | <?php |
||
23 | use yii\helpers\Html; |
||
24 | |||
25 | class PlanGridView extends \hipanel\grid\BoxedGridView |
||
26 | { |
||
27 | public function columns(): array |
||
28 | { |
||
29 | return array_merge(parent::columns(), [ |
||
30 | 'client' => [ |
||
31 | 'class' => ClientColumn::class, |
||
32 | ], |
||
33 | 'name' => [ |
||
34 | 'attribute' => 'name', |
||
35 | 'filterAttribute' => 'name_ilike', |
||
36 | 'filterOptions' => ['class' => 'narrow-filter'], |
||
37 | 'class' => MainColumn::class, |
||
38 | 'note' => 'note', |
||
39 | 'noteOptions' => [ |
||
40 | 'url' => Url::to(['@plan/set-note']), |
||
41 | ], |
||
42 | 'badges' => function (Plan $model): string { |
||
43 | return $this->prepareBadges($model); |
||
44 | }, |
||
45 | ], |
||
46 | 'simple_name' => [ |
||
47 | 'attribute' => 'name', |
||
48 | 'format' => 'html', |
||
49 | 'value' => function (Plan $model): string { |
||
50 | return sprintf('%s %s', $model->name, $this->prepareBadges($model)); |
||
51 | }, |
||
52 | ], |
||
53 | 'state' => [ |
||
54 | 'attribute' => 'state', |
||
55 | 'class' => RefColumn::class, |
||
56 | 'filterAttribute' => 'state', |
||
57 | 'filterOptions' => ['class' => 'narrow-filter'], |
||
58 | 'format' => 'html', |
||
59 | 'gtype' => 'state,tariff', |
||
60 | ], |
||
61 | 'type' => [ |
||
62 | 'attribute' => 'type', |
||
63 | 'class' => RefColumn::class, |
||
64 | 'filterAttribute' => 'type_in', |
||
65 | 'filterOptions' => ['class' => 'narrow-filter'], |
||
66 | 'format' => 'html', |
||
67 | 'gtype' => 'type,tariff', |
||
68 | ], |
||
69 | 'actions' => [ |
||
70 | 'class' => MenuColumn::class, |
||
71 | 'menuClass' => PlanActionsMenu::class, |
||
72 | ], |
||
73 | 'monthly' => [ |
||
74 | 'attribute' => 'monthly', |
||
75 | 'contentOptions' => ['id' => 'plan-monthly-value'], |
||
76 | ], |
||
77 | 'custom_attributes' => [ |
||
78 | 'class' => DataColumn::class, |
||
79 | 'label' => Yii::t('hipanel:finance', 'Attributes'), |
||
80 | 'format' => 'raw', |
||
81 | 'contentOptions' => ['style' => 'padding: 0;'], |
||
82 | 'value' => static fn(Plan $plan): string => PlanAttributes::widget(['plan' => $plan]), |
||
|
|||
83 | ] |
||
84 | ]); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @param Plan $model |
||
89 | * @return string |
||
90 | */ |
||
91 | protected function prepareBadges(Plan $model): string |
||
92 | { |
||
93 | $html = ''; |
||
94 | if ($model->your_tariff) { |
||
95 | $html .= Html::tag('span', Html::tag('i', null, ['class' => 'fa fa-lock']), ['class' => 'label bg-red pull-right', 'style' => 'margin-left: .1em;']); |
||
96 | } |
||
105 |