Completed
Push — master ( cf838f...441ca2 )
by Dmitry
04:31
created

Osimage::getFullOsName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * Server module for HiPanel
5
 *
6
 * @link      https://github.com/hiqdev/hipanel-module-server
7
 * @package   hipanel-module-server
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
/**
13
 * @link    http://hiqdev.com/hipanel
14
 * @license http://hiqdev.com/hipanel/license
15
 * @copyright Copyright (c) 2015 HiQDev
16
 */
17
18
namespace hipanel\modules\server\models;
19
20
use Yii;
21
22
/**
23
 * @property string osimage
24
 * @property string os
25
 * @property string version
26
 * @property string bitwise
27
 * @property string panel
28
 * @property array softpack
29
 */
30
class Osimage extends \hiqdev\hiart\ActiveRecord
31
{
32
    const NO_PANEL = 'no';
33
34
    /**
35
     * @return array the list of attributes for this record
36
     */
37
    public function attributes()
38
    {
39
        return ['osimage', 'os', 'version', 'bitwise', 'panel', 'softpack'];
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function rules()
46
    {
47
        return [[['osimage'], 'required']];
48
    }
49
50
    /**
51
     * @param string $delimiter defines delimiter to separeate os, version and bitwise of OS
52
     * @return string
53
     */
54
    public function getFullOsName($delimiter = ' ')
55
    {
56
        return implode($delimiter, [$this->os, $this->version, $this->bitwise]);
57
    }
58
59
    public function getSoftPackName()
60
    {
61
        return $this->hasSoftPack() ? $this->softpack['name'] : 'clear';
62
    }
63
64
    public function getDisplaySoftPackName()
65
    {
66
        return Yii::t('hipanel/server/os', $this->getSoftPackName());
67
    }
68
69
    public function hasSoftPack()
70
    {
71
        return !empty($this->softpack);
72
    }
73
74
    public function getPanelName()
75
    {
76
        return $this->panel ?: static::NO_PANEL;
77
    }
78
79
    public function getSoftPack()
80
    {
81
        return $this->hasSoftPack() ? $this->softpack : [];
82
    }
83
84
    public function getDisplayPanelName()
85
    {
86
        $panel = $this->getPanelName();
87
        if ($panel === static::NO_PANEL) {
88
            $panel = 'No panel';
89
        }
90
        return Yii::t('hipanel/server/panel', $panel);
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function attributeLabels()
97
    {
98
        return [
99
            'osimagae' => Yii::t('hipanel/server/os', 'System name of image'),
100
            'os' => Yii::t('hipanel/server/os', 'OS'),
101
            'softpack' => Yii::t('hipanel/server/os', 'Soft package'),
102
            'panel' => Yii::t('hipanel/server/os', 'Panel'),
103
        ];
104
    }
105
}
106