Passed
Push — master ( 46dd23...a76d17 )
by Dmitry
03:18
created

src/models/Osimage.php (1 issue)

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
/**
12
 * @see    http://hiqdev.com/hipanel
13
 * @license http://hiqdev.com/hipanel/license
14
 * @copyright Copyright (c) 2015 HiQDev
15
 */
16
17
namespace hipanel\modules\server\models;
18
19
use hiqdev\hiart\ActiveRecord;
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 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', 'title', 'deprecated', 'name'];
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 separate 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
        if ($this->panel) {
77
            return $this->panel;
78
        }
79
        /** @var array $softpack */
80
        if ($softpack = $this->getSoftPack() && $softpack['panel']) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $softpack seems to be never defined.
Loading history...
81
            return $softpack['panel'];
82
        }
83
84
        return static::NO_PANEL;
85
    }
86
87
    public function getSoftPack()
88
    {
89
        return $this->hasSoftPack() ? $this->softpack : [];
90
    }
91
92
    public function getDisplayPanelName()
93
    {
94
        $panel = $this->getPanelName();
95
        if ($panel === static::NO_PANEL) {
96
            $panel = 'No panel';
97
        }
98
99
        return Yii::t('hipanel:server:panel', $panel);
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function attributeLabels()
106
    {
107
        return [
108
            'osimagae' => Yii::t('hipanel:server:os', 'System name of image'),
109
            'os' => Yii::t('hipanel:server:os', 'OS'),
110
            'softpack' => Yii::t('hipanel:server:os', 'Soft package'),
111
            'panel' => Yii::t('hipanel:server:os', 'Panel'),
112
        ];
113
    }
114
}
115