Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
40.38% covered (danger)
40.38%
21 / 52
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
OlzAccountMenu
40.38% covered (danger)
40.38%
21 / 52
0.00% covered (danger)
0.00%
0 / 1
55.53
0.00% covered (danger)
0.00%
0 / 1
 getHtml
40.38% covered (danger)
40.38%
21 / 52
0.00% covered (danger)
0.00%
0 / 1
55.53
1<?php
2
3namespace Olz\Common\Components\OlzAccountMenu;
4
5use Olz\Common\Components\OlzComponent;
6use Olz\Entity\Users\User;
7
8/** @extends OlzComponent<array<string, mixed>> */
9class OlzAccountMenu extends OlzComponent {
10    public function getHtml(mixed $args): string {
11        $out = '';
12
13        $auth_user = $this->authUtils()->getCurrentAuthUser();
14        $user = $this->authUtils()->getCurrentUser();
15        $image_paths = $this->authUtils()->getUserAvatar($user);
16        $code_href = $this->envUtils()->getCodeHref();
17        $should_verify_email = (
18            $user
19            && !$user->getParentUserId()
20            && !$user->isEmailVerified()
21            && !$this->authUtils()->hasPermission('verified_email', $user)
22        );
23        $show_profile_notification_dot = $should_verify_email;
24        $show_notification_dot = $user && $show_profile_notification_dot;
25
26        $out .= <<<'ZZZZZZZZZZ'
27            <a
28                href='#'
29                role='button'
30                id='account-menu-link'
31                data-bs-toggle='dropdown'
32                aria-label='Benutzermenu'
33                aria-haspopup='true'
34                aria-expanded='false'
35            >
36            ZZZZZZZZZZ;
37        if ($show_notification_dot) {
38            $out .= "<div class='notification-dot'></div>";
39        }
40        $image_src_html = $this->htmlUtils()->getImageSrcHtml($image_paths);
41        $out .= "<img {$image_src_html} alt='' class='account-thumbnail' />";
42        $out .= "</a>";
43        $out .= "<div class='dropdown-menu dropdown-menu-end' aria-labelledby='account-menu-link'>";
44        if ($user && $auth_user) {
45            $out .= "<a class='dropdown-item' href='{$code_href}benutzer/ich'>";
46            if ($show_profile_notification_dot) {
47                $out .= "<div class='notification-dot'></div>";
48            }
49            $out .= "Profil</a>";
50
51            $entityManager = $this->dbUtils()->getEntityManager();
52            $user_repo = $entityManager->getRepository(User::class);
53            $child_users = $auth_user->getId() ?
54                $user_repo->findBy(['parent_user' => $auth_user->getId()]) : [];
55            $has_family = count($child_users) > 0;
56
57            if ($has_family) {
58                $out .= "<div class='dropdown-divider'></div>";
59                $is_current = $auth_user->getId() === $user->getId();
60                $class = $is_current ? ' disabled' : '';
61                $out .= <<<ZZZZZZZZZZ
62                    <a
63                        id='switch-user-{$auth_user->getId()}'
64                        class='dropdown-item{$class}'
65                        href='#'
66                        onclick='olz.olzAccountMenuSwitchUser({$auth_user->getId()})'
67                    >
68                        {$auth_user->getFullName()}
69                    </a>
70                    ZZZZZZZZZZ;
71
72                foreach ($child_users as $child_user) {
73                    $is_current = $child_user->getId() === $user->getId();
74                    $class = $is_current ? ' disabled' : '';
75                    $out .= <<<ZZZZZZZZZZ
76                        <a
77                            id='switch-user-{$child_user->getId()}'
78                            class='dropdown-item{$class}'
79                            href='#'
80                            onclick='olz.olzAccountMenuSwitchUser({$child_user->getId()})'
81                        >
82                            {$child_user->getFullName()}
83                        </a>
84                        ZZZZZZZZZZ;
85                }
86            }
87
88            $out .= <<<'ZZZZZZZZZZ'
89                <div class='dropdown-divider'></div>
90                <a
91                    id='logout-menu-item'
92                    class='dropdown-item'
93                    href='#'
94                    onclick='olz.olzAccountMenuLogout()'
95                >
96                    Logout
97                </a>
98                ZZZZZZZZZZ;
99        } else {
100            $out .= <<<'ZZZZZZZZZZ'
101                <a
102                    id='login-menu-item'
103                    class='dropdown-item'
104                    href='#login-dialog'
105                    role='button'
106                >
107                    Login
108                </a>
109                ZZZZZZZZZZ;
110        }
111        $out .= "</div>";
112
113        return $out;
114    }
115}