getContainer()->getPermissionsService()->currentUserCanWriteTime(Entities::APPOINTMENTS)) { throw new AccessDeniedException('You are not allowed to update appointment'); } $result = new CommandResult(); $this->checkMandatoryFields($command); /** @var SettingsService $settingsService */ $settingsService = $this->container->get('domain.settings.service'); /** @var AppointmentRepository $appointmentRepo */ $appointmentRepo = $this->container->get('domain.booking.appointment.repository'); /** @var ServiceRepository $serviceRepository */ $serviceRepository = $this->container->get('domain.bookable.service.repository'); /** @var AppointmentApplicationService $appointmentAS */ $appointmentAS = $this->container->get('application.booking.appointment.service'); /** @var AbstractUser $user */ $user = $this->container->get('logged.in.user'); if ($user->getType() === Entities::CUSTOMER && !$settingsService->getSetting('roles', 'allowCustomerReschedule') ) { throw new AccessDeniedException('You are not allowed to update appointment'); } $appointmentId = (int)$command->getArg('id'); $bookingStart = $command->getField('bookingStart'); /** @var Appointment $appointment */ $appointment = $appointmentRepo->getById($appointmentId); /** @var Service $service */ $service = $serviceRepository->getProviderServiceWithExtras( $appointment->getServiceId()->getValue(), $appointment->getProviderId()->getValue() ); /** @var CustomerBooking $booking */ foreach ($appointment->getBookings()->getItems() as $booking) { if ($user->getType() === Entities::CUSTOMER && $booking->getCustomerId()->getValue() !== $user->getId()->getValue() && in_array($booking->getStatus()->getValue(), [BookingStatus::APPROVED, BookingStatus::PENDING], true) && ($service->getMinCapacity()->getValue() !== 1 || $service->getMaxCapacity()->getValue() !==1) ) { throw new AccessDeniedException('You are not allowed to update appointment'); } } if (!$appointment instanceof Appointment) { $result->setResult(CommandResult::RESULT_ERROR); $result->setMessage('Could not get appointment'); return $result; } $appointment->setBookingStart( new DateTimeValue( DateTimeService::getCustomDateTimeObject( $bookingStart ) ) ); $appointment->setBookingEnd( new DateTimeValue( DateTimeService::getCustomDateTimeObject($bookingStart) ->modify('+' . $appointmentAS->getAppointmentLengthTime($appointment, $service) . ' second') ) ); if (!$appointmentAS->canBeBooked($appointment, $user->getType() === Entities::CUSTOMER)) { $result->setResult(CommandResult::RESULT_ERROR); $result->setMessage(FrontendStrings::getCommonStrings()['time_slot_unavailable']); $result->setData([ 'timeSlotUnavailable' => true ]); return $result; } try { $appointmentRepo->update($appointmentId, $appointment); } catch (QueryExecutionException $e) { throw $e; } $result->setResult(CommandResult::RESULT_SUCCESS); $result->setMessage('Successfully updated appointment time'); $result->setData([ Entities::APPOINTMENT => $appointment->toArray() ]); return $result; } }