Completed
Push — master ( ccdb45...342210 )
by Dmitry
12s queued 10s
created

BackupController::behaviors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Hosting Plugin for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-hosting
6
 * @package   hipanel-module-hosting
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\hosting\controllers;
12
13
use hipanel\actions\IndexAction;
14
use hipanel\actions\RedirectAction;
15
use hipanel\actions\SmartDeleteAction;
16
use hipanel\actions\ViewAction;
17
use hipanel\base\CrudController;
18
use hipanel\filters\EasyAccessControl;
19
use Yii;
20
21
class BackupController extends CrudController
22
{
23
    public function behaviors()
24
    {
25
        return array_merge(parent::behaviors(), [
26
            [
27
                'class' => EasyAccessControl::class,
28
                'actions' => [
29
                    'delete' => 'account.delete',
30
                    '*' => 'account.read',
31
                ],
32
            ],
33
        ]);
34
    }
35
36
    public function actions()
37
    {
38
        return array_merge(parent::actions(), [
39
            'index' => [
40
                'class' => IndexAction::class,
41
                'data' => function ($action) {
42
                    return [
43
                        'objectOptions' => $action->controller->getObjectOptions(),
44
                    ];
45
                },
46
                'filterStorageMap' => [
47
                    'name_like' => 'hosting.backup.name_like',
48
                    'type' => 'hosting.backup.type',
49
                    'state' => 'hosting.backup.state',
50
                    'server' => 'server.server.name',
51
                    'account' => 'hosting.account.login',
52
                    'client_id' => 'client.client.id',
53
                ],
54
            ],
55
            'view' => [
56
                'class' => ViewAction::class,
57
            ],
58
            'delete' => [
59
                'class' => SmartDeleteAction::class,
60
                'success' => Yii::t('hipanel:hosting', 'Backup deleting task has been added to queue'),
61
                'error' => Yii::t('hipanel:hosting', 'An error occurred when trying to delete backup'),
62
                'POST html | POST pjax' => [
63
                    'save' => true,
64
                    'success' => [
65
                        'class' => RedirectAction::class,
66
                    ],
67
                ],
68
            ],
69
        ]);
70
    }
71
72
    public function getObjectOptions()
73
    {
74
        return [
75
            'hdomain' => Yii::t('hipanel:hosting', 'Domain'),
76
            'db' => Yii::t('hipanel:hosting', 'Data Bases'),
77
        ];
78
    }
79
}
80