Completed
Pull Request — master (#136)
by Klochok
07:02 queued 03:42
created

OrderPositionDescriptionWidget::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 29
ccs 0
cts 25
cp 0
rs 9.488
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Server module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-server
6
 * @package   hipanel-module-server
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\server\widgets\cart;
12
13
use hipanel\modules\server\cart\ServerOrderDedicatedProduct;
14
use hipanel\modules\server\cart\ServerOrderProduct;
15
use yii\base\Widget;
16
use yii\helpers\Html;
17
18
/**
19
 * Class OrderPositionDescriptionWidget renders description for Server order position
20
 * in cart.
21
 */
22
class OrderPositionDescriptionWidget extends Widget
23
{
24
    /**
25
     * @var ServerOrderProduct|ServerOrderDedicatedProduct
26
     */
27
    public $position;
28
29
    public function init()
30
    {
31
        $this->view->registerCss(<<<CSS
32
            .cart-item .dl-config { display: none; }
33
            
34
            dl.dl-config {
35
                padding: 1em 0 0;
36
                display: flex;
37
                flex-flow: row wrap;
38
            }
39
40
            dl.dl-config dt {
41
                flex-basis: 16%;
42
                text-align: left;
43
                width: auto;
44
            }
45
46
            dl.dl-config dt::after {
47
                content: ":";
48
            }
49
50
            dl.dl-config dd {
51
                flex-basis: 70%;
52
                flex-grow: 1;
53
                margin: 0;
54
                padding: 0;
55
            }
56
CSS
57
        , [], __CLASS__ . '_client_css');
58
    }
59
60
    /** {@inheritdoc} */
61
    public function run()
62
    {
63
        return $this->render('_orderPositionDescription', ['position' => $this->position]);
64
    }
65
66
    /**
67
     * @param array $items
68
     * @return string
69
     */
70
    public function formatConfig(array $items = []): string
71
    {
72
        $html = '';
73
        foreach ($items as $label => $value) {
74
            if (empty($value)) {
75
                continue;
76
            }
77
            $html .= Html::tag('dt', $label) . Html::tag('dd', $value);
78
        }
79
80
        return Html::tag('dl', $html, ['class' => 'dl-horizontal dl-config']);
81
    }
82
}
83