ServerOrderDedicatedPurchase   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
eloc 20
c 1
b 0
f 1
dl 0
loc 52
ccs 0
cts 37
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 21 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
use yii\helpers\Html;
18
19
/**
20
 * Class ServerOrderPurchase.
21
 */
22
class ServerOrderDedicatedPurchase extends AbstractServerPurchase
23
{
24
    use ModelTrait;
25
26
    /** {@inheritdoc} */
27
    public static function operation()
28
    {
29
        return 'BuyConfig';
30
    }
31
32
    /** {@inheritdoc} */
33
    public function init()
34
    {
35
        parent::init();
36
37
        $this->amount = $this->position->getQuantity();
38
    }
39
40
    public function rules()
41
    {
42
        return array_merge(parent::rules(), [
43
            [['image', 'config_id', 'tariff_id'], 'required'],
44
            [['image', 'administration', 'softpack', 'label', 'location'], 'string'],
45
            [['tariff_id', 'object_id'], 'integer'],
46
        ]);
47
    }
48
49
    public function execute()
50
    {
51
        if (parent::execute()) {
52
            $remark = Box::widget([
53
                'options' => ['class' => 'box-solid box-warning'],
54
                'body' => Yii::t('hipanel:server:order', '{tnx_for_order} The server will be ready in a few minutes. You will receive an email with server access information right after setup. Go to the {server_list} to see the status of the service preparation.', [
55
                    'tnx_for_order' => Html::tag('h4', Yii::t('hipanel:server:order', 'Thank you for the order!')),
56
                    'server_list' => Html::a(Yii::t('hipanel:server:order', 'server list'), ['@server/index']),
57
                ]),
58
            ]);
59
60
            Yii::$app->getView()->params['remarks'][__CLASS__] = $remark;
61
62
            if (is_array($this->_result) && isset($this->_result['_action_pending'])) {
63
                throw new PendingPurchaseException(Yii::t('hipanel:server:order', 'Server setup will be performed as soon as manager confirms your account verification. Pleas wait.'), $this);
64
            }
65
66
            return true;
67
        }
68
69
        return false;
70
    }
71
72
    public function renderNotes()
73
    {
74
    }
75
}
76