Completed
Push — master ( 4bde9c...94e19b )
by Andrii
04:39
created

src/grid/PlanGridView.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\grid;
12
13
use hipanel\grid\MainColumn;
14
use hipanel\grid\RefColumn;
15
use hipanel\helpers\Url;
16
use hipanel\modules\client\grid\ClientColumn;
17
use hipanel\modules\finance\menus\PlanActionsMenu;
18
use hipanel\modules\finance\models\Plan;
19
use hiqdev\yii2\menus\grid\MenuColumn;
20
use Yii;
21
use yii\helpers\Html;
22
23
class PlanGridView extends \hipanel\grid\BoxedGridView
24
{
25
    public function columns(): array
26
    {
27
        return array_merge(parent::columns(), [
28
            'client' => [
29
                'class' => ClientColumn::class,
30
            ],
31
            'name' => [
32
                'attribute' => 'name',
33
                'filterAttribute' => 'name_ilike',
34
                'filterOptions' => ['class' => 'narrow-filter'],
35
                'class' => MainColumn::class,
36
                'note' => 'note',
37
                'noteOptions' => [
38
                    'url' => Url::to(['@plan/set-note']),
39
                ],
40
                'badges' => function (Plan $model): string {
41
                    return $this->prepareBadges($model);
42
                },
43
            ],
44
            'simple_name' => [
45
                'attribute' => 'name',
46
                'format' => 'html',
47
                'value' => function (Plan $model): string {
48
                    return sprintf('%s %s', $model->name, $this->prepareBadges($model));
49
                },
50
            ],
51
            'state' => [
52
                'attribute' => 'state',
53
                'class' => RefColumn::class,
54
                'filterAttribute' => 'state',
55
                'filterOptions' => ['class' => 'narrow-filter'],
56
                'format' => 'html',
57
                'gtype' => 'state,tariff',
58
            ],
59
            'type' => [
60
                'attribute' => 'type',
61
                'class' => RefColumn::class,
62
                'filterAttribute' => 'type_in',
63
                'filterOptions' => ['class' => 'narrow-filter'],
64
                'format' => 'html',
65
                'gtype' => 'type,tariff',
66
            ],
67
            'actions' => [
68
                'class' => MenuColumn::class,
69
                'menuClass' => PlanActionsMenu::class,
70
            ],
71
            'monthly' => [
72
                'attribute' => 'monthly',
73
                'contentOptions' => ['id' => 'plan-monthly-value'],
74
            ],
75
        ]);
76
    }
77
78
    /**
79
     * @param Plan $model
80
     * @return string
81
     */
82
    protected function prepareBadges(Plan $model): string
83
    {
84
        $html = '';
85
        if ($model->your_tariff) {
0 ignored issues
show
The property your_tariff does not exist on object<hipanel\modules\finance\models\Plan>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
86
            $html .=  Html::tag('span', Html::tag('i', null, ['class' => 'fa fa-lock']), ['class' => 'label bg-red pull-right', 'style' => 'margin-left: .1em;']);
87
        }
88
        if ($model->is_grouping) {
89
            $localization = Yii::t('hipanel.finance.plan', 'Grouping');
90
            $html .= Html::tag('span', $localization, ['class' => 'label bg-olive pull-right']);
91
        }
92
93
        return $html;
94
    }
95
}
96