Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 53
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
OlzAccountMenu
0.00% covered (danger)
0.00%
0 / 53
0.00% covered (danger)
0.00%
0 / 1
210
0.00% covered (danger)
0.00%
0 / 1
 getHtml
0.00% covered (danger)
0.00%
0 / 53
0.00% covered (danger)
0.00%
0 / 1
210
1<?php
2
3namespace Olz\Components\Auth\OlzAccountMenu;
4
5use Olz\Components\Common\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 .= "<a href='#' role='button' id='account-menu-link' data-bs-toggle='dropdown' aria-label='Benutzermenu' aria-haspopup='true' aria-expanded='false'>";
27        if ($show_notification_dot) {
28            $out .= "<div class='notification-dot'></div>";
29        }
30        $image_src_html = $this->htmlUtils()->getImageSrcHtml($image_paths);
31        $out .= "<img {$image_src_html} alt='' class='account-thumbnail' />";
32        $out .= "</a>";
33        $out .= "<div class='dropdown-menu dropdown-menu-end' aria-labelledby='account-menu-link'>";
34        if ($user && $auth_user) {
35            $out .= "<a class='dropdown-item' href='{$code_href}benutzer/ich'>";
36            if ($show_profile_notification_dot) {
37                $out .= "<div class='notification-dot'></div>";
38            }
39            $out .= "Profil</a>";
40
41            $entityManager = $this->dbUtils()->getEntityManager();
42            $user_repo = $entityManager->getRepository(User::class);
43            $child_users = $auth_user->getId() ?
44                $user_repo->findBy(['parent_user' => $auth_user->getId()]) : [];
45            $has_family = count($child_users) > 0;
46
47            if ($has_family) {
48                $out .= "<div class='dropdown-divider'></div>";
49                $is_current = $auth_user->getId() === $user->getId();
50                $class = $is_current ? ' disabled' : '';
51                $out .= <<<ZZZZZZZZZZ
52                    <a
53                        id='switch-user-{$auth_user->getId()}'
54                        class='dropdown-item{$class}'
55                        href='#'
56                        onclick='olz.olzAccountMenuSwitchUser({$auth_user->getId()})'
57                    >
58                        {$auth_user->getFullName()}
59                    </a>
60                    ZZZZZZZZZZ;
61
62                foreach ($child_users as $child_user) {
63                    $is_current = $child_user->getId() === $user->getId();
64                    $class = $is_current ? ' disabled' : '';
65                    $out .= <<<ZZZZZZZZZZ
66                        <a
67                            id='switch-user-{$child_user->getId()}'
68                            class='dropdown-item{$class}'
69                            href='#'
70                            onclick='olz.olzAccountMenuSwitchUser({$child_user->getId()})'
71                        >
72                            {$child_user->getFullName()}
73                        </a>
74                        ZZZZZZZZZZ;
75                }
76            }
77
78            $out .= <<<'ZZZZZZZZZZ'
79                <div class='dropdown-divider'></div>
80                <a
81                    id='logout-menu-item'
82                    class='dropdown-item'
83                    href='#'
84                    onclick='olz.olzAccountMenuLogout()'
85                >
86                    Logout
87                </a>
88                ZZZZZZZZZZ;
89        } else {
90            $out .= <<<'ZZZZZZZZZZ'
91                <a
92                    id='login-menu-item'
93                    class='dropdown-item'
94                    href='#login-dialog'
95                    role='button'
96                >
97                    Login
98                </a>
99                ZZZZZZZZZZ;
100        }
101        $out .= "</div>";
102
103        return $out;
104    }
105}