Completed
Push — master ( 42fdff...4bba11 )
by vistart
02:58
created

UserPanel::save()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 36
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 20
nc 5
nop 0
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace yii\debug\panels;
14
15
use Yii;
16
use yii\data\ArrayDataProvider;
17
use yii\debug\Panel;
18
use yii\db\ActiveRecord;
19
20
/**
21
 * Debugger panel that collects and displays user data.
22
 *
23
 * @version 1.0
24
 * @author vistart <[email protected]>
25
 */
26
class UserPanel extends Panel
27
{
28
    /**
29
     * @inheritdoc
30
     */
31
    public function getName()
32
    {
33
        return 'User';
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function getSummary()
40
    {
41
        return Yii::$app->view->render('panels/user/summary', ['panel' => $this]);
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function getDetail()
48
    {
49
        return Yii::$app->view->render('panels/user/detail', ['panel' => $this]);
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55
    public function save()
56
    {
57
        $data = Yii::$app->user->identity;
58
59
        if (!isset($data)) {
60
            return ;
61
        }
62
63
        $authManager = Yii::$app->getAuthManager();
64
65
        $rolesProvider = null;
66
        $permissionsProvider = null;
67
68
        if ($authManager) {
69
            $rolesProvider = new ArrayDataProvider([
70
                'allModels' => $authManager->getRolesByUser($data),
71
            ]);
72
73
            $permissionsProvider = new ArrayDataProvider([
74
                'allModels' => $authManager->getPermissionsByUser($data),
75
76
            ]);
77
        }
78
79
        $attributes = array_keys(get_object_vars($data));
80
        if ($data instanceof ActiveRecord) {
81
            $attributes = array_keys($data->getAttributes());
82
        }
83
        
84
        return [
85
            'identity' => $data,
86
            'attributes' => $attributes,
87
            'rolesProvider' => $rolesProvider,
88
            'permissionsProvider' => $permissionsProvider,
89
        ];
90
    }
91
}
92