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-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\finance\logic; |
12
|
|
|
|
13
|
|
|
use hipanel\models\Ref; |
14
|
|
|
use hipanel\modules\finance\forms\CertificateTariffForm; |
15
|
|
|
use hipanel\modules\finance\models\Tariff; |
16
|
|
|
use hiqdev\hiart\ConnectionInterface; |
17
|
|
|
use Yii; |
18
|
|
|
use yii\base\InvalidConfigException; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class CertificateTariffManager. |
22
|
|
|
* |
23
|
|
|
* @author Dmytro Naumenko <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class CertificateTariffManager extends AbstractTariffManager |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var CertificateTariffForm |
29
|
|
|
*/ |
30
|
|
|
public $form; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
protected $type = Tariff::TYPE_CERT; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var ConnectionInterface |
39
|
|
|
*/ |
40
|
|
|
private $connection; |
41
|
|
|
|
42
|
|
|
public function __construct(ConnectionInterface $connection, $config = []) |
43
|
|
|
{ |
44
|
|
|
$this->connection = $connection; |
45
|
|
|
|
46
|
|
|
parent::__construct($config); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function init() |
50
|
|
|
{ |
51
|
|
|
if (!Yii::getAlias('@certificate', true)) { |
52
|
|
|
throw new InvalidConfigException('Certificate module is missing'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
parent::init(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function determineParentTariff() |
59
|
|
|
{ |
60
|
|
|
$id = parent::determineParentTariff(); |
61
|
|
|
|
62
|
|
|
if ($id === null) { |
63
|
|
|
$tariff = reset(Tariff::find() |
|
|
|
|
64
|
|
|
->action('get-available-info') |
65
|
|
|
->andFilterWhere(['type' => $this->type]) |
66
|
|
|
->all()); |
67
|
|
|
|
68
|
|
|
if ($tariff instanceof Tariff) { |
69
|
|
|
$id = $tariff->id; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $id; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
protected function getFormOptions() |
77
|
|
|
{ |
78
|
|
|
return array_merge([ |
79
|
|
|
'class' => CertificateTariffForm::class, |
80
|
|
|
'certificateTypes' => Ref::getList('type,certificate', 'hipanel:certificate', [ |
81
|
|
|
'select' => 'id_label', |
82
|
|
|
'mapOptions' => ['from' => 'id'], |
83
|
|
|
]), |
84
|
|
|
], parent::getFormOptions()); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|