Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       0.00%  | 
       0 / 90  | 
               | 
       0.00%  | 
       0 / 3  | 
       CRAP |         | 
       0.00%  | 
       0 / 1  | 
      
| OlzUserDetail |         | 
       0.00%  | 
       0 / 90  | 
               | 
       0.00%  | 
       0 / 3  | 
       506 |         | 
       0.00%  | 
       0 / 1  | 
      
| getSearchTitle |         | 
       0.00%  | 
       0 / 1  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| getSearchResults |         | 
       0.00%  | 
       0 / 1  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| getHtml |         | 
       0.00%  | 
       0 / 88  | 
               | 
       0.00%  | 
       0 / 1  | 
       420 | |||
| 1 | <?php | 
| 2 | |
| 3 | namespace Olz\Users\Components\OlzUserDetail; | 
| 4 | |
| 5 | use Olz\Components\Common\OlzRootComponent; | 
| 6 | use Olz\Components\Page\OlzFooter\OlzFooter; | 
| 7 | use Olz\Components\Page\OlzHeader\OlzHeader; | 
| 8 | use Olz\Entity\Users\User; | 
| 9 | |
| 10 | /** @extends OlzRootComponent<array<string, mixed>> */ | 
| 11 | class OlzUserDetail extends OlzRootComponent { | 
| 12 | public function getSearchTitle(): string { | 
| 13 | return 'TODO'; | 
| 14 | } | 
| 15 | |
| 16 | public function getSearchResults(array $terms): array { | 
| 17 | return []; | 
| 18 | } | 
| 19 | |
| 20 | public function getHtml(mixed $args): string { | 
| 21 | $code_href = $this->envUtils()->getCodeHref(); | 
| 22 | $user_repo = $this->entityManager()->getRepository(User::class); | 
| 23 | $user = $user_repo->findOneBy(['id' => $args['id']]); | 
| 24 | |
| 25 | if (!$user) { | 
| 26 | $this->httpUtils()->dieWithHttpError(404); | 
| 27 | throw new \Exception('should already have failed'); | 
| 28 | } | 
| 29 | |
| 30 | $out = OlzHeader::render([ | 
| 31 | 'back_link' => "{$code_href}verein", | 
| 32 | 'title' => $user->getFullName(), | 
| 33 | 'description' => "{$user->getFullName()} - Profil.", | 
| 34 | 'norobots' => true, | 
| 35 | ]); | 
| 36 | |
| 37 | $out .= "<div class='content-full olz-user-detail'>"; | 
| 38 | |
| 39 | $image_paths = $this->authUtils()->getUserAvatar($user); | 
| 40 | $image_src_html = $this->htmlUtils()->getImageSrcHtml($image_paths); | 
| 41 | $img_html = "<img {$image_src_html} alt='' class='image'>"; | 
| 42 | |
| 43 | $auth_user_id = $this->session()->get('auth_user_id'); | 
| 44 | $is_parent = $auth_user_id && intval($user->getParentUserId()) === intval($auth_user_id); | 
| 45 | $is_self = $auth_user_id && intval($user->getId()) === intval($auth_user_id); | 
| 46 | $has_permissions = $this->authUtils()->hasPermission('users'); | 
| 47 | $can_edit = $is_parent || $is_self || $has_permissions; | 
| 48 | $edit_admin = ''; | 
| 49 | $edit_password = ''; | 
| 50 | if ($can_edit) { | 
| 51 | $json_id = json_encode($user->getId()); | 
| 52 | $edit_admin = <<<ZZZZZZZZZZ | 
| 53 | <div> | 
| 54 | <button | 
| 55 | id='edit-user-button' | 
| 56 | class='btn btn-primary' | 
| 57 | onclick='return olz.editUser({$json_id})' | 
| 58 | > | 
| 59 | <img src='{$code_href}assets/icns/edit_white_16.svg' class='noborder' /> | 
| 60 | Bearbeiten | 
| 61 | </button> | 
| 62 | </div> | 
| 63 | ZZZZZZZZZZ; | 
| 64 | $edit_password = <<<'ZZZZZZZZZZ' | 
| 65 | <button | 
| 66 | class='btn btn-secondary' | 
| 67 | onclick='return olz.initOlzChangePasswordModal()' | 
| 68 | id='change-password-button' | 
| 69 | > | 
| 70 | Passwort ändern | 
| 71 | </button> | 
| 72 | ZZZZZZZZZZ; | 
| 73 | } | 
| 74 | |
| 75 | $street = $user->getStreet() ?? '(Keine Adresse)'; | 
| 76 | $postal_code = $user->getPostalCode() ?? '(Keine PLZ)'; | 
| 77 | $city = $user->getCity() ?? '(Kein Ort)'; | 
| 78 | $region = $user->getRegion() ?? 'Keine Region'; | 
| 79 | $country_code = $user->getCountryCode() ?? 'Kein Land'; | 
| 80 | $birthdate = $user->getBirthdate()?->format('d.m.Y') ?? '(Unbekannt)'; | 
| 81 | $phone = $user->getPhone() ?? '(Unbekannt)'; | 
| 82 | |
| 83 | if ( | 
| 84 | !$user->getParentUserId() | 
| 85 | && !$user->isEmailVerified() | 
| 86 | && !$this->authUtils()->hasPermission('verified_email', $user) | 
| 87 | ) { | 
| 88 | if ($user->getEmailVerificationToken()) { | 
| 89 | $out .= <<<'ZZZZZZZZZZ' | 
| 90 | <div class='alert alert-danger' role='alert'> | 
| 91 | Deine E-Mail-Adresse ist noch nicht bestätigt. Bitte prüfe deine Inbox (und dein Spam-Postfach) auf unsere Bestätigungs-E-Mail (Betreff: "[OLZ] E-Mail bestätigen"). | 
| 92 | <a | 
| 93 | href='#' | 
| 94 | onclick='olz.initOlzVerifyUserEmailModal()' | 
| 95 | id='verify-user-email-link' | 
| 96 | > | 
| 97 | Erneut senden | 
| 98 | </a> | 
| 99 | </div> | 
| 100 | ZZZZZZZZZZ; | 
| 101 | } else { | 
| 102 | $out .= <<<'ZZZZZZZZZZ' | 
| 103 | <div class='alert alert-danger' role='alert'> | 
| 104 | Deine E-Mail-Adresse ist noch nicht bestätigt. | 
| 105 | <a | 
| 106 | href='#' | 
| 107 | onclick='olz.initOlzVerifyUserEmailModal()' | 
| 108 | id='verify-user-email-link' | 
| 109 | > | 
| 110 | Jetzt bestätigen | 
| 111 | </a> | 
| 112 | </div> | 
| 113 | ZZZZZZZZZZ; | 
| 114 | } | 
| 115 | } | 
| 116 | |
| 117 | $out .= "<div class='edit-user-container'>{$edit_admin}</div>"; | 
| 118 | $out .= "<div class='image-container'>{$img_html}</div>"; | 
| 119 | $out .= "<h1 class='name-container'>{$user->getFullName()}</h1>"; | 
| 120 | $out .= "<div class='info-container username'>Benutzername: {$user->getUsername()}</div>"; | 
| 121 | if ($can_edit) { | 
| 122 | $out .= "<div class='info-container address1'>{$street}</div>"; | 
| 123 | $out .= "<div class='info-container address2'>{$postal_code} {$city} ({$region}, {$country_code})</div>"; | 
| 124 | $out .= "<div class='info-container birthdate'>Geburtsdatum: {$birthdate}</div>"; | 
| 125 | $out .= "<div class='info-container phone'>Telephon: {$phone}</div>"; | 
| 126 | } | 
| 127 | |
| 128 | $has_official_email = $this->authUtils()->hasPermission('user_email', $user); | 
| 129 | $email_html = ''; | 
| 130 | if ($has_official_email) { | 
| 131 | $host = $this->envUtils()->getEmailForwardingHost(); | 
| 132 | $email = "{$user->getUsername()}@{$host}"; | 
| 133 | $email_html = $this->htmlUtils()->replaceEmailAdresses($email); | 
| 134 | } else { | 
| 135 | $email_html = ( | 
| 136 | $user->getEmail() | 
| 137 | ? $this->htmlUtils()->replaceEmailAdresses($user->getEmail()) | 
| 138 | : '' | 
| 139 | ); | 
| 140 | } | 
| 141 | if ($email_html) { | 
| 142 | $out .= "<div class='info-container email'>{$email_html}</div>"; | 
| 143 | } | 
| 144 | $out .= $edit_password; | 
| 145 | |
| 146 | if ($can_edit) { | 
| 147 | $out .= "<h2>Familie</h2>"; | 
| 148 | $child_users = $user_repo->findBy(['parent_user' => $user->getId()]); | 
| 149 | if ($child_users) { | 
| 150 | $out .= "<ul class='info-container'>"; | 
| 151 | foreach ($child_users as $child_user) { | 
| 152 | $out .= "<li>Familienmitglied <a href='{$code_href}benutzer/{$child_user->getId()}'>{$child_user->getFullName()}</a></li>"; | 
| 153 | } | 
| 154 | $out .= "</ul>"; | 
| 155 | } | 
| 156 | if ($user->getParentUserId()) { | 
| 157 | $parent_user = $user_repo->findOneBy(['id' => $user->getParentUserId()]); | 
| 158 | $out .= "<div class='info-container'>Familienmitglied von <a href='{$code_href}benutzer/{$parent_user?->getId()}'>{$parent_user?->getFullName()}</a></div>"; | 
| 159 | if ($child_users) { | 
| 160 | $this->log()->warning("User {$user->getId()} has parent and children."); | 
| 161 | } | 
| 162 | } else { | 
| 163 | $json_id = json_encode($user->getId()); | 
| 164 | $out .= <<<ZZZZZZZZZZ | 
| 165 | <div> | 
| 166 | <button | 
| 167 | id='add-child-user-button' | 
| 168 | class='btn btn-secondary' | 
| 169 | onclick='return olz.addChildUser({$json_id})' | 
| 170 | > | 
| 171 | <img src='{$code_href}assets/icns/new_white_16.svg' class='noborder' /> | 
| 172 | Familienmitglied hinzufügen | 
| 173 | </button> | 
| 174 | </div> | 
| 175 | ZZZZZZZZZZ; | 
| 176 | } | 
| 177 | } | 
| 178 | $out .= "</div>"; | 
| 179 | |
| 180 | $out .= OlzFooter::render(); | 
| 181 | |
| 182 | return $out; | 
| 183 | } | 
| 184 | } |