Skip to content

Commit

Permalink
Merge pull request #211 from crf-devs/fix-slot-state-change
Browse files Browse the repository at this point in the history
Fix slot state change
  • Loading branch information
mRoca authored Apr 3, 2020
2 parents 00357df + 61ead30 commit 63978fd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Domain/PlanningUpdateDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,16 @@ protected function process(string $entityClass, string $availabilityClass, array
/** @var AvailabilityInterface */
$currentEntity = end($search);

foreach ($schedules as $schedule) {
list($scheduleStart, $scheduleEnd) = $schedule;
$searchAvailabilities = array_filter($availabilities, function (AvailabilityInterface $availability) use ($entityId, $scheduleStart, $scheduleEnd) {
return $availability->getOwner()->getId() === (int) $entityId && $availability->getStartTime() === new \DateTimeImmutable($scheduleStart) && $availability->getEndTime() === new \DateTimeImmutable($scheduleEnd);
foreach ($schedules as [$scheduleStart, $scheduleEnd]) {
$scheduleStartDate = new \DateTimeImmutable($scheduleStart);
$scheduleEndDate = new \DateTimeImmutable($scheduleEnd);

$searchAvailabilities = array_filter($availabilities, function (AvailabilityInterface $availability) use ($entityId, $scheduleStartDate, $scheduleEndDate) {
// Caution: it's not possible to compare DateTimeImmutable with ====
return
$availability->getOwner()->getId() === (int) $entityId
&& 0 === $availability->getStartTime()->getTimestamp() - $scheduleStartDate->getTimestamp()
&& 0 === $availability->getEndTime()->getTimestamp() - $scheduleEndDate->getTimestamp();
});
$availability = end($searchAvailabilities);

Expand Down

0 comments on commit 63978fd

Please sign in to comment.