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