UserComponent::implementedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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
     * @throws  \Aura\Intl\Exception
48
     */
49
    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...
50
    {
51
        $prefix = $this->_controller->request->getParam('prefix');
52
        if ($prefix === 'admin' && $this->_controller->Auth->user('id')) {
53
            $this->_setupAdminProfileNavBar();
54
        }
55
    }
56
57
    /**
58
     * Setup profile nav bar for admin.
59
     *
60
     * @return  void
61
     *
62
     * @throws  \Aura\Intl\Exception
63
     */
64
    protected function _setupAdminProfileNavBar()
65
    {
66
        Nav::add('profile', 'profile', [
67
            'weight' => 10,
68
            'icon'   => 'user',
69
            'title'  => __d('community', 'My profile'),
70
            'url'    => [
71
                'action'     => 'edit',
72
                'controller' => 'Users',
73
                'plugin'     => 'Community',
74
                $this->_controller->Auth->user('id')
75
            ]
76
        ]);
77
78
        Nav::add('profile', 'logout', [
79
            'weight' => 100,
80
            'icon'   => 'sign-out-alt',
81
            'title'  => __d('community', 'Logout'),
82
            'url' => [
83
                'controller' => 'Users',
84
                'action'     => 'logout',
85
                'plugin'     => 'Community'
86
            ]
87
        ]);
88
    }
89
}
90