ProfileMenu::run()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 3
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace humhub\modules\user\widgets;
4
5
use Yii;
6
use humhub\modules\user\models\User;
7
use humhub\modules\user\permissions\ViewAboutPage;
8
9
class ProfileMenu extends \humhub\widgets\BaseMenu
10
{
11
    /**
12
     * @var User
13
     */
14
    public $user;
15
    /**
16
     * @inheritdoc
17
     */
18
    public $template = "@humhub/widgets/views/leftNavigation";
19
    /**
20
     * @inheritdoc
21
     */
22
    public function init()
23
    {
24
        $this->addItemGroup([
25
            'id' => 'profile',
26
            'label' => Yii::t('UserModule.widgets_ProfileMenuWidget', '<strong>Profile</strong> menu'),
27
            'sortOrder' => 100,
28
        ]);
29
        $this->addItem([
30
            'label' => Yii::t('UserModule.widgets_ProfileMenuWidget', 'Stream'),
31
            'group' => 'profile',
32
            'icon' => '<i class="fa fa-bars"></i>',
33
            'url' => $this->user->createUrl('//user/profile/home'),
34
            'sortOrder' => 200,
35
            'isActive' => (Yii::$app->controller->id == "profile" && (Yii::$app->controller->action->id == "index" || Yii::$app->controller->action->id == "home")),
36
        ]);
37
        if ($this->user->permissionManager->can(new ViewAboutPage())) {
38
            $this->addItem([
39
                'label' => Yii::t('UserModule.widgets_ProfileMenuWidget', 'About'),
40
                'group' => 'profile',
41
                'icon' => '<i class="fa fa-info-circle"></i>',
42
                'url' => $this->user->createUrl('//user/profile/about'),
43
                'sortOrder' => 300,
44
                'isActive' => (Yii::$app->controller->id == "profile" && Yii::$app->controller->action->id == "about"),
45
            ]);
46
        }
47
        parent::init();
48
    }
49
    /**
50
     * @inheritdoc
51
     */
52
    public function run()
53
    {
54
        if (Yii::$app->user->isGuest && $this->user->visibility != User::VISIBILITY_ALL) {
55
            return;
56
        }
57
        return parent::run();
58
    }
59
}
60
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
61