feat: mailing to filtered teamer list
addresses #869dv9bur
This commit is contained in:
1 parent
48cd2d6b67
commit
6511f821ac
18 files changed
+1223
-7
No files matched your search
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Teamer;
|
||||
|
||||
use App\Model\TeamerMailingDto;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
|
||||
/**
|
||||
* Keeps the composed mail in the session, the same way the teamer filter is kept.
|
||||
*
|
||||
* Adjusting the filter leaves the compose page and comes back to it, which would
|
||||
* otherwise throw away everything the admin has written so far.
|
||||
*/
|
||||
class TeamerMailingDraftHandler
|
||||
{
|
||||
/**
|
||||
* A blank textarea makes the placeholders easy to miss, so a new mailing already opens
|
||||
* with the greeting the vast majority of them starts with.
|
||||
*/
|
||||
public const NEW_MESSAGE = 'Hallo '.TeamerMailingService::PLACEHOLDER_FIRST_NAME.',';
|
||||
|
||||
private const NAMESPACE = 'mailing:teamer';
|
||||
|
||||
public function __construct(private readonly RequestStack $requestStack)
|
||||
{
|
||||
}
|
||||
|
||||
public function getDraft(): TeamerMailingDto
|
||||
{
|
||||
$mailingDto = new TeamerMailingDto();
|
||||
|
||||
if (null === $data = $this->getSession()->get(self::NAMESPACE)) {
|
||||
return $mailingDto->setMessage(self::NEW_MESSAGE);
|
||||
}
|
||||
|
||||
return $mailingDto
|
||||
->setSubject($data['subject'] ?? null)
|
||||
->setMessage($data['message'] ?? null)
|
||||
;
|
||||
}
|
||||
|
||||
public function hasDraft(): bool
|
||||
{
|
||||
return $this->getSession()->has(self::NAMESPACE);
|
||||
}
|
||||
|
||||
public function saveDraft(TeamerMailingDto $mailingDto): void
|
||||
{
|
||||
$this->getSession()->set(self::NAMESPACE, [
|
||||
'subject' => $mailingDto->getSubject(),
|
||||
'message' => $mailingDto->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function resetDraft(): void
|
||||
{
|
||||
$this->getSession()->remove(self::NAMESPACE);
|
||||
}
|
||||
|
||||
private function getSession(): SessionInterface
|
||||
{
|
||||
return $this->requestStack->getSession();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user