Completed
Push — master ( c2bc12...ef5bc2 )
by Dmitry
04:55
created

src/controllers/TariffController.php (6 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\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\AbstractTariffManager;
21
use hipanel\modules\finance\logic\CertificateTariffManager;
22
use hipanel\modules\finance\logic\DomainTariffManager;
23
use hipanel\modules\finance\logic\OvdsTariffManager;
24
use hipanel\modules\finance\logic\ServerTariffManager;
25
use hipanel\modules\finance\logic\SvdsTariffManager;
26
use hipanel\modules\finance\logic\TariffManagerFactory;
27
use Yii;
28
29
class TariffController extends \hipanel\base\CrudController
30
{
31 View Code Duplication
    public function behaviors()
32
    {
33
        return array_merge(parent::behaviors(), [
34
            'access-control' => [
35
                'class' => EasyAccessControl::class,
36
                'actions' => [
37
                    'create,import,copy' => 'plan.create',
38
                    'update'    => 'plan.update',
39
                    'delete'    => 'plan.delete',
40
                    '*'         => 'plan.read',
41
                ],
42
            ],
43
        ]);
44
    }
45
46 1
    public function actions()
47
    {
48 1
        return array_merge(parent::actions(), [
49 1
            'index' => [
50
                'class' => IndexAction::class,
51
                'data' => function () {
52
                    return [
53
                        'types' => Ref::getList('type,tariff', 'hipanel:finance:tariff:types'),
54
                    ];
55 1
                },
56
            ],
57
            'search' => [
58
                'class' => ComboSearchAction::class,
59
            ],
60
            'validate-form' => [
61
                'class' => ValidateFormAction::class,
62
            ],
63
            'set-note' => [
64
                'class' => SmartUpdateAction::class,
65 1
                'success' => Yii::t('hipanel', 'Note updated'),
66
            ],
67
            'delete' => [
68
                'class' => SmartDeleteAction::class,
69 1
                'success' => Yii::t('hipanel:finance:tariff', 'Tariff deleted'),
70
            ],
71
        ]);
72
    }
73
74 View Code Duplication
    public function actionCreateDomain($parent_id = null)
0 ignored issues
show
This method seems to be duplicated in your project.

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.

Loading history...
75
    {
76
        /** @var DomainTariffManager $manager */
77
        $manager = TariffManagerFactory::createByType('domain', $parent_id);
78
        $form = $manager->form;
79
80
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
81
            $manager->insert();
82
83
            return $this->redirect(['view', 'id' => $form->id]);
84
        }
85
86
        return $this->render('domain/create', ['model' => $form]);
87
    }
88
89 View Code Duplication
    public function actionCreateSvds($parent_id = null)
0 ignored issues
show
This method seems to be duplicated in your project.

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.

Loading history...
90
    {
91
        /** @var SvdsTariffManager $manager */
92
        $manager = TariffManagerFactory::createByType('svds', $parent_id);
93
94
        $form = $manager->form;
95
96
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
97
            $manager->insert();
98
99
            return $this->redirect(['view', 'id' => $form->id]);
100
        }
101
102
        return $this->render('vds/create', ['model' => $form]);
103
    }
104
105 View Code Duplication
    public function actionCreateOvds($parent_id = null)
0 ignored issues
show
This method seems to be duplicated in your project.

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.

Loading history...
106
    {
107
        /** @var OvdsTariffManager $manager */
108
        $manager = TariffManagerFactory::createByType('ovds', $parent_id);
109
        $form = $manager->form;
110
111
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
112
            $manager->insert();
113
114
            return $this->redirect(['view', 'id' => $form->id]);
115
        }
116
117
        return $this->render('vds/create', ['model' => $form]);
118
    }
119
120 View Code Duplication
    public function actionCreateCertificate($parent_id = null)
0 ignored issues
show
This method seems to be duplicated in your project.

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.

Loading history...
121
    {
122
        /** @var CertificateTariffManager $manager */
123
        $manager = TariffManagerFactory::createByType('certificate', $parent_id);
124
        $form = $manager->form;
125
126
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
127
            $manager->insert();
128
129
            return $this->redirect(['view', 'id' => $form->id]);
130
        }
131
132
        return $this->render('certificate/create', ['model' => $form]);
133
    }
134
135 View Code Duplication
    public function actionCreateServer($parent_id = null)
0 ignored issues
show
This method seems to be duplicated in your project.

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.

Loading history...
136
    {
137
        /** @var ServerTariffManager $manager */
138
        $manager = TariffManagerFactory::createByType('server', $parent_id);
139
        $form = $manager->form;
140
141
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
142
            $manager->insert();
143
144
            return $this->redirect(['view', 'id' => $form->id]);
145
        }
146
147
        return $this->render('server/create', ['model' => $form]);
148
    }
149
150 View Code Duplication
    public function actionUpdate($id)
0 ignored issues
show
This method seems to be duplicated in your project.

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.

Loading history...
151
    {
152
        /** @var AbstractTariffManager $manager */
153
        $manager = TariffManagerFactory::createById($id, ['scenario' => 'update']);
154
        $form = $manager->form;
155
156
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
157
            $manager->update();
158
159
            return $this->redirect(['view', 'id' => $form->id]);
160
        }
161
162
        return $this->render($manager->getType() . '/update', ['model' => $form]);
163
    }
164
165
    public function actionCopy()
166
    {
167
        $id = Yii::$app->request->post('selection')[0];
168
        $manager = TariffManagerFactory::createById($id, ['scenario' => 'create']);
169
        $form = $manager->form;
170
        $form->id = null;
171
172
        return $this->render($manager->getType() . '/copy', ['model' => $form]);
173
    }
174
175
    public function actionView($id)
176
    {
177
        $manager = TariffManagerFactory::createById($id);
178
179
        return $this->render('view', ['manager' => $manager]);
180
    }
181
}
182