Completed
Push — master ( a3d311...211d79 )
by Cheren
02:09
created

UserComponent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 59
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A implementedEvents() 0 6 1
A startup() 0 7 3
B _setupAdminProfileNavBar() 0 25 1
1
<?php
2
/**
3
 * CakeCMS Community
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package     Community
10
 * @license     MIT
11
 * @copyright   MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link        https://github.com/CakeCMS/Community".
13
 * @author      Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Community\Controller\Component;
17
18
use Cake\Event\Event;
19
use Core\Controller\Component\AppComponent;
20
use Core\Nav;
21
22
/**
23
 * Class UserComponent
24
 *
25
 * @package Community\Controller\Component
26
 */
27
class UserComponent extends AppComponent
28
{
29
30
    /**
31
     * Events supported by this component.
32
     *
33
     * @return array
34
     */
35
    public function implementedEvents()
36
    {
37
        return [
38
            'Controller.startup' => 'startup'
39
        ];
40
    }
41
42
    /**
43
     * Startup callback.
44
     *
45
     * @param Event $event
46
     */
47
    public function startup(Event $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
    {
49
        $prefix = $this->_controller->request->getParam('prefix');
50
        if ($prefix === 'admin' && $this->_controller->Auth->user('id')) {
51
            $this->_setupAdminProfileNavBar();
52
        }
53
    }
54
55
    /**
56
     * Setup profile nav bar for admin.
57
     *
58
     * @return void
59
     */
60
    protected function _setupAdminProfileNavBar()
61
    {
62
        Nav::add('profile', 'profile', [
63
            'weight' => 10,
64
            'icon'   => 'user',
65
            'title'  => __d('community', 'My profile'),
66
            'url'    => [
67
                'action'     => 'edit',
68
                'controller' => 'Users',
69
                'plugin'     => 'Community',
70
                $this->_controller->Auth->user('id')
71
            ]
72
        ]);
73
74
        Nav::add('profile', 'logout', [
75
            'weight' => 100,
76
            'icon'   => 'sign-out-alt',
77
            'title'  => __d('community', 'Logout'),
78
            'url' => [
79
                'controller' => 'Users',
80
                'action'     => 'logout',
81
                'plugin'     => 'Community'
82
            ]
83
        ]);
84
    }
85
}
86