|
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\controllers; |
|
12
|
|
|
|
|
13
|
|
|
use hipanel\actions\ComboSearchAction; |
|
14
|
|
|
use hipanel\actions\IndexAction; |
|
15
|
|
|
use hipanel\actions\SmartDeleteAction; |
|
16
|
|
|
use hipanel\actions\SmartUpdateAction; |
|
17
|
|
|
use hipanel\actions\ValidateFormAction; |
|
18
|
|
|
use hipanel\filters\EasyAccessControl; |
|
19
|
|
|
use hipanel\models\Ref; |
|
20
|
|
|
use hipanel\modules\finance\logic\DomainTariffManager; |
|
21
|
|
|
use hipanel\modules\finance\logic\TariffManagerFactory; |
|
22
|
|
|
use hipanel\modules\finance\models\CertificateResource; |
|
23
|
|
|
use Yii; |
|
24
|
|
|
|
|
25
|
|
|
class TariffController extends \hipanel\base\CrudController |
|
26
|
1 |
|
{ |
|
27
|
|
|
public function behaviors() |
|
28
|
|
|
{ |
|
29
|
|
|
return array_merge(parent::behaviors(), [ |
|
|
|
|
|
|
30
|
1 |
|
'access-control' => [ |
|
31
|
1 |
|
'class' => EasyAccessControl::class, |
|
32
|
|
|
'actions' => [ |
|
33
|
|
|
'create,import,copy' => 'plan.create', |
|
34
|
|
|
'update' => 'plan.update', |
|
35
|
1 |
|
'delete' => 'plan.delete', |
|
36
|
1 |
|
'*' => 'plan.read', |
|
37
|
|
|
], |
|
38
|
1 |
|
], |
|
39
|
1 |
|
]); |
|
40
|
|
|
} |
|
41
|
1 |
|
|
|
42
|
1 |
|
public function actions() |
|
43
|
|
|
{ |
|
44
|
1 |
|
return array_merge(parent::actions(), [ |
|
45
|
1 |
|
'index' => [ |
|
46
|
1 |
|
'class' => IndexAction::class, |
|
47
|
|
|
'data' => function () { |
|
48
|
1 |
|
return [ |
|
49
|
1 |
|
'types' => Ref::getList('type,tariff', 'hipanel:finance:tariff:types'), |
|
50
|
1 |
|
]; |
|
51
|
1 |
|
}, |
|
52
|
|
|
], |
|
53
|
|
|
'search' => [ |
|
54
|
|
|
'class' => ComboSearchAction::class, |
|
55
|
|
|
], |
|
56
|
|
|
'validate-form' => [ |
|
57
|
|
|
'class' => ValidateFormAction::class, |
|
58
|
|
|
], |
|
59
|
|
|
'set-note' => [ |
|
60
|
|
|
'class' => SmartUpdateAction::class, |
|
61
|
|
|
'success' => Yii::t('hipanel', 'Note updated'), |
|
62
|
|
|
], |
|
63
|
|
|
'delete' => [ |
|
64
|
|
|
'class' => SmartDeleteAction::class, |
|
65
|
|
|
'success' => Yii::t('hipanel:finance:tariff', 'Tariff deleted'), |
|
66
|
|
|
], |
|
67
|
|
|
]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
View Code Duplication |
public function actionCreateDomain($parent_id = null) |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
|
|
/** @var DomainTariffManager $manager */ |
|
73
|
|
|
$manager = TariffManagerFactory::createByType('domain', $parent_id); |
|
74
|
|
|
$form = $manager->form; |
|
75
|
|
|
|
|
76
|
|
|
if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) { |
|
77
|
|
|
$manager->insert(); |
|
78
|
|
|
|
|
79
|
|
|
return $this->redirect(['view', 'id' => $form->id]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $this->render('domain/create', ['model' => $form]); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
View Code Duplication |
public function actionCreateSvds($parent_id = null) |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
/** @var DomainTariffManager $manager */ |
|
88
|
|
|
$manager = TariffManagerFactory::createByType('svds', $parent_id); |
|
89
|
|
|
|
|
90
|
|
|
$form = $manager->form; |
|
91
|
|
|
|
|
92
|
|
|
if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) { |
|
93
|
|
|
$manager->insert(); |
|
94
|
|
|
|
|
95
|
|
|
return $this->redirect(['view', 'id' => $form->id]); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $this->render('vds/create', ['model' => $form]); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
View Code Duplication |
public function actionCreateOvds($parent_id = null) |
|
|
|
|
|
|
102
|
|
|
{ |
|
103
|
|
|
/** @var DomainTariffManager $manager */ |
|
104
|
|
|
$manager = TariffManagerFactory::createByType('ovds', $parent_id); |
|
105
|
|
|
$form = $manager->form; |
|
106
|
|
|
|
|
107
|
|
|
if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) { |
|
108
|
|
|
$manager->insert(); |
|
109
|
|
|
|
|
110
|
|
|
return $this->redirect(['view', 'id' => $form->id]); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return $this->render('vds/create', ['model' => $form]); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
View Code Duplication |
public function actionCreateCertificate($parent_id = null) |
|
|
|
|
|
|
117
|
|
|
{ |
|
118
|
|
|
/** @var CertificateResource $manager */ |
|
119
|
|
|
$manager = TariffManagerFactory::createByType('certificate', $parent_id); |
|
120
|
|
|
$form = $manager->form; |
|
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) { |
|
123
|
|
|
$manager->insert(); |
|
124
|
|
|
|
|
125
|
|
|
return $this->redirect(['view', 'id' => $form->id]); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $this->render('certificate/create', ['model' => $form]); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
View Code Duplication |
public function actionCreateServer($parent_id = null) |
|
|
|
|
|
|
132
|
|
|
{ |
|
133
|
|
|
/** @var CertificateResource $manager */ |
|
134
|
|
|
$manager = TariffManagerFactory::createByType('server', $parent_id); |
|
135
|
|
|
$form = $manager->form; |
|
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) { |
|
138
|
|
|
$manager->insert(); |
|
139
|
|
|
|
|
140
|
|
|
return $this->redirect(['view', 'id' => $form->id]); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
return $this->render('server/create', ['model' => $form]); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
View Code Duplication |
public function actionUpdate($id) |
|
|
|
|
|
|
147
|
|
|
{ |
|
148
|
|
|
$manager = TariffManagerFactory::createById($id, ['scenario' => 'update']); |
|
149
|
|
|
$form = $manager->form; |
|
150
|
|
|
|
|
151
|
|
|
if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) { |
|
152
|
|
|
$manager->update(); |
|
153
|
|
|
|
|
154
|
|
|
return $this->redirect(['view', 'id' => $form->id]); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
return $this->render($manager->getType() . '/update', ['model' => $form]); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
public function actionCopy() |
|
161
|
|
|
{ |
|
162
|
|
|
$id = Yii::$app->request->post('selection')[0]; |
|
163
|
|
|
$manager = TariffManagerFactory::createById($id, ['scenario' => 'create']); |
|
164
|
|
|
$form = $manager->form; |
|
165
|
|
|
|
|
166
|
|
|
return $this->render($manager->getType() . '/copy', ['model' => $form]); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
public function actionView($id) |
|
170
|
|
|
{ |
|
171
|
|
|
$manager = TariffManagerFactory::createById($id); |
|
172
|
|
|
|
|
173
|
|
|
return $this->render('view', ['manager' => $manager]); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.