feat: all-season assignments
This commit is contained in:
1 parent
675cec1b69
commit
cf876ed224
119 files changed
+6194
-294
No files matched your search
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\SeasonAssignment;
|
||||
use App\Entity\Teamer;
|
||||
use App\Model\SeasonAssignmentFilterDto;
|
||||
use App\Repository\Traits\QueryHelperTrait;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<SeasonAssignment>
|
||||
*
|
||||
* @method SeasonAssignment|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method SeasonAssignment|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method SeasonAssignment[] findAll()
|
||||
* @method SeasonAssignment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class SeasonAssignmentRepository extends ServiceEntityRepository
|
||||
{
|
||||
use QueryHelperTrait;
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, SeasonAssignment::class);
|
||||
}
|
||||
|
||||
public function getListQuery(SeasonAssignmentFilterDto $filterDto): Query
|
||||
{
|
||||
$qb = $this->createQueryBuilder('season_assignment');
|
||||
|
||||
$qb
|
||||
->select('season_assignment', 'teamer', 'job_profile')
|
||||
// an assignment waiting for a teamer has to stay in the list - that is exactly
|
||||
// the state an administrative user is looking for when placing people
|
||||
->leftJoin('season_assignment.teamer', 'teamer')
|
||||
->innerJoin('season_assignment.jobProfile', 'job_profile')
|
||||
;
|
||||
|
||||
$this->applyFilterSettings($filterDto, $qb);
|
||||
|
||||
return $qb
|
||||
->addOrderBy('season_assignment.dateFrom', \SortDirection::Descending)
|
||||
->addOrderBy('teamer.lastName', \SortDirection::Ascending)
|
||||
->getQuery()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* The assignments a teamer already has in one season, for the rule that allows only one.
|
||||
*
|
||||
* Bucketed by the assignment's own first day, which is exactly how
|
||||
* App\Config\SeasonCalendar::seasonYearFor() decides what season something belongs to.
|
||||
* Deliberately not SeasonPeriodFilter: that one also requires the period to end inside the
|
||||
* window, and a placement running past the season's last day still belongs to it here.
|
||||
*/
|
||||
public function countInSeasonWindow(
|
||||
Teamer $teamer,
|
||||
\DateTimeImmutable $windowStart,
|
||||
\DateTimeImmutable $windowEnd,
|
||||
?int $excludeId = null,
|
||||
): int {
|
||||
return (int) $this
|
||||
->createInSeasonWindowQueryBuilder($teamer, $windowStart, $windowEnd, $excludeId)
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* A teamer's assignments in one season, earliest first - what the teamer's own season page
|
||||
* is about. Bucketed by the assignment's own first day, like countInSeasonWindow().
|
||||
*
|
||||
* @return SeasonAssignment[]
|
||||
*/
|
||||
public function findForTeamerInSeason(
|
||||
Teamer $teamer,
|
||||
\DateTimeImmutable $windowStart,
|
||||
\DateTimeImmutable $windowEnd,
|
||||
): array {
|
||||
$qb = $this->createInSeasonWindowQueryBuilder($teamer, $windowStart, $windowEnd);
|
||||
|
||||
return $qb
|
||||
->select('season_assignment')
|
||||
->addOrderBy('season_assignment.dateFrom', \SortDirection::Ascending)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracted so the conditions can be pinned by a test compiling the DQL - the suite has no
|
||||
* fixtures, so what is asserted is what the query says, not what it returns.
|
||||
*
|
||||
* The window is read off the assignment itself, so there is no second row that could be
|
||||
* soft-deleted underneath a live placement and drop it out of the season it belongs to.
|
||||
*/
|
||||
public function createInSeasonWindowQueryBuilder(
|
||||
Teamer $teamer,
|
||||
\DateTimeImmutable $windowStart,
|
||||
\DateTimeImmutable $windowEnd,
|
||||
?int $excludeId = null,
|
||||
): QueryBuilder {
|
||||
$qb = $this->createQueryBuilder('season_assignment');
|
||||
|
||||
$qb
|
||||
->select($qb->expr()->count('season_assignment'))
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->eq('season_assignment.teamer', ':teamer'),
|
||||
$qb->expr()->isNull('season_assignment.deletedAt'),
|
||||
$qb->expr()->gte('season_assignment.dateFrom', ':windowStart'),
|
||||
$qb->expr()->lte('season_assignment.dateFrom', ':windowEnd')
|
||||
))
|
||||
->setParameter('teamer', $teamer)
|
||||
->setParameter('windowStart', $windowStart)
|
||||
->setParameter('windowEnd', $windowEnd)
|
||||
;
|
||||
|
||||
if (null !== $excludeId) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->neq('season_assignment.id', ':excludeId'))
|
||||
->setParameter('excludeId', $excludeId)
|
||||
;
|
||||
}
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
private function applyFilterSettings(SeasonAssignmentFilterDto $filterDto, QueryBuilder $qb): void
|
||||
{
|
||||
if (null !== $filterDto->getTeamerName()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->orX(
|
||||
$qb->expr()->like('teamer.firstName', ':teamerName'),
|
||||
$qb->expr()->like('teamer.lastName', ':teamerName')
|
||||
))
|
||||
->setParameter('teamerName', '%'.$this->escapeLikeWildcards($filterDto->getTeamerName()).'%')
|
||||
;
|
||||
}
|
||||
|
||||
if (0 < count($filterDto->getHotelCodes())) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->in('season_assignment.hotelCode', ':hotelCodes'))
|
||||
->setParameter('hotelCodes', $filterDto->getHotelCodes())
|
||||
;
|
||||
}
|
||||
|
||||
if (0 < count($filterDto->getJobProfiles())) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->in('season_assignment.jobProfile', ':jobProfiles'))
|
||||
->setParameter('jobProfiles', $filterDto->getJobProfiles())
|
||||
;
|
||||
}
|
||||
|
||||
if (false === $filterDto->isIncludeDeleted()) {
|
||||
$qb->andWhere($qb->expr()->isNull('season_assignment.deletedAt'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\SeasonAssignmentTask;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<SeasonAssignmentTask>
|
||||
*
|
||||
* @method SeasonAssignmentTask|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method SeasonAssignmentTask|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method SeasonAssignmentTask[] findAll()
|
||||
* @method SeasonAssignmentTask[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class SeasonAssignmentTaskRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, SeasonAssignmentTask::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Every open entry that could still be reminded about: not ticked off, on a live assignment
|
||||
* that has a teamer on it.
|
||||
*
|
||||
* The deadlines themselves are not part of this query. They are computed from the
|
||||
* assignment's first day by a relative offset, and month arithmetic is not invertible
|
||||
* day by day - "minus one month" from the 31st and back again lands somewhere else - so a
|
||||
* query built by inverting the offset would silently skip entries. The reminder resolves
|
||||
* every row through SeasonTaskDeadlineResolver instead; the set is small, one assignment per
|
||||
* all-season teamer per season.
|
||||
*
|
||||
* @return SeasonAssignmentTask[]
|
||||
*/
|
||||
public function findOpen(?\DateTimeImmutable $windowStart = null, ?\DateTimeImmutable $windowEnd = null): array
|
||||
{
|
||||
return $this
|
||||
->createOpenQueryBuilder($windowStart, $windowEnd)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracted so the conditions can be pinned by a test compiling the DQL - the suite has no
|
||||
* fixtures, so what is asserted is what the query says, not what it returns.
|
||||
*/
|
||||
public function createOpenQueryBuilder(
|
||||
?\DateTimeImmutable $windowStart = null,
|
||||
?\DateTimeImmutable $windowEnd = null,
|
||||
): QueryBuilder {
|
||||
$qb = $this->createQueryBuilder('task');
|
||||
|
||||
$qb
|
||||
->select('task', 'season_assignment', 'teamer')
|
||||
->innerJoin('task.seasonAssignment', 'season_assignment')
|
||||
// no teamer means nobody to remind and nobody to be late
|
||||
->innerJoin('season_assignment.teamer', 'teamer')
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->eq('task.done', ':done'),
|
||||
$qb->expr()->isNull('season_assignment.deletedAt'),
|
||||
$qb->expr()->isNull('teamer.deletedAt')
|
||||
))
|
||||
->setParameter('done', false)
|
||||
->addOrderBy('teamer.lastName', \SortDirection::Ascending)
|
||||
->addOrderBy('teamer.firstName', \SortDirection::Ascending)
|
||||
;
|
||||
|
||||
if (null !== $windowStart) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->gte('season_assignment.dateFrom', ':windowStart'))
|
||||
->setParameter('windowStart', $windowStart)
|
||||
;
|
||||
}
|
||||
|
||||
if (null !== $windowEnd) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->lte('season_assignment.dateFrom', ':windowEnd'))
|
||||
->setParameter('windowEnd', $windowEnd)
|
||||
;
|
||||
}
|
||||
|
||||
return $qb;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Config\SeasonTask;
|
||||
use App\Entity\SeasonTaskDocument;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<SeasonTaskDocument>
|
||||
*
|
||||
* @method SeasonTaskDocument|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method SeasonTaskDocument|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method SeasonTaskDocument[] findAll()
|
||||
* @method SeasonTaskDocument[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class SeasonTaskDocumentRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, SeasonTaskDocument::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The mapping keyed by task, for views that render the whole checklist at once and would
|
||||
* otherwise query per row.
|
||||
*
|
||||
* @return array<string, SeasonTaskDocument>
|
||||
*/
|
||||
public function findIndexedByTaskKey(): array
|
||||
{
|
||||
$indexed = [];
|
||||
|
||||
foreach ($this->findAll() as $seasonTaskDocument) {
|
||||
$indexed[$seasonTaskDocument->getTaskKey()] = $seasonTaskDocument;
|
||||
}
|
||||
|
||||
return $indexed;
|
||||
}
|
||||
|
||||
public function findForTask(SeasonTask $task): ?SeasonTaskDocument
|
||||
{
|
||||
return $this->findOneBy(['taskKey' => $task->value]);
|
||||
}
|
||||
}
|
||||
@@ -150,6 +150,13 @@ class TeamerRepository extends ServiceEntityRepository
|
||||
;
|
||||
}
|
||||
|
||||
if (true === $filterDto->isAllSeason()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->eq('teamer.allSeason', ':allSeason'))
|
||||
->setParameter('allSeason', true)
|
||||
;
|
||||
}
|
||||
|
||||
if (false === $filterDto->isIncludeDeleted()) {
|
||||
$qb->andWhere($qb->expr()->isNull('teamer.deletedAt'));
|
||||
}
|
||||
@@ -167,11 +174,15 @@ class TeamerRepository extends ServiceEntityRepository
|
||||
return $qb;
|
||||
}
|
||||
|
||||
public function getAutocompletionData(string $search): array
|
||||
/**
|
||||
* @param bool $allSeasonOnly restricts the suggestions to all-season teamers, so a season
|
||||
* assignment cannot be created for someone who works short term
|
||||
*/
|
||||
private function createAutocompletionQueryBuilder(string $search, bool $allSeasonOnly): QueryBuilder
|
||||
{
|
||||
$qb = $this->createQueryBuilder('teamer');
|
||||
|
||||
$teamers = $qb
|
||||
$qb
|
||||
->where($qb->expr()->orX(
|
||||
$qb->expr()->like('teamer.lastName', ':search'),
|
||||
$qb->expr()->like('teamer.firstName', ':search'),
|
||||
@@ -180,6 +191,22 @@ class TeamerRepository extends ServiceEntityRepository
|
||||
->orderBy('teamer.lastName', \SortDirection::Ascending)
|
||||
->addOrderBy('teamer.firstName', \SortDirection::Ascending)
|
||||
->setParameter('search', '%'.$this->escapeLikeWildcards($search).'%')
|
||||
;
|
||||
|
||||
if (true === $allSeasonOnly) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->eq('teamer.allSeason', ':allSeason'))
|
||||
->setParameter('allSeason', true)
|
||||
;
|
||||
}
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
public function getAutocompletionData(string $search, bool $allSeasonOnly = false): array
|
||||
{
|
||||
$teamers = $this
|
||||
->createAutocompletionQueryBuilder($search, $allSeasonOnly)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Model\DocumentFilterDto;
|
||||
use App\Repository\Traits\QueryHelperTrait;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
@@ -46,17 +47,17 @@ class UploadRepository extends ServiceEntityRepository
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* The picker behind every "choose a document" field, restricted to the global library.
|
||||
*
|
||||
* Without the type condition it offers every upload in the system - Honorarverträge,
|
||||
* Honorarnoten, Belege, Führerscheine - so picking one would have pointed a setting at a
|
||||
* teamer's private file.
|
||||
*/
|
||||
public function getAutocompletionData(string $search): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('upload');
|
||||
|
||||
$documents = $qb
|
||||
->where($qb->expr()->orX(
|
||||
$qb->expr()->like('upload.originalFilename', ':filename'),
|
||||
$qb->expr()->like('upload.displayName', ':filename')
|
||||
))
|
||||
->setParameter('filename', '%'.$this->escapeLikeWildcards($search).'%')
|
||||
->orderBy('upload.originalFilename', \SortDirection::Ascending)
|
||||
$documents = $this
|
||||
->createAutocompletionQueryBuilder($search)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
@@ -79,6 +80,24 @@ class UploadRepository extends ServiceEntityRepository
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function createAutocompletionQueryBuilder(string $search): QueryBuilder
|
||||
{
|
||||
$qb = $this->createQueryBuilder('upload');
|
||||
|
||||
return $qb
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->eq('upload.type', ':type'),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->like('upload.originalFilename', ':filename'),
|
||||
$qb->expr()->like('upload.displayName', ':filename')
|
||||
)
|
||||
))
|
||||
->setParameter('type', Upload::TYPE_DOCUMENT)
|
||||
->setParameter('filename', '%'.$this->escapeLikeWildcards($search).'%')
|
||||
->orderBy('upload.originalFilename', \SortDirection::Ascending)
|
||||
;
|
||||
}
|
||||
|
||||
public function getBatchDownloadListQuery(
|
||||
string $type = Upload::TYPE_INVOICE,
|
||||
string $status = Upload::STATUS_PAID,
|
||||
|
||||
Reference in new issue
Block a user