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
@@ -62,6 +62,98 @@ class AssignmentRepository extends ServiceEntityRepository
|
||||
return $qb->getQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* The assignments a mailing can go to, of those given: not deleted, and with at least one
|
||||
* confirmed teamer - an assignment without one would only make the recipient count look
|
||||
* wrong. In the order of the overview, by travel date.
|
||||
*
|
||||
* @param string[] $uuids
|
||||
*
|
||||
* @return Assignment[]
|
||||
*/
|
||||
public function findForMailing(array $uuids): array
|
||||
{
|
||||
if ([] === $uuids) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$qb = $this->createQueryBuilder('assignment');
|
||||
|
||||
return $qb
|
||||
->select('assignment', 'destination', 'job_profile')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
->leftJoin('assignment.jobProfile', 'job_profile')
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->in('assignment.uuid', ':uuids'),
|
||||
$qb->expr()->isNull('assignment.deletedAt'),
|
||||
$this->hasConfirmedDisposition()
|
||||
))
|
||||
->setParameter('uuids', $uuids)
|
||||
->setParameter('confirmed', Disposition::STATUS_CONFIRMED)
|
||||
->orderBy('destination.dateFrom', \SortDirection::Ascending)
|
||||
->addOrderBy('assignment.id', \SortDirection::Ascending)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignments to add to a mailing: not deleted, not over yet and with a confirmed teamer, the
|
||||
* same as findForMailing(). Searched like the destination autocomplete, plus the job profile.
|
||||
*
|
||||
* @return array<int, array{value: string, text: string}>
|
||||
*/
|
||||
public function getMailingAutocompletionData(string $search): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('assignment');
|
||||
|
||||
$assignments = $qb
|
||||
->select('assignment', 'destination', 'job_profile')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
->innerJoin('assignment.jobProfile', 'job_profile')
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->isNull('assignment.deletedAt'),
|
||||
$qb->expr()->gte('destination.dateTo', ':today'),
|
||||
$this->hasConfirmedDisposition(),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->like('destination.product', ':search'),
|
||||
$qb->expr()->like('destination.hotel', ':search'),
|
||||
$qb->expr()->like('job_profile.name', ':search'),
|
||||
$qb->expr()->like('DATE_FORMAT(destination.dateFrom, \'%d.%m.%y\')', ':search')
|
||||
)
|
||||
))
|
||||
->setParameter('today', new \DateTimeImmutable('today'))
|
||||
->setParameter('search', '%'.$this->escapeLikeWildcards($search).'%')
|
||||
->setParameter('confirmed', Disposition::STATUS_CONFIRMED)
|
||||
->orderBy('destination.dateFrom', \SortDirection::Ascending)
|
||||
->addOrderBy('assignment.id', \SortDirection::Ascending)
|
||||
->setMaxResults(30)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
||||
return array_map(fn (Assignment $assignment) => [
|
||||
'value' => $assignment->getUuid(),
|
||||
'text' => sprintf(
|
||||
'%s · %s · %s',
|
||||
$assignment->getDestination(),
|
||||
$assignment->getDestination()?->getHotel(),
|
||||
$assignment->getJobProfile()?->getName()
|
||||
),
|
||||
], $assignments);
|
||||
}
|
||||
|
||||
/**
|
||||
* DQL for "assignment has a confirmed disposition"; the caller binds :confirmed.
|
||||
*/
|
||||
private function hasConfirmedDisposition(): string
|
||||
{
|
||||
return sprintf(
|
||||
'EXISTS (SELECT confirmed_disposition.id FROM %s confirmed_disposition WHERE confirmed_disposition.assignment = assignment AND confirmed_disposition.status = :confirmed)',
|
||||
Disposition::class
|
||||
);
|
||||
}
|
||||
|
||||
public function getListQueryForTeamer(Teamer $teamer, AssignmentFilterDto $filterDto): Query
|
||||
{
|
||||
// Find ids of assignments with available slots first
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Mailing;
|
||||
use App\Entity\Upload;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Mailing>
|
||||
*
|
||||
* @method Mailing|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Mailing|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Mailing[] findAll()
|
||||
* @method Mailing[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class MailingRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Mailing::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a sent mailing still points at this file, in which case removing it from its
|
||||
* template must leave the file and its row alone.
|
||||
*/
|
||||
public function hasAttachment(Upload $upload): bool
|
||||
{
|
||||
$qb = $this->createQueryBuilder('mailing');
|
||||
|
||||
return 0 < (int) $qb
|
||||
->select('COUNT(mailing.id)')
|
||||
->innerJoin('mailing.attachments', 'attachment')
|
||||
->where($qb->expr()->eq('attachment', ':upload'))
|
||||
->setParameter('upload', $upload)
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\MailingTemplate;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<MailingTemplate>
|
||||
*
|
||||
* @method MailingTemplate|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method MailingTemplate|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method MailingTemplate[] findAll()
|
||||
* @method MailingTemplate[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class MailingTemplateRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, MailingTemplate::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MailingTemplate[]
|
||||
*/
|
||||
public function findActive(): array
|
||||
{
|
||||
return $this->findBy(['deletedAt' => null], ['name' => 'ASC']);
|
||||
}
|
||||
|
||||
public function findActiveByUuid(string $uuid): ?MailingTemplate
|
||||
{
|
||||
return $this->findOneBy(['uuid' => $uuid, 'deletedAt' => null]);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\License;
|
||||
use App\Entity\Teamer;
|
||||
use App\Model\TeamerFilterDto;
|
||||
@@ -75,6 +77,57 @@ class TeamerRepository extends ServiceEntityRepository
|
||||
return array_map(TeamerMailingRecipient::fromRow(...), $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* The teamers with a confirmed disposition on any of the given assignments, each once
|
||||
* however many of them they are on. Same projection as getMailingRecipients().
|
||||
*
|
||||
* @param Assignment[] $assignments
|
||||
*
|
||||
* @return TeamerMailingRecipient[]
|
||||
*/
|
||||
public function getAssignmentMailingRecipients(array $assignments): array
|
||||
{
|
||||
if ([] === $assignments) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_map(
|
||||
TeamerMailingRecipient::fromRow(...),
|
||||
$this->createAssignmentMailingQueryBuilder($assignments)->getQuery()->getArrayResult()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Assignment[] $assignments
|
||||
*/
|
||||
public function createAssignmentMailingQueryBuilder(array $assignments): QueryBuilder
|
||||
{
|
||||
$qb = $this->createQueryBuilder('teamer');
|
||||
|
||||
return $qb
|
||||
->distinct()
|
||||
->select(
|
||||
'teamer.id AS id',
|
||||
'teamer.firstName AS firstName',
|
||||
'teamer.lastName AS lastName',
|
||||
'teamer.communication.email AS email',
|
||||
'teamer.deletedAt AS deletedAt',
|
||||
'user.disabledAt AS disabledAt'
|
||||
)
|
||||
->innerJoin('teamer.dispositions', 'disposition')
|
||||
->leftJoin('teamer.user', 'user')
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->in('disposition.assignment', ':assignments'),
|
||||
$qb->expr()->eq('disposition.status', ':status')
|
||||
))
|
||||
->setParameter('assignments', $assignments)
|
||||
->setParameter('status', Disposition::STATUS_CONFIRMED)
|
||||
// the compose page lists the names in this order
|
||||
->addOrderBy('teamer.lastName', \SortDirection::Ascending)
|
||||
->addOrderBy('teamer.firstName', \SortDirection::Ascending)
|
||||
;
|
||||
}
|
||||
|
||||
private function createListQueryBuilder(TeamerFilterDto $filterDto): QueryBuilder
|
||||
{
|
||||
$qb = $this->createQueryBuilder('teamer');
|
||||
|
||||
Reference in new issue
Block a user