Completed
Push — master ( db50e7...7354ed )
by Dmitry
15:54 queued 13:20
created

src/controllers/TariffProfileController.php (1 issue)

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\SmartCreateAction;
16
use hipanel\actions\SmartDeleteAction;
17
use hipanel\actions\SmartUpdateAction;
18
use hipanel\actions\ValidateFormAction;
19
use hipanel\actions\ViewAction;
20
use hipanel\filters\EasyAccessControl;
21
use Yii;
22
23
class TariffProfileController extends \hipanel\base\CrudController
24
{
25 View Code Duplication
    public function behaviors()
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...
26
    {
27
        return array_merge(parent::behaviors(), [
28
            'access-control' => [
29
                'class' => EasyAccessControl::class,
30
                'actions' => [
31
                    'create' => 'plan.create',
32
                    'update' => 'plan.update',
33
                    'delete' => 'plan.delete',
34
                    '*'      => 'plan.read',
35
                ],
36
            ],
37
        ]);
38
    }
39
40
    public function actions()
41
    {
42
        return array_merge(parent::actions(), [
43
            'index' => [
44
                'class' => IndexAction::class,
45
            ],
46
            'create' => [
47
                'class' => SmartCreateAction::class,
48
                'data' => function(\hipanel\actions\RenderAction $action) : array {
49
                    $user = Yii::$app->user->identity;
50
                    if ($user->type === 'reseller') {
51
                        return [
52
                            'client' => $user->username,
53
                            'client_id' => $user->id,
54
                        ];
55
                    }
56
                    return [
57
                        'client' => $user->seller,
58
                        'client_id' => $user->seller_id,
59
                    ];
60
                }
61
            ],
62
            'update' => [
63
                'class' => SmartUpdateAction::class,
64
                'data'  => function(\hipanel\actions\RenderAction $action, array $data) : array {
65
                    $model = $data['model'];
66
                    return [
67
                        'client' => $model->client,
68
                        'client_id' => $model->client_id,
69
                    ];
70
                },
71
            ],
72
            'search' => [
73
                'class' => ComboSearchAction::class,
74
            ],
75
            'validate-form' => [
76
                'class' => ValidateFormAction::class,
77
            ],
78
            'view' => [
79
                'class' => ViewAction::class,
80
            ],
81
            'delete' => [
82
                'class' => SmartDeleteAction::class,
83
                'success' => Yii::t('hipanel.finance.tariffprofile', 'Profile deleted'),
84
            ],
85
        ]);
86
    }
87
}
88