Completed
Push — master ( 8c1c91...aeff30 )
by Dmitry
05:55
created

TariffController::actions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1.0001

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 28
ccs 17
cts 18
cp 0.9444
rs 8.8571
cc 1
eloc 18
nc 1
nop 0
crap 1.0001
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\SmartDeleteAction;
18
use hipanel\actions\SmartPerformAction;
19
use hipanel\actions\SmartUpdateAction;
20
use hipanel\actions\ValidateFormAction;
21
use hipanel\modules\finance\logic\DomainTariffManager;
22
use hipanel\modules\finance\logic\TariffManagerFactory;
23
use Yii;
24
25 1
class TariffController extends \hipanel\base\CrudController
26
{
27
    public function actions()
28
    {
29 1
        return [
30
            'set-orientation' => [
31 1
                'class' => OrientationAction::class,
32 1
                'allowedRoutes' => [
33 1
                    '@tariff/index'
34
                ]
35 1
            ],
36 1
            'index' => [
37
                'class' => IndexAction::class,
38 1
            ],
39 1
            'search' => [
40
                'class' => SearchAction::class,
41 1
            ],
42 1
            'validate-form' => [
43
                'class' => ValidateFormAction::class,
44 1
            ],
45 1
            'set-note' => [
46 1
                'class' => SmartUpdateAction::class,
47
                'success' => Yii::t('hipanel', 'Note updated'),
48 1
            ],
49 1
            'delete' => [
50 1
                'class' => SmartDeleteAction::class,
51 1
                'success' => Yii::t('hipanel:finance:tariff', 'Tariff deleted'),
52
            ],
53
        ];
54
    }
55
56 View Code Duplication
    public function actionCreateDomain()
0 ignored issues
show
Duplication introduced by
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...
57
    {
58
        /** @var DomainTariffManager $manager */
59
        $manager = TariffManagerFactory::createByType('domain');
60
        $form = $manager->form;
61
62
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
63
            $manager->insert();
64
            return $this->redirect(['view', 'id' => $form->id]);
65
        }
66
67
        return $this->render('domain/create', ['model' => $form]);
68
    }
69
70 View Code Duplication
    public function actionCreateSvds($parent_id = null)
0 ignored issues
show
Duplication introduced by
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...
71
    {
72
        /** @var DomainTariffManager $manager */
73
        $manager = TariffManagerFactory::createByType('svds', $parent_id);
74
75
        $form = $manager->form;
76
77
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
78
            $manager->insert();
79
            return $this->redirect(['view', 'id' => $form->id]);
80
        }
81
82
        return $this->render('vds/create', ['model' => $form]);
83
    }
84
85 View Code Duplication
    public function actionCreateOvds($parent_id = null)
0 ignored issues
show
Duplication introduced by
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...
86
    {
87
        /** @var DomainTariffManager $manager */
88
        $manager = TariffManagerFactory::createByType('ovds', $parent_id);
89
        $form = $manager->form;
90
91
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
92
            $manager->insert();
93
            return $this->redirect(['view', 'id' => $form->id]);
94
        }
95
96
        return $this->render('vds/create', ['model' => $form]);
97
    }
98
99 View Code Duplication
    public function actionUpdate($id)
0 ignored issues
show
Duplication introduced by
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...
100
    {
101
        $manager = TariffManagerFactory::createById($id, ['scenario' => 'update']);
102
        $form = $manager->form;
103
104
        if (Yii::$app->request->isPost && $form->load(Yii::$app->request->post())) {
105
            $manager->update();
106
            return $this->redirect(['view', 'id' => $form->id]);
107
        }
108
109
        return $this->render($manager->getType() . '/update', ['model' => $form]);
110
    }
111
112
    public function actionView($id)
113
    {
114
        $manager = TariffManagerFactory::createById($id);
115
116
        return $this->render('view', ['manager' => $manager]);
117
    }
118
}
119