fix: correctly assign items to timeline

This commit is contained in:
Björn Fromme
2025-03-25 15:47:08 +01:00
parent ecc059cefc
commit da18856cc2
4 changed files with 63 additions and 50 deletions
@@ -36,7 +36,7 @@ class TimelineFilterController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$this->filterHandler->handleRequest($form);
$returnUrl = $this->getReturnUrl($request, 'app_administrative_assignment_timeline');
$returnUrl = $this->getReturnUrl($request, 'app_administrative_timeline');
return new HxRedirectResponse($returnUrl);
}
@@ -51,7 +51,7 @@ class TimelineFilterController extends AbstractController
public function reset(Request $request): Response
{
$this->filterHandler->resetFilterSettings();
$returnUrl = $this->getReturnUrl($request, 'app_administrative_assignment_timeline');
$returnUrl = $this->getReturnUrl($request, 'app_administrative_timeline');
return $this->redirect($returnUrl);
}
+14
View File
@@ -10,6 +10,7 @@ class TimelineItem
public const TYPE_ASSIGNMENT = 'assignment';
public const TYPE_DISPOSITION = 'disposition';
private ?int $dispositionId = null;
private ?\DateTimeImmutable $dateFrom = null;
private ?\DateTimeImmutable $dateTo = null;
private ?string $status = null;
@@ -44,6 +45,7 @@ class TimelineItem
$dateTo = $assignment->getDestination()->getDateTo();
return (new static($assignment->getId(), static::TYPE_DISPOSITION))
->setDispositionId($disposition->getId())
->setDateFrom($dateFrom)
->setDateTo($dateTo)
->setJobProfile($assignment->getJobProfile()->getName())
@@ -64,6 +66,18 @@ class TimelineItem
return $this->type;
}
public function getDispositionId(): ?int
{
return $this->dispositionId;
}
public function setDispositionId(?int $dispositionId): static
{
$this->dispositionId = $dispositionId;
return $this;
}
public function getDateFrom(): ?\DateTimeImmutable
{
return $this->dateFrom;
+9 -18
View File
@@ -41,33 +41,24 @@ class TimelineService
private function addItem(array &$rows, TimelineItem $item): void
{
$itemAdded = false;
$rowIndex = 0;
foreach ($rows as $index => $row) {
$addToRow = true;
$fitsRow = true;
foreach ($row as $entry) {
/** @var TimelineItem $entry */
if (
$item->getDateFrom() >= $entry->getDateFrom() && $item->getDateFrom() <= $entry->getDateTo()
|| $item->getDateTo() >= $entry->getDateFrom() && $item->getDateTo() <= $entry->getDateTo()
) {
$addToRow = false;
if ($entry->getDateTo() >= $item->getDateFrom() && $entry->getDateFrom() <= $item->getDateTo()) {
$fitsRow = false;
}
}
if (true === $addToRow) {
$rows[$index][$item->getKey()] = $item;
$itemAdded = true;
break;
}
$rowIndex = $index;
}
if (false === $itemAdded) {
$rows[] = [
$item->getKey() => $item,
];
if (false === $fitsRow) {
++$rowIndex;
}
$rows[$rowIndex][$item->getKey()] = $item;
}
public function getActiveWindow(): CarbonPeriod