Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| OlzEmailCard | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 1 |
| getHtml | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Apps\Newsletter\Components\OlzEmailCard; |
| 4 | |
| 5 | use Olz\Apps\Newsletter\Components\OlzNotificationSubscriptionsForm\OlzNotificationSubscriptionsForm; |
| 6 | use Olz\Components\Common\OlzComponent; |
| 7 | use Olz\Entity\NotificationSubscription; |
| 8 | use Olz\Entity\Users\User; |
| 9 | |
| 10 | /** @extends OlzComponent<array<string, mixed>> */ |
| 11 | class OlzEmailCard extends OlzComponent { |
| 12 | public function getHtml(mixed $args): string { |
| 13 | $code_href = $this->envUtils()->getCodeHref(); |
| 14 | $entityManager = $this->dbUtils()->getEntityManager(); |
| 15 | $user_repo = $entityManager->getRepository(User::class); |
| 16 | $user = $this->authUtils()->getCurrentUser(); |
| 17 | |
| 18 | if ($user) { |
| 19 | $user_email = $user->getEmail(); |
| 20 | $has_email = $user_email !== null && strlen($user_email) > 0; |
| 21 | $is_email_verified = ( |
| 22 | $user->isEmailVerified() |
| 23 | || $this->authUtils()->hasPermission('verified_email', $user) |
| 24 | ); |
| 25 | |
| 26 | $notification_subscription_repo = $entityManager->getRepository(NotificationSubscription::class); |
| 27 | $subscriptions = $notification_subscription_repo->findBy(['user' => $user, 'delivery_type' => 'email']); |
| 28 | $form = OlzNotificationSubscriptionsForm::render(['subscriptions' => $subscriptions]); |
| 29 | |
| 30 | if (!$has_email) { |
| 31 | $content = <<<ZZZZZZZZZZ |
| 32 | <p class="card-text">Nichts verpassen mit dem E-Mail Newsletter in deiner Mailbox!</p> |
| 33 | <p class="card-text text-end"> |
| 34 | <a |
| 35 | href="{$code_href}benutzer/ich" |
| 36 | class="btn btn-light btn-sm" |
| 37 | > |
| 38 | E-Mail Adresse eintragen |
| 39 | </a> |
| 40 | </p> |
| 41 | ZZZZZZZZZZ; |
| 42 | } elseif (!$is_email_verified) { |
| 43 | $content = <<<ZZZZZZZZZZ |
| 44 | <p class="card-text">Nichts verpassen mit dem E-Mail Newsletter in deiner Mailbox!</p> |
| 45 | <p class="card-text text-end"> |
| 46 | <a |
| 47 | href="{$code_href}benutzer/ich" |
| 48 | class="btn btn-light btn-sm" |
| 49 | > |
| 50 | E-Mail Adresse bestätigen |
| 51 | </a> |
| 52 | </p> |
| 53 | ZZZZZZZZZZ; |
| 54 | } else { |
| 55 | $content = <<<ZZZZZZZZZZ |
| 56 | <form id='email-notifications-form' onsubmit='return olzNewsletter.olzEmailNotificationsUpdate(this)'> |
| 57 | <p class='card-title'><b>Du hast folgende Benachrichtigungen aktiviert:</b></p> |
| 58 | {$form} |
| 59 | <p class="card-text text-end"> |
| 60 | <button |
| 61 | id='email-notifications-submit' |
| 62 | type='submit' |
| 63 | class='btn btn-light btn-sm' |
| 64 | > |
| 65 | Speichern |
| 66 | </button> |
| 67 | </p> |
| 68 | <div id='email-notifications-success-message' class='alert alert-success' role='alert'></div> |
| 69 | <div id='email-notifications-error-message' class='alert alert-danger' role='alert'></div> |
| 70 | </form> |
| 71 | ZZZZZZZZZZ; |
| 72 | } |
| 73 | |
| 74 | return <<<ZZZZZZZZZZ |
| 75 | <div class="email-card card text-white bg-email mb-2"> |
| 76 | <h3 class="card-header"> |
| 77 | <img src='{$code_href}assets/icns/login_mail.svg' alt=''> |
| 78 | E-Mail Newsletter |
| 79 | </h3> |
| 80 | <div class="card-body"> |
| 81 | {$content} |
| 82 | </div> |
| 83 | </div> |
| 84 | ZZZZZZZZZZ; |
| 85 | } |
| 86 | return ''; |
| 87 | } |
| 88 | } |