Completed
Push — master ( 27dc7b...6de725 )
by Andrii
05:04
created

ServerOrderDedicatedPurchase   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
eloc 18
dl 0
loc 49
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 18 4
A init() 0 5 1
A operation() 0 3 1
A rules() 0 6 1
A renderNotes() 0 2 1
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\cart;
12
13
use hipanel\base\ModelTrait;
14
use hipanel\modules\finance\cart\PendingPurchaseException;
15
use hipanel\widgets\Box;
16
use Yii;
17
18
/**
19
 * Class ServerOrderPurchase.
20
 */
21
class ServerOrderDedicatedPurchase extends AbstractServerPurchase
22
{
23
    use ModelTrait;
24
25
    /** {@inheritdoc} */
26
    public static function operation()
27
    {
28
        return 'Buy';
29
    }
30
31
    /** {@inheritdoc} */
32
    public function init()
33
    {
34
        parent::init();
35
36
        $this->amount = $this->position->getQuantity();
37
    }
38
39
    public function rules()
40
    {
41
        return array_merge(parent::rules(), [
42
            [['osimage', 'config_id', 'tariff_id'], 'required'],
43
            [['osimage', 'administration', 'softpack', 'label', 'location'], 'string'],
44
            [['tariff_id', 'object_id'], 'integer'],
45
        ]);
46
    }
47
48
    public function execute()
49
    {
50
        if (parent::execute()) {
51
            $remark = Box::widget([
52
                'options' => ['class' => 'box-solid box-warning'],
53
                'body' => Yii::t('hipanel:server:order', 'You will receive an email with server access information right after setup'),
54
            ]);
55
56
            Yii::$app->getView()->params['remarks'][__CLASS__] = $remark;
57
58
            if (is_array($this->_result) && isset($this->_result['_action_pending'])) {
59
                throw new PendingPurchaseException(Yii::t('hipanel:server:order', 'Server setup will be performed as soon as manager confirms your account verification. Pleas wait.'), $this);
60
            }
61
62
            return true;
63
        }
64
65
        return false;
66
    }
67
68
    public function renderNotes()
69
    {
70
    }
71
}
72