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