Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| OlzTelegramCard | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| getHtml | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Apps\Newsletter\Components\OlzTelegramCard; |
| 4 | |
| 5 | use Olz\Apps\Newsletter\Components\OlzNotificationSubscriptionsForm\OlzNotificationSubscriptionsForm; |
| 6 | use Olz\Components\Common\OlzComponent; |
| 7 | use Olz\Entity\NotificationSubscription; |
| 8 | use Olz\Entity\TelegramLink; |
| 9 | use Olz\Repository\Faq\PredefinedQuestion; |
| 10 | |
| 11 | /** @extends OlzComponent<array<string, mixed>> */ |
| 12 | class OlzTelegramCard extends OlzComponent { |
| 13 | public function getHtml(mixed $args): string { |
| 14 | $entityManager = $this->dbUtils()->getEntityManager(); |
| 15 | $user = $this->authUtils()->getCurrentUser(); |
| 16 | $code_href = $this->envUtils()->getCodeHref(); |
| 17 | |
| 18 | if ($user) { |
| 19 | $telegram_link_repo = $entityManager->getRepository(TelegramLink::class); |
| 20 | $telegram_link = $telegram_link_repo->findOneBy(['user' => $user]); |
| 21 | $has_telegram_link = $telegram_link && $telegram_link->getTelegramChatId() !== null; |
| 22 | |
| 23 | $notification_subscription_repo = $entityManager->getRepository(NotificationSubscription::class); |
| 24 | $subscriptions = $notification_subscription_repo->findBy(['user' => $user, 'delivery_type' => 'telegram']); |
| 25 | $form = OlzNotificationSubscriptionsForm::render(['subscriptions' => $subscriptions]); |
| 26 | $telegram_question_ident = PredefinedQuestion::Telegram->value; |
| 27 | |
| 28 | if (!$has_telegram_link) { |
| 29 | $content = <<<ZZZZZZZZZZ |
| 30 | <p class="card-text">Mit der Chat-App Telegram halten wir dich immer auf dem Laufenden!</p> |
| 31 | <p class="card-text text-end"> |
| 32 | <a |
| 33 | href="#" |
| 34 | role="button" |
| 35 | onclick="olz.initOlzLinkTelegramModal()" |
| 36 | class="btn btn-light btn-sm" |
| 37 | > |
| 38 | Aktivieren |
| 39 | </a> |
| 40 | </p> |
| 41 | <p class="card-text"><a href='{$code_href}fragen_und_antworten/{$telegram_question_ident}' class='linkwhite'>Weshalb Telegram?</a></p> |
| 42 | ZZZZZZZZZZ; |
| 43 | } else { |
| 44 | $content = <<<ZZZZZZZZZZ |
| 45 | <form id='telegram-notifications-form' onsubmit='return olzNewsletter.olzTelegramNotificationsUpdate(this)'> |
| 46 | <p class='card-title'><b>Du hast folgende Benachrichtigungen aktiviert:</b></p> |
| 47 | {$form} |
| 48 | <p class="card-text text-end"> |
| 49 | <button |
| 50 | id='telegram-notifications-submit' |
| 51 | type='submit' |
| 52 | class='btn btn-light btn-sm' |
| 53 | > |
| 54 | Speichern |
| 55 | </button> |
| 56 | </p> |
| 57 | <div id='telegram-notifications-success-message' class='alert alert-success' role='alert'></div> |
| 58 | <div id='telegram-notifications-error-message' class='alert alert-danger' role='alert'></div> |
| 59 | <p class="card-text"><a href='{$code_href}fragen_und_antworten/{$telegram_question_ident}' class='linkwhite'>Weshalb Telegram?</a></p> |
| 60 | </form> |
| 61 | ZZZZZZZZZZ; |
| 62 | } |
| 63 | |
| 64 | return <<<ZZZZZZZZZZ |
| 65 | <div class="telegram-card card text-white bg-telegram mb-2"> |
| 66 | <h3 class="card-header"> |
| 67 | <img src='{$code_href}assets/icns/login_telegram.svg' alt=''> |
| 68 | Nachrichten-Push |
| 69 | </h3> |
| 70 | <div class="card-body"> |
| 71 | {$content} |
| 72 | </div> |
| 73 | </div> |
| 74 | ZZZZZZZZZZ; |
| 75 | } |
| 76 | return ''; |
| 77 | } |
| 78 | } |