1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Finance module for HiPanel |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/hipanel-module-finance |
7
|
|
|
* @package hipanel-module-finance |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hipanel\modules\finance\controllers; |
13
|
|
|
|
14
|
|
|
use hipanel\actions\IndexAction; |
15
|
|
|
use hipanel\actions\OrientationAction; |
16
|
|
|
use hipanel\actions\SearchAction; |
17
|
|
|
use hipanel\actions\SmartPerformAction; |
18
|
|
|
use hipanel\actions\SmartUpdateAction; |
19
|
|
|
use hipanel\actions\ValidateFormAction; |
20
|
|
|
use hipanel\actions\ViewAction; |
21
|
|
|
use hipanel\modules\finance\logic\DomainTariffManager; |
22
|
|
|
use hipanel\modules\finance\logic\TariffManagerFactory; |
23
|
|
|
use hipanel\modules\finance\models\Tariff; |
24
|
|
|
use Yii; |
25
|
|
|
|
26
|
|
|
class TariffController extends \hipanel\base\CrudController |
27
|
|
|
{ |
28
|
1 |
|
public function actions() |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
|
|
'set-orientation' => [ |
32
|
|
|
'class' => OrientationAction::class, |
33
|
|
|
'allowedRoutes' => [ |
34
|
|
|
'@tariff/index' |
35
|
|
|
] |
36
|
1 |
|
], |
37
|
|
|
'index' => [ |
38
|
|
|
'class' => IndexAction::class, |
39
|
1 |
|
], |
40
|
|
|
'search' => [ |
41
|
|
|
'class' => SearchAction::class, |
42
|
1 |
|
], |
43
|
|
|
'view' => [ |
44
|
|
|
'class' => ViewAction::class, |
45
|
1 |
|
], |
46
|
|
|
'validate-form' => [ |
47
|
|
|
'class' => ValidateFormAction::class, |
48
|
1 |
|
], |
49
|
|
|
'set-note' => [ |
50
|
1 |
|
'class' => SmartUpdateAction::class, |
51
|
1 |
|
'success' => Yii::t('hipanel', 'Note updated'), |
52
|
1 |
|
], |
53
|
|
|
'delete' => [ |
54
|
1 |
|
'class' => SmartPerformAction::class, |
55
|
1 |
|
'success' => Yii::t('hipanel/finance/tariff', 'Tariff deleted'), |
56
|
1 |
|
], |
57
|
1 |
|
]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
public function actionCreateDomain() |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$manager = TariffManagerFactory::createByType('domain'); |
63
|
|
|
|
64
|
|
|
if (Yii::$app->request->isPost && $manager->model->load(Yii::$app->request->post())) { |
65
|
|
|
$manager->insert(); |
66
|
|
|
return $this->redirect(['view', 'id' => $manager->model->id]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $this->render('domain/create', ['model' => $manager->model]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
View Code Duplication |
public function actionUpdate($id) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$manager = TariffManagerFactory::createById($id); |
75
|
|
|
|
76
|
|
|
if (Yii::$app->request->isPost && $manager->model->load(Yii::$app->request->post())) { |
77
|
|
|
$manager->update(); |
78
|
|
|
return $this->redirect(['view', 'id' => $manager->model->id]); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $this->render($manager->getType() . '/update', ['model' => $manager->model]); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.