From 1e3bd9aaad546c8cfad8304848f4513ff99dbdd2 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Wed, 15 Dec 2021 19:55:52 +0100 Subject: [PATCH] Added email notification on angeltype confirmation --- .../controller/user_angeltypes_controller.php | 43 +++++++++++++++++++ includes/model/UserAngelTypes_model.php | 15 +++++++ resources/lang/de_DE/additional.po | 9 ++++ resources/lang/en_US/additional.po | 9 ++++ .../views/emails/angeltype-confirmed.twig | 11 +++++ resources/views/emails/mail.twig | 1 + 6 files changed, 88 insertions(+) create mode 100644 resources/views/emails/angeltype-confirmed.twig diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index 71c86715..7672fadb 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -1,6 +1,9 @@ hasPostData('confirm_all')) { + $users = UserAngelTypes_all_unconfirmed($angeltype['id']); UserAngelTypes_confirm_all($angeltype['id'], $user->id); engelsystem_log(sprintf('Confirmed all users for angeltype %s', AngelType_name_render($angeltype, true))); success(sprintf(__('Confirmed all users for angeltype %s.'), AngelType_name_render($angeltype))); + + foreach ($users as $user) { + $user = User::find($user['user_id']); + user_angeltype_confirm_email($user, $angeltype); + } + throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); } @@ -164,6 +174,9 @@ function user_angeltype_confirm_controller(): array User_Nick_render($user_source), AngelType_name_render($angeltype) )); + + user_angeltype_confirm_email($user_source, $angeltype); + throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); } @@ -173,6 +186,36 @@ function user_angeltype_confirm_controller(): array ]; } +/** + * @param User $user + * @param array $angeltype + * @return void + */ +function user_angeltype_confirm_email(User $user, array $angeltype): void +{ + if (!$user->settings->email_shiftinfo) { + return; + } + + try { + /** @var EngelsystemMailer $mailer */ + $mailer = app(EngelsystemMailer::class); + $mailer->sendViewTranslated( + $user, + 'notification.angeltype.confirmed', + 'emails/angeltype-confirmed', + ['name' => $angeltype['name'], 'angeltype' => $angeltype, 'username' => $user->name] + ); + } catch (SwiftException $e) { + /** @var LoggerInterface $logger */ + $logger = app('logger'); + $logger->error( + 'Unable to send email "{title}" to user {user} with {exception}', + ['title' => __('notification.angeltype.confirmed'), 'user' => $user->name, 'exception' => $e] + ); + } +} + /** * Remove a user from an Angeltype. * diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php index 3ed7c987..880faf9d 100644 --- a/includes/model/UserAngelTypes_model.php +++ b/includes/model/UserAngelTypes_model.php @@ -142,6 +142,21 @@ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user_id) ', [$confirm_user_id, $angeltype_id]); } +/** + * Get all unconfirmed Users for given Angeltype + * + * @param int $angeltype_id + */ +function UserAngelTypes_all_unconfirmed($angeltype_id) +{ + return DB::select(' + SELECT * + FROM `UserAngelTypes` + WHERE `angeltype_id`=? + AND `confirm_user_id` IS NULL + ', [$angeltype_id]); +} + /** * Confirm an UserAngelType with confirming user. * diff --git a/resources/lang/de_DE/additional.po b/resources/lang/de_DE/additional.po index 48dc9c4d..53c9bf40 100644 --- a/resources/lang/de_DE/additional.po +++ b/resources/lang/de_DE/additional.po @@ -139,5 +139,14 @@ msgstr "Es gibt eine neue News: %1$s" msgid "notification.news.new.text" msgstr "Du kannst sie dir unter %3$s anschauen." +msgid "notification.angeltype.confirmed" +msgstr "Du wurdest als %s bestätigt" + +msgid "notification.angeltype.confirmed.introduction" +msgstr "Du wurdest von einem Supporter als %1$s bestätigt." + +msgid "notification.angeltype.confirmed.text" +msgstr "Eine Beschreibung findest du unter %2$s" + msgid "user.edit.success" msgstr "Benutzer erfolgreich bearbeitet." diff --git a/resources/lang/en_US/additional.po b/resources/lang/en_US/additional.po index 2b399111..ce32fba5 100644 --- a/resources/lang/en_US/additional.po +++ b/resources/lang/en_US/additional.po @@ -135,5 +135,14 @@ msgstr "A new news is available: %1$s" msgid "notification.news.new.text" msgstr "You can watch it at %3$s" +msgid "notification.angeltype.confirmed" +msgstr "You have been confirmed as an %s" + +msgid "notification.angeltype.confirmed.introduction" +msgstr "You have been confirmed as an %1$s by a supporter." + +msgid "notification.angeltype.confirmed.text" +msgstr "You can find a description at %2$s" + msgid "user.edit.success" msgstr "User edited successfully." diff --git a/resources/views/emails/angeltype-confirmed.twig b/resources/views/emails/angeltype-confirmed.twig new file mode 100644 index 00000000..1fd2d0b1 --- /dev/null +++ b/resources/views/emails/angeltype-confirmed.twig @@ -0,0 +1,11 @@ +{% extends "emails/mail.twig" %} + +{% set url=url('/angeltypes', {'action': 'view', 'angeltype_id': angeltype.id}) %} + +{% block introduction %} +{{ __('notification.angeltype.confirmed.introduction', [angeltype.name, url])|raw }} +{% endblock %} + +{% block message %} +{{ __('notification.angeltype.confirmed.text', [angeltype.name, url])|raw }} +{% endblock %} diff --git a/resources/views/emails/mail.twig b/resources/views/emails/mail.twig index d6675f51..3c9f7537 100644 --- a/resources/views/emails/mail.twig +++ b/resources/views/emails/mail.twig @@ -4,4 +4,5 @@ {% block message %}{{ message|raw }}{% endblock %} +{{ '-- ' }} {% block footer %}{{ __('This email is autogenerated and has not been signed. You got this email because you are registered in the %s.', [config('app_name')]) }}{% endblock %}