Completed
Push — master ( 0e490c...4b4ef3 )
by Dmitry
11:06
created

DomainTariffManager::update()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 0
cts 10
cp 0
rs 9.8666
cc 2
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\logic;
12
13
use hipanel\modules\finance\forms\DomainTariffForm;
14
use hipanel\modules\finance\models\Tariff;
15
use hiqdev\hiart\ConnectionInterface;
16
use hiqdev\hiart\ResponseErrorException;
17
use Yii;
18
use yii\web\NotFoundHttpException;
19
use yii\web\UnprocessableEntityHttpException;
20
21
class DomainTariffManager extends AbstractTariffManager
22
{
23
    /**
24
     * @var DomainTariffForm
25
     */
26
    public $form;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected $type = Tariff::TYPE_DOMAIN;
32
33
    /**
34
     * @var ConnectionInterface
35
     */
36
    private $connection;
37
38
    public function __construct(ConnectionInterface $connection, $config = [])
39
    {
40
        $this->connection = $connection;
41
42
        parent::__construct($config);
43
    }
44
45
    public function init()
46
    {
47
        parent::init();
48
49
        if (!Yii::getAlias('@domain', true)) {
50
            throw new NotFoundHttpException('Domain module is missing');
51
        }
52
53
        $this->formOptions['zones'] = $this->getZones();
54
    }
55
56
    protected function getFormOptions()
57
    {
58
        return array_merge([
59
            'class' => DomainTariffForm::class,
60
            'zones' => $this->getZones(),
61
        ], parent::getFormOptions());
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    protected function getZones()
68
    {
69
        $command = $this->connection->createCommand();
70
        return $command->perform('getZones', '')->getData();
71
    }
72
}
73