diff --git a/zmsadmin/js/page/availabilityDay/index.js b/zmsadmin/js/page/availabilityDay/index.js index 50cc70adb..9b23a22f8 100644 --- a/zmsadmin/js/page/availabilityDay/index.js +++ b/zmsadmin/js/page/availabilityDay/index.js @@ -511,7 +511,6 @@ class AvailabilityPage extends Component { selectedAvailability: this.state.selectedAvailability })) }; - console.log("here"); const url = `${this.props.links.includeurl}/availability/conflicts/`; fetch(url, requestOptions) .then(res => res.json()) diff --git a/zmsadmin/src/Zmsadmin/AvailabilityConflicts.php b/zmsadmin/src/Zmsadmin/AvailabilityConflicts.php index 952d3be80..92edd5287 100644 --- a/zmsadmin/src/Zmsadmin/AvailabilityConflicts.php +++ b/zmsadmin/src/Zmsadmin/AvailabilityConflicts.php @@ -45,7 +45,7 @@ protected static function getAvailabilityData($input) $availabilityList->addEntity($futureAvailability); } - [$earliestStartDateTime, $latestEndDateTime] = self::getDateTimeRangeFromList($availabilityList, $selectedDateTime); + [$earliestStartDateTime, $latestEndDateTime] = $availabilityList->getDateTimeRangeFromList( $selectedDateTime); $availabilityList = $availabilityList->sortByCustomStringKey('endTime'); $conflictList = $availabilityList->getConflicts($earliestStartDateTime, $latestEndDateTime); @@ -94,45 +94,6 @@ protected static function getAvailabilityList($scope, $dateTime) } - /** - * Get the earliest startDateTime and latest endDateTime from an AvailabilityList - * If the start date of any availability is before the selected date, use the selected date instead. - * - * @param AvailabilityList $availabilityList - * @param \DateTimeImmutable $selectedDate - * @return array - */ - protected static function getDateTimeRangeFromList(AvailabilityList $availabilityList, \DateTimeImmutable $selectedDate): array - { - $earliestStartDateTime = null; - $latestEndDateTime = null; - - foreach ($availabilityList as $availability) { - // Convert Unix timestamp to date strings - $startDate = (new \DateTimeImmutable())->setTimestamp($availability->startDate)->format('Y-m-d'); - $endDate = (new \DateTimeImmutable())->setTimestamp($availability->endDate)->format('Y-m-d'); - - // Combine date and time for start and end - $startDateTime = new \DateTimeImmutable("{$startDate} {$availability->startTime}"); - $endDateTime = new \DateTimeImmutable("{$endDate} {$availability->endTime}"); - - // Adjust the startDateTime if it's before the selected date - if ($startDateTime < $selectedDate) { - $startDateTime = $selectedDate->setTime(0, 0); - } - // Determine the earliest start time - if (is_null($earliestStartDateTime) || $startDateTime < $earliestStartDateTime) { - $earliestStartDateTime = $startDateTime; - } - - // Determine the latest end time - if (is_null($latestEndDateTime) || $endDateTime > $latestEndDateTime) { - $latestEndDateTime = $endDateTime; - } - } - - return [$earliestStartDateTime, $latestEndDateTime]; - } } diff --git a/zmsapi/src/Zmsapi/AvailabilityAdd.php b/zmsapi/src/Zmsapi/AvailabilityAdd.php index 6aa600c4b..24a832b96 100644 --- a/zmsapi/src/Zmsapi/AvailabilityAdd.php +++ b/zmsapi/src/Zmsapi/AvailabilityAdd.php @@ -89,7 +89,7 @@ public function readResponse( throw new AvailabilityUpdateFailed(); } - [$earliestStartDateTime, $latestEndDateTime] = $this->getDateTimeRangeFromCollection($mergedCollection, \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $input['selectedDate'] . ' 00:00:00')); + [$earliestStartDateTime, $latestEndDateTime] = $mergedCollection->getDateTimeRangeFromList(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $input['selectedDate'] . ' 00:00:00')); $conflicts = $mergedCollection->getConflicts($earliestStartDateTime, $latestEndDateTime); if ($conflicts->count() > 0) { //error_log(json_encode($conflicts)); @@ -109,48 +109,6 @@ public function readResponse( $response = Render::withLastModified($response, time(), '0'); return Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); } - - - /** - * Get the earliest startDateTime and latest endDateTime from a Collection - * If the start date of any availability is before the selected date, - * use the selected date instead. - * - * @param Collection $collection - * @param \DateTimeImmutable $selectedDate - * @return array - */ - private function getDateTimeRangeFromCollection(Collection $collection, \DateTimeImmutable $selectedDate): array - { - $earliestStartDateTime = null; - $latestEndDateTime = null; - - foreach ($collection as $availability) { - // Convert Unix timestamp to a date string before concatenating with the time - $startDate = (new \DateTimeImmutable())->setTimestamp($availability->startDate)->format('Y-m-d'); - $endDate = (new \DateTimeImmutable())->setTimestamp($availability->endDate)->format('Y-m-d'); - - // Combine date and time for start and end - $startDateTime = new \DateTimeImmutable("{$startDate} {$availability->startTime}"); - $endDateTime = new \DateTimeImmutable("{$endDate} {$availability->endTime}"); - - // If startDate is before the selectedDate, use the selectedDate as the start - if ($startDateTime < $selectedDate) { - $startDateTime = $selectedDate->setTime(0, 0); - } - - // Determine the earliest start and latest end times - if (is_null($earliestStartDateTime) || $startDateTime < $earliestStartDateTime) { - $earliestStartDateTime = $startDateTime; - } - if (is_null($latestEndDateTime) || $endDateTime > $latestEndDateTime) { - $latestEndDateTime = $endDateTime; - } - } - - return [$earliestStartDateTime, $latestEndDateTime]; - } - protected function writeEntityUpdate($entity, $resolveReferences): Entity { diff --git a/zmsapi/src/Zmsapi/AvailabilityUpdate.php b/zmsapi/src/Zmsapi/AvailabilityUpdate.php index c4d78cbcf..20842db21 100644 --- a/zmsapi/src/Zmsapi/AvailabilityUpdate.php +++ b/zmsapi/src/Zmsapi/AvailabilityUpdate.php @@ -96,7 +96,7 @@ public function readResponse( throw new AvailabilityUpdateFailed(); } - [$earliestStartDateTime, $latestEndDateTime] = $this->getDateTimeRangeFromCollection($mergedCollection, \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $input['selectedDate'] . ' 00:00:00')); + [$earliestStartDateTime, $latestEndDateTime] = $mergedCollection->getDateTimeRangeFromList(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $input['selectedDate'] . ' 00:00:00')); $conflicts = $mergedCollection->getConflicts($earliestStartDateTime, $latestEndDateTime); if ($conflicts->count() > 0) { //error_log(json_encode($conflicts)); @@ -117,46 +117,6 @@ public function readResponse( return Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); } - /** - * Get the earliest startDateTime and latest endDateTime from a Collection - * If the start date of any availability is before the selected date, - * use the selected date instead. - * - * @param Collection $collection - * @param \DateTimeImmutable $selectedDate - * @return array - */ - private function getDateTimeRangeFromCollection(Collection $collection, \DateTimeImmutable $selectedDate): array - { - $earliestStartDateTime = null; - $latestEndDateTime = null; - - foreach ($collection as $availability) { - // Convert Unix timestamp to a date string before concatenating with the time - $startDate = (new \DateTimeImmutable())->setTimestamp($availability->startDate)->format('Y-m-d'); - $endDate = (new \DateTimeImmutable())->setTimestamp($availability->endDate)->format('Y-m-d'); - - // Combine date and time for start and end - $startDateTime = new \DateTimeImmutable("{$startDate} {$availability->startTime}"); - $endDateTime = new \DateTimeImmutable("{$endDate} {$availability->endTime}"); - - // If startDate is before the selectedDate, use the selectedDate as the start - if ($startDateTime < $selectedDate) { - $startDateTime = $selectedDate->setTime(0, 0); - } - - // Determine the earliest start and latest end times - if (is_null($earliestStartDateTime) || $startDateTime < $earliestStartDateTime) { - $earliestStartDateTime = $startDateTime; - } - if (is_null($latestEndDateTime) || $endDateTime > $latestEndDateTime) { - $latestEndDateTime = $endDateTime; - } - } - - return [$earliestStartDateTime, $latestEndDateTime]; - } - protected function writeEntityUpdate($entity, $resolveReferences): Entity { $repository = new AvailabilityRepository(); diff --git a/zmsentities/src/Zmsentities/Collection/AvailabilityList.php b/zmsentities/src/Zmsentities/Collection/AvailabilityList.php index 6082697ae..e096c27ea 100644 --- a/zmsentities/src/Zmsentities/Collection/AvailabilityList.php +++ b/zmsentities/src/Zmsentities/Collection/AvailabilityList.php @@ -177,7 +177,46 @@ public function validateInputs(\DateTimeImmutable $startDate, \DateTimeImmutable return $errorList; } - + /** + * Get the earliest startDateTime and latest endDateTime from an AvailabilityList + * If the start date of any availability is before the selected date, use the selected date instead. + * + * @param AvailabilityList $availabilityList + * @param \DateTimeImmutable $selectedDate + * @return array + */ + public function getDateTimeRangeFromList(\DateTimeImmutable $selectedDate): array + { + $earliestStartDateTime = null; + $latestEndDateTime = null; + + foreach ($this as $availability) { + // Convert Unix timestamp to date strings + $startDate = (new \DateTimeImmutable())->setTimestamp($availability->startDate)->format('Y-m-d'); + $endDate = (new \DateTimeImmutable())->setTimestamp($availability->endDate)->format('Y-m-d'); + + // Combine date and time for start and end + $startDateTime = new \DateTimeImmutable("{$startDate} {$availability->startTime}"); + $endDateTime = new \DateTimeImmutable("{$endDate} {$availability->endTime}"); + + // Adjust the startDateTime if it's before the selected date + if ($startDateTime < $selectedDate) { + $startDateTime = $selectedDate->setTime(0, 0); + } + + // Determine the earliest start time + if (is_null($earliestStartDateTime) || $startDateTime < $earliestStartDateTime) { + $earliestStartDateTime = $startDateTime; + } + + // Determine the latest end time + if (is_null($latestEndDateTime) || $endDateTime > $latestEndDateTime) { + $latestEndDateTime = $endDateTime; + } + } + + return [$earliestStartDateTime, $latestEndDateTime]; + } public function getConflicts($startDate, $endDate) {