Added email notification on angeltype confirmation

main
Igor Scheller 3 years ago committed by msquare
parent 8d436d988a
commit 1e3bd9aaad

@ -1,6 +1,9 @@
<?php <?php
use Engelsystem\Mail\EngelsystemMailer;
use Engelsystem\Models\User\User; use Engelsystem\Models\User\User;
use Psr\Log\LoggerInterface;
use Swift_SwiftException as SwiftException;
/** /**
* Display a hint for team/angeltype supporters if there are unconfirmed users for his angeltype. * Display a hint for team/angeltype supporters if there are unconfirmed users for his angeltype.
@ -100,10 +103,17 @@ function user_angeltypes_confirm_all_controller(): array
} }
if ($request->hasPostData('confirm_all')) { if ($request->hasPostData('confirm_all')) {
$users = UserAngelTypes_all_unconfirmed($angeltype['id']);
UserAngelTypes_confirm_all($angeltype['id'], $user->id); UserAngelTypes_confirm_all($angeltype['id'], $user->id);
engelsystem_log(sprintf('Confirmed all users for angeltype %s', AngelType_name_render($angeltype, true))); 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))); 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']])); 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), User_Nick_render($user_source),
AngelType_name_render($angeltype) AngelType_name_render($angeltype)
)); ));
user_angeltype_confirm_email($user_source, $angeltype);
throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); 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. * Remove a user from an Angeltype.
* *

@ -142,6 +142,21 @@ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user_id)
', [$confirm_user_id, $angeltype_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. * Confirm an UserAngelType with confirming user.
* *

@ -139,5 +139,14 @@ msgstr "Es gibt eine neue News: %1$s"
msgid "notification.news.new.text" msgid "notification.news.new.text"
msgstr "Du kannst sie dir unter %3$s anschauen." 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" msgid "user.edit.success"
msgstr "Benutzer erfolgreich bearbeitet." msgstr "Benutzer erfolgreich bearbeitet."

@ -135,5 +135,14 @@ msgstr "A new news is available: %1$s"
msgid "notification.news.new.text" msgid "notification.news.new.text"
msgstr "You can watch it at %3$s" 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" msgid "user.edit.success"
msgstr "User edited successfully." msgstr "User edited successfully."

@ -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 %}

@ -4,4 +4,5 @@
{% block message %}{{ message|raw }}{% endblock %} {% 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 %} {% 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 %}

Loading…
Cancel
Save