feat: add mailing templates and mail the confirmed teamers of selected assignments

This commit is contained in:
fromme committed 2026-11-11 14:02:55 +01:00
1 parent 6c89f1b8a9
commit e285646bb2
57 files changed
+3525 -31

No files matched your search

@@ -0,0 +1,99 @@
<?php
namespace App\Controller\Administrative\AssignmentMailing;
use App\Controller\Traits\AuthenticatedUserTrait;
use App\Email\MailBodyRenderer;
use App\Entity\Upload;
use App\Form\AssignmentMailingAddType;
use App\Form\AssignmentMailingType;
use App\Model\AssignmentMailingDto;
use App\Service\Teamer\AssignmentMailingDraftHandler;
use App\Service\Teamer\AssignmentMailingService;
use App\Service\Teamer\MailingAttachmentHandler;
use App\Service\Teamer\TeamerMailingService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Service\Attribute\Required;
/**
* What the actions of the assignment mailing share: the draft, the form over its wording and the
* pieces of the compose page that htmx swaps on their own.
*/
abstract class AbstractAssignmentMailingController extends AbstractController
{
use AuthenticatedUserTrait;
protected AssignmentMailingDraftHandler $draftHandler;
protected AssignmentMailingService $mailingService;
protected MailingAttachmentHandler $attachmentHandler;
protected TeamerMailingService $teamerMailingService;
protected MailBodyRenderer $mailBodyRenderer;
#[Required]
public function setMailingDependencies(
AssignmentMailingDraftHandler $draftHandler,
AssignmentMailingService $mailingService,
MailingAttachmentHandler $attachmentHandler,
TeamerMailingService $teamerMailingService,
MailBodyRenderer $mailBodyRenderer,
): void {
$this->draftHandler = $draftHandler;
$this->mailingService = $mailingService;
$this->attachmentHandler = $attachmentHandler;
$this->teamerMailingService = $teamerMailingService;
$this->mailBodyRenderer = $mailBodyRenderer;
}
/**
* The form over the draft: a GET shows the parked wording, a POST carries the current one.
* Assignments and template stay what the draft says, the form has no fields for them.
*/
protected function createMailingForm(Request $request, ?AssignmentMailingDto $mailingDto = null): FormInterface
{
$form = $this->createForm(AssignmentMailingType::class, $mailingDto ?? $this->draftHandler->getDraft());
$form->handleRequest($request);
return $form;
}
/**
* What the composing user would receive, see the teamer mailing's renderPreview().
*
* @return array{subject: string, bodyHtml: string}
*/
protected function renderPreview(AssignmentMailingDto $mailingDto): array
{
$values = $this->teamerMailingService->placeholderValuesForUser($this->getAuthenticatedUser());
return [
'subject' => $this->teamerMailingService->render($mailingDto->getSubject(), $values),
'bodyHtml' => $this->mailBodyRenderer->render($mailingDto->getMessage(), $values),
];
}
/**
* For administrative/assignment_mailing/_assignments.html.twig.
*/
protected function assignmentsContext(AssignmentMailingDto $mailingDto): array
{
return [
'mailingDto' => $mailingDto,
'recipients' => $this->mailingService->resolveRecipients($mailingDto),
'addForm' => $this->createForm(AssignmentMailingAddType::class)->createView(),
];
}
/**
* For administrative/assignment_mailing/_attachments.html.twig.
*/
protected function attachmentsContext(AssignmentMailingDto $mailingDto): array
{
return [
'mailingDto' => $mailingDto,
'pending' => $this->attachmentHandler->getPending(Upload::TYPE_MAILING_ATTACHMENT),
'maxAttachmentBytes' => MailingAttachmentHandler::MAX_TOTAL_BYTES,
];
}
}