Manual mails can be sent

This commit is contained in:
2026-04-18 20:52:13 +02:00
parent ed7f887e3a
commit ff98f0860c
235 changed files with 151212 additions and 50 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Domains\Event\Controllers\MailCompose;
use App\Scopes\CommonController;
use Illuminate\Http\Request;
class ByGroupController extends CommonController
{
public function __invoke(string $eventIdentifier, string $groupType, Request $request) {
$event = $this->events->getByIdentifier($eventIdentifier, true);
$recipients = [];
switch ($groupType) {
case 'by-local-group':
$participants = $this->eventParticipants->groupByLocalGroup($event, $request, $request->input('groupName'));
$recipients = $this->eventParticipants->getMailAddresses($participants[$request->input('groupName')]);
break;
case 'by-participation-group':
$participants = $this->eventParticipants->groupByParticipationType($event, $request, $request->input('groupName'));
$recipients = $this->eventParticipants->getMailAddresses($participants[$request->input('groupName')]);
break;
case 'signed-off':
$participants = $this->eventParticipants->getSignedOffParticipants($event, $request, $request->input('groupName'));
$recipients = $this->eventParticipants->getMailAddresses($participants[$request->input('groupName')]);
break;
default:
$participants = $this->eventParticipants->getForList($event, $request);
$recipients = $this->eventParticipants->getMailAddresses($participants);
}
return response()->json(['recipients' => $recipients]);
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Domains\Event\Controllers\MailCompose;
use App\Mail\ManualMails\ManualMailsCommonMail;
use App\Mail\ManualMails\ManualMailsReportMail;
use App\Mail\ParticipantCocMails\ParticipantCocCompleteMail;
use App\Scopes\CommonController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
class SendController extends CommonController
{
public function __invoke(string $eventIdentifier, Request $request) {
$recipients = $request->input('recipients')
|> function (string $value) : string { return str_replace(';', ',', $value); }
|> function (string $value) : array { return explode( ',', $value); };
$event = $this->events->getByIdentifier($eventIdentifier, true)->toResource()->toArray($request);
$sentRecipients = [];
$allOkay = true;
$subject = $request->input('subject') ?? 'Neue Nachricht zu Veranstaltung "' . $event['name'] . '"';
foreach ($recipients as $recipient) {
if (in_array($recipient, $sentRecipients)) {
continue;
}
$sentRecipients[] = $recipient;
try {
Mail::to(trim($recipient))->send(new ManualMailsCommonMail(
mailSubject: $subject,
message: $request->input('message'),
event: $event,
));
} catch (\Exception $e) {
$allOkay = false;
}
}
$user = auth()->user();
$reportSubject = sprintf('Sendebericht für Nachricht mit Betreff "%s"', $subject);
Mail::to($user->email)->send(new ManualMailsReportMail(
mailSubject: $reportSubject,
message: $request->input('message'),
event: $event,
originalRecipients: $sentRecipients
));
if ($allOkay) {
return response()->json([
'success' => true,
'message' => sprintf(
'E-Mail wurde erfolgreich an %1$s Personen versendet. Du hast eine Kopie an deine Mail-Adresse erhalten.',
count($sentRecipients)
),
]);
} else {
return response()->json([
'success' => false,
'message' => 'Es gab einen Fehler beim Versenden der Nachrichten.'
]);
}
}
}