Completed
Push — master ( 6572b9...210ee5 )
by Dmitry
16:33
created

Service::getObjects_count()   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 1
Metric Value
c 3
b 0
f 1
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * Hosting Plugin for HiPanel
5
 *
6
 * @link      https://github.com/hiqdev/hipanel-module-hosting
7
 * @package   hipanel-module-hosting
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\modules\hosting\models;
13
14
use hipanel\helpers\StringHelper;
15
use Yii;
16
17
class Service extends \hipanel\base\Model
18
{
19
    use \hipanel\base\ModelTrait;
20
21
    /** @inheritdoc */
22
    public function rules()
23
    {
24
        return [
25
            [['id', 'server_id', 'device_id', 'client_id', 'seller_id', 'soft_id'], 'integer'],
26
            [['name', 'server', 'device', 'client', 'seller', 'soft'], 'safe'],
27
            [['ip', 'ips', 'bin', 'etc', 'objects_count'], 'safe'],
28
            [['soft_type', 'soft_type_label', 'state', 'state_label'], 'safe'],
29
            [['server'], 'safe', 'on' => ['create']],
30
            [['bin', 'etc', 'soft', 'state'], 'safe', 'on' => ['create', 'update']],
31
            [['ips'], 'filter',
32
                'filter' => function ($value) {
33
                    return StringHelper::explode($value);
34
                },
35
                'skipOnArray' => true, 'on' => ['create', 'update']
36
            ],
37
            [['ips'], 'each', 'rule' => ['ip'], 'on' => ['create', 'update']],
38
            [['id'], 'integer', 'on' => ['update']],
39
            [['id'], 'required', 'on' => ['update']],
40
        ];
41
    }
42
43
    /** @inheritdoc */
44
    public function attributeLabels()
45
    {
46
        return $this->mergeAttributeLabels([
47
            'soft_type'         => Yii::t('hipanel', 'Type'),
48
            'bin'               => Yii::t('hipanel/hosting', 'bin'),
49
            'etc'               => Yii::t('hipanel/hosting', 'etc'),
50
            'soft'              => Yii::t('hipanel/hosting', 'Soft'),
51
        ]);
52
    }
53
54
    public function getIps()
55
    {
56
        return $this->hasMany(Ip::class, ['service_id', 'id']);
57
    }
58
}
59