feat: add mailing templates and mail the confirmed teamers of selected assignments
This commit is contained in:
1 parent
6c89f1b8a9
commit
e285646bb2
57 files changed
+3525
-31
No files matched your search
+99
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\AssignmentMailing;
|
||||
|
||||
use App\Entity\Assignment;
|
||||
use App\Form\AssignmentMailingAddType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class AddAssignmentController extends AbstractAssignmentMailingController
|
||||
{
|
||||
#[Route('/administrative/assignment/mailing/add', name: 'app_administrative_assignment_mailing_add', methods: ['POST'])]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$mailingDto = $this->draftHandler->getDraft();
|
||||
|
||||
$form = $this->createForm(AssignmentMailingAddType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
/** @var Assignment|null $assignment */
|
||||
$assignment = $form->isSubmitted() && $form->isValid() ? $form->get('assignment')->getData() : null;
|
||||
|
||||
if (null !== $assignment && false === $assignment->isDeleted()
|
||||
&& false === in_array($assignment, $mailingDto->getAssignments(), true)) {
|
||||
$this->draftHandler->saveDraft(
|
||||
$mailingDto->setAssignments([...$mailingDto->getAssignments(), $assignment])
|
||||
);
|
||||
|
||||
// read back, so the list comes in the draft's order
|
||||
$mailingDto = $this->draftHandler->getDraft();
|
||||
}
|
||||
|
||||
return $this->render('administrative/assignment_mailing/_assignments.html.twig', $this->assignmentsContext($mailingDto));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\AssignmentMailing;
|
||||
|
||||
use App\Controller\Traits\ReturnUrlTrait;
|
||||
use App\Entity\Upload;
|
||||
use App\Repository\MailingTemplateRepository;
|
||||
use App\Service\Teamer\TeamerMailingService;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
/**
|
||||
* Compose a mail to the teamers confirmed on a set of assignments.
|
||||
*
|
||||
* Arriving from the overview's "Mail an Teamer:innen" (?start=1, plus the ticked assignments)
|
||||
* starts a new mailing for them; arriving otherwise continues the one in the draft. A submit of the form sends the preview
|
||||
* to the composing user, the real send goes through the confirmation modal.
|
||||
*/
|
||||
class ComposeController extends AbstractAssignmentMailingController
|
||||
{
|
||||
use ReturnUrlTrait;
|
||||
|
||||
public function __construct(private readonly MailingTemplateRepository $mailingTemplateRepository)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/administrative/assignment/mailing', name: 'app_administrative_assignment_mailing_compose')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
if (true === $request->query->has('start')) {
|
||||
$omitted = $this->draftHandler->startDraft(array_filter($request->query->all('assignments'), 'is_string'));
|
||||
$this->attachmentHandler->discardPending(Upload::TYPE_MAILING_ATTACHMENT);
|
||||
|
||||
if ($omitted > 0) {
|
||||
$this->addFlash('info', 1 === $omitted
|
||||
? 'Ein Einsatz ohne bestätigte Teamer:innen wurde weggelassen'
|
||||
: sprintf('%d Einsätze ohne bestätigte Teamer:innen wurden weggelassen', $omitted));
|
||||
}
|
||||
|
||||
// without the selection in the address, a reload continues this mailing instead of
|
||||
// starting it over
|
||||
return $this->redirectToRoute('app_administrative_assignment_mailing_compose', [
|
||||
'r' => $request->query->get('r'),
|
||||
]);
|
||||
}
|
||||
|
||||
$form = $this->createMailingForm($request);
|
||||
$mailingDto = $form->getData();
|
||||
|
||||
if ($form->isSubmitted()) {
|
||||
$this->draftHandler->saveDraft($mailingDto);
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
if (null !== $error = $this->mailingService->validateAttachments($mailingDto)) {
|
||||
$this->addFlash('error', $error);
|
||||
} else {
|
||||
$this->mailingService->sendPreview($mailingDto, $this->getAuthenticatedUser());
|
||||
|
||||
$this->addFlash('success', sprintf(
|
||||
'Die Vorschau wurde an %s gesendet',
|
||||
$this->getAuthenticatedUser()->getUserIdentifier()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// no redirect after the preview mail, the composed mail has to survive it
|
||||
return $this->render('administrative/assignment_mailing/compose.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'mailingDto' => $mailingDto,
|
||||
'preview' => $this->renderPreview($mailingDto),
|
||||
'templates' => $this->mailingTemplateRepository->findActive(),
|
||||
'placeholders' => TeamerMailingService::PLACEHOLDERS,
|
||||
'hasDraft' => $this->draftHandler->hasDraft(),
|
||||
'returnUrl' => $this->getReturnUrl($request, 'app_administrative_assignment_index'),
|
||||
] + $this->assignmentsContext($mailingDto) + $this->attachmentsContext($mailingDto));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\AssignmentMailing;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class ConfirmController extends AbstractAssignmentMailingController
|
||||
{
|
||||
#[Route('/administrative/assignment/mailing/confirm', name: 'app_administrative_assignment_mailing_confirm', methods: ['POST'])]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$form = $this->createMailingForm($request);
|
||||
$mailingDto = $form->getData();
|
||||
|
||||
$this->draftHandler->saveDraft($mailingDto);
|
||||
|
||||
// Only the wording is carried on in hidden fields. Assignments, template and the dropped
|
||||
// files are the draft's and the upload session's, which is where the send reads them.
|
||||
return $this->render('administrative/assignment_mailing/modal_confirm.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'mailingDto' => $mailingDto,
|
||||
'valid' => $form->isSubmitted() && $form->isValid(),
|
||||
'attachmentError' => $this->mailingService->validateAttachments($mailingDto),
|
||||
'attachmentSize' => $this->mailingService->getAttachmentSize($mailingDto),
|
||||
'recipients' => $this->mailingService->resolveRecipients($mailingDto),
|
||||
] + $this->attachmentsContext($mailingDto));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\AssignmentMailing;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class DiscardController extends AbstractAssignmentMailingController
|
||||
{
|
||||
#[Route('/administrative/assignment/mailing/discard', name: 'app_administrative_assignment_mailing_discard')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(): Response
|
||||
{
|
||||
$this->draftHandler->resetDraft();
|
||||
$this->attachmentHandler->discardPending(Upload::TYPE_MAILING_ATTACHMENT);
|
||||
|
||||
return $this->redirectToRoute('app_administrative_assignment_index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\AssignmentMailing;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
/**
|
||||
* Parks the wording typed so far and answers with its preview, in one request for the same
|
||||
* reason as the teamer mailing's draft route.
|
||||
*/
|
||||
class DraftController extends AbstractAssignmentMailingController
|
||||
{
|
||||
#[Route('/administrative/assignment/mailing/draft', name: 'app_administrative_assignment_mailing_draft', methods: ['POST'])]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$mailingDto = $this->createMailingForm($request)->getData();
|
||||
|
||||
$this->draftHandler->saveDraft($mailingDto);
|
||||
|
||||
return $this->render('admin/teamer/_mailing_preview.html.twig', $this->renderPreview($mailingDto));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\AssignmentMailing;
|
||||
|
||||
use App\Entity\Assignment;
|
||||
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class RemoveAssignmentController extends AbstractAssignmentMailingController
|
||||
{
|
||||
#[Route('/administrative/assignment/mailing/remove/{uuid}', name: 'app_administrative_assignment_mailing_remove', methods: ['POST'])]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(
|
||||
#[MapEntity(mapping: ['uuid' => 'uuid'])]
|
||||
Assignment $assignment,
|
||||
): Response {
|
||||
$mailingDto = $this->draftHandler->getDraft();
|
||||
$mailingDto->setAssignments(array_filter(
|
||||
$mailingDto->getAssignments(),
|
||||
fn (Assignment $selected) => $selected !== $assignment
|
||||
));
|
||||
|
||||
$this->draftHandler->saveDraft($mailingDto);
|
||||
|
||||
return $this->render('administrative/assignment_mailing/_assignments.html.twig', $this->assignmentsContext($mailingDto));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\AssignmentMailing;
|
||||
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class SendController extends AbstractAssignmentMailingController
|
||||
{
|
||||
#[Route('/administrative/assignment/mailing/send', name: 'app_administrative_assignment_mailing_send', methods: ['POST'])]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$form = $this->createMailingForm($request);
|
||||
$mailingDto = $form->getData();
|
||||
|
||||
if (false === $form->isSubmitted() || false === $form->isValid()) {
|
||||
return $this->backToCompose('Die Mail konnte nicht gesendet werden, Betreff oder Nachricht fehlen');
|
||||
}
|
||||
|
||||
if (null !== $error = $this->mailingService->validateAttachments($mailingDto)) {
|
||||
return $this->backToCompose($error);
|
||||
}
|
||||
|
||||
$recipients = $this->mailingService->resolveRecipients($mailingDto);
|
||||
|
||||
if (0 === $recipients->getEligibleCount()) {
|
||||
return $this->backToCompose('Die Mail konnte nicht gesendet werden, sie hat keine Empfänger:innen');
|
||||
}
|
||||
|
||||
$this->mailingService->send($mailingDto, $recipients, $this->getAuthenticatedUser());
|
||||
|
||||
// it is on its way, the next mailing starts on a blank page
|
||||
$this->draftHandler->resetDraft();
|
||||
|
||||
// not "wurde gesendet", see the teamer mailing: nothing has reached a mail server yet
|
||||
$this->addFlash('success', sprintf(
|
||||
'Die Mail wird an %d Teamer:innen gesendet',
|
||||
$recipients->getEligibleCount()
|
||||
));
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_administrative_assignment_index'));
|
||||
}
|
||||
|
||||
private function backToCompose(string $error): Response
|
||||
{
|
||||
$this->addFlash('error', $error);
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_administrative_assignment_mailing_compose'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\AssignmentMailing;
|
||||
|
||||
use App\Form\AssignmentMailingType;
|
||||
use App\Repository\MailingTemplateRepository;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
/**
|
||||
* Picks the template the mailing starts from: its subject and message replace what is in the
|
||||
* form, and its files join the mailing. Picking none keeps the wording and drops the files.
|
||||
*
|
||||
* Answers with the subject and message fields, the attachments and the preview, the last two
|
||||
* swapped out of band.
|
||||
*/
|
||||
class TemplateController extends AbstractAssignmentMailingController
|
||||
{
|
||||
public function __construct(private readonly MailingTemplateRepository $mailingTemplateRepository)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/administrative/assignment/mailing/template', name: 'app_administrative_assignment_mailing_template', methods: ['POST'])]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$mailingDto = $this->createMailingForm($request)->getData();
|
||||
|
||||
$template = $this->mailingTemplateRepository->findActiveByUuid((string) $request->request->get('template'));
|
||||
$mailingDto->setTemplate($template);
|
||||
|
||||
if (null !== $template) {
|
||||
$mailingDto
|
||||
->setSubject($template->getSubject())
|
||||
->setMessage($template->getMessage())
|
||||
;
|
||||
}
|
||||
|
||||
$this->draftHandler->saveDraft($mailingDto);
|
||||
|
||||
// a fresh form, so the fields show the template's wording rather than what was posted
|
||||
return $this->render('administrative/assignment_mailing/template.html.twig', [
|
||||
'form' => $this->createForm(AssignmentMailingType::class, $mailingDto)->createView(),
|
||||
'preview' => $this->renderPreview($mailingDto),
|
||||
] + $this->attachmentsContext($mailingDto));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\System\MailingTemplate;
|
||||
|
||||
use App\Controller\Traits\AuthenticatedUserTrait;
|
||||
use App\Entity\MailingTemplate;
|
||||
use App\Entity\Upload;
|
||||
use App\Form\MailingTemplateType;
|
||||
use App\Service\Teamer\MailingAttachmentHandler;
|
||||
use App\Service\Teamer\TeamerMailingDraftHandler;
|
||||
use App\Service\Teamer\TeamerMailingService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class CreateController extends AbstractController
|
||||
{
|
||||
use AuthenticatedUserTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly MailingAttachmentHandler $attachmentHandler,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/system/mailing-template/create', name: 'app_administrative_system_mailing_template_create')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$template = (new MailingTemplate())->setMessage(TeamerMailingDraftHandler::NEW_MESSAGE);
|
||||
|
||||
$form = $this->createForm(MailingTemplateType::class, $template);
|
||||
$form->handleRequest($request);
|
||||
|
||||
// files left over from a template form that was never saved must not end up on this one
|
||||
if (false === $form->isSubmitted()) {
|
||||
$this->attachmentHandler->discardPending(Upload::TYPE_MAILING_TEMPLATE);
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
if (null !== $error = $this->attachmentHandler->validateTemplateAttachments($template, [])) {
|
||||
$form->addError(new FormError($error));
|
||||
}
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->attachmentHandler->saveTemplateAttachments($template, [], $this->getAuthenticatedUser());
|
||||
$this->entityManager->persist($template);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Die Mailvorlage wurde angelegt');
|
||||
$this->logger->info('Create mailing template', [
|
||||
'mailing_template_id' => $template->getId(),
|
||||
'mailing_template_name' => $template->getName(),
|
||||
'attachments' => $template->getAttachments()->count(),
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_administrative_system_mailing_template_index');
|
||||
}
|
||||
|
||||
return $this->render('administrative/system/mailing_template/create.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'template' => $template,
|
||||
'pending' => $this->attachmentHandler->getPending(Upload::TYPE_MAILING_TEMPLATE),
|
||||
'placeholders' => TeamerMailingService::PLACEHOLDERS,
|
||||
'maxAttachmentBytes' => MailingAttachmentHandler::MAX_TOTAL_BYTES,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\System\MailingTemplate;
|
||||
|
||||
use App\Entity\MailingTemplate;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
/**
|
||||
* Soft, so the mailings sent from the template keep pointing at it - and at its files, which are
|
||||
* left where they are.
|
||||
*/
|
||||
class DeleteController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/system/mailing-template/delete/{uuid}', name: 'app_administrative_system_mailing_template_delete')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(
|
||||
#[MapEntity(mapping: ['uuid' => 'uuid'])]
|
||||
MailingTemplate $template,
|
||||
Request $request,
|
||||
): Response {
|
||||
if (true === $request->isMethod('POST')) {
|
||||
$template->setDeleted();
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Die Mailvorlage wurde gelöscht');
|
||||
$this->logger->info('Delete mailing template', [
|
||||
'mailing_template_id' => $template->getId(),
|
||||
'mailing_template_name' => $template->getName(),
|
||||
]);
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_administrative_system_mailing_template_index'));
|
||||
}
|
||||
|
||||
return $this->render('administrative/system/mailing_template/modal_delete.html.twig', [
|
||||
'template' => $template,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\System\MailingTemplate;
|
||||
|
||||
use App\Controller\Traits\AuthenticatedUserTrait;
|
||||
use App\Entity\MailingTemplate;
|
||||
use App\Entity\Upload;
|
||||
use App\Form\MailingTemplateType;
|
||||
use App\Service\Teamer\MailingAttachmentHandler;
|
||||
use App\Service\Teamer\TeamerMailingService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class EditController extends AbstractController
|
||||
{
|
||||
use AuthenticatedUserTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly MailingAttachmentHandler $attachmentHandler,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/system/mailing-template/edit/{uuid}', name: 'app_administrative_system_mailing_template_edit')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(
|
||||
#[MapEntity(mapping: ['uuid' => 'uuid'])]
|
||||
MailingTemplate $template,
|
||||
Request $request,
|
||||
): Response {
|
||||
if (true === $template->isDeleted()) {
|
||||
throw $this->createNotFoundException('Die Mailvorlage wurde gelöscht');
|
||||
}
|
||||
|
||||
$form = $this->createForm(MailingTemplateType::class, $template);
|
||||
$form->handleRequest($request);
|
||||
|
||||
// files left over from a template form that was never saved must not end up on this one
|
||||
if (false === $form->isSubmitted()) {
|
||||
$this->attachmentHandler->discardPending(Upload::TYPE_MAILING_TEMPLATE);
|
||||
}
|
||||
|
||||
/** @var Upload[] $remove */
|
||||
$remove = $form->has('removeAttachments')
|
||||
? iterator_to_array($form->get('removeAttachments')->getData() ?? [], false)
|
||||
: [];
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
if (null !== $error = $this->attachmentHandler->validateTemplateAttachments($template, $remove)) {
|
||||
$form->addError(new FormError($error));
|
||||
}
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->attachmentHandler->saveTemplateAttachments($template, $remove, $this->getAuthenticatedUser());
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Die Mailvorlage wurde aktualisiert');
|
||||
$this->logger->info('Edit mailing template', [
|
||||
'mailing_template_id' => $template->getId(),
|
||||
'mailing_template_name' => $template->getName(),
|
||||
'attachments' => $template->getAttachments()->count(),
|
||||
'attachments_removed' => count($remove),
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_administrative_system_mailing_template_index');
|
||||
}
|
||||
|
||||
return $this->render('administrative/system/mailing_template/edit.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'template' => $template,
|
||||
'pending' => $this->attachmentHandler->getPending(Upload::TYPE_MAILING_TEMPLATE),
|
||||
'placeholders' => TeamerMailingService::PLACEHOLDERS,
|
||||
'maxAttachmentBytes' => MailingAttachmentHandler::MAX_TOTAL_BYTES,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\System\MailingTemplate;
|
||||
|
||||
use App\Repository\MailingTemplateRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly MailingTemplateRepository $mailingTemplateRepository)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/administrative/system/mailing-template', name: 'app_administrative_system_mailing_template_index')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('administrative/system/mailing_template/index.html.twig', [
|
||||
'templates' => $this->mailingTemplateRepository->findActive(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user