Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
Messages | |
100.00% |
14 / 14 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
created | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
sendMail | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Engelsystem\Events\Listener; |
6 | |
7 | use Engelsystem\Mail\EngelsystemMailer; |
8 | use Engelsystem\Models\Message; |
9 | use Engelsystem\Models\User\User; |
10 | use Psr\Log\LoggerInterface; |
11 | |
12 | class Messages |
13 | { |
14 | public function __construct( |
15 | protected LoggerInterface $log, |
16 | protected EngelsystemMailer $mailer |
17 | ) { |
18 | } |
19 | |
20 | public function created(Message $message): void |
21 | { |
22 | if (!$message->receiver->settings->email_messages) { |
23 | return; |
24 | } |
25 | |
26 | $this->sendMail($message, $message->receiver, 'notification.messages.new', 'emails/messages-new'); |
27 | } |
28 | |
29 | private function sendMail(Message $message, User $user, string $subject, string $template): void |
30 | { |
31 | $this->mailer->sendViewTranslated( |
32 | $user, |
33 | $subject, |
34 | $template, |
35 | [ |
36 | 'sender' => $message->sender->displayName, |
37 | 'send_message' => $message, |
38 | 'username' => $user->displayName, |
39 | ] |
40 | ); |
41 | } |
42 | } |