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