getContainer()->get('logged.in.user'); if ($currentUser === null || !$this->getContainer()->getPermissionsService()->currentUserCanRead(Entities::APPOINTMENTS)) { throw new AccessDeniedException('You are not allowed to read appointments'); } $result = new CommandResult(); /** @var AppointmentRepository $appointmentRepo */ $appointmentRepo = $this->container->get('domain.booking.appointment.repository'); /** @var CustomerApplicationService $customerAS */ $customerAS = $this->container->get('application.user.customer.service'); $appointment = $appointmentRepo->getById((int)$command->getField('id')); $customerAS->removeBookingsForOtherCustomers($currentUser, new Collection([$appointment])); /** @var CustomerBooking $booking */ foreach ($appointment->getBookings()->getItems() as $booking) { if ($booking->getCustomFields() && json_decode($booking->getCustomFields()->getValue(), true) === null) { $booking->setCustomFields(null); } } if (!$appointment instanceof Appointment) { $result->setResult(CommandResult::RESULT_ERROR); $result->setMessage('Could not get appointment'); return $result; } $result->setResult(CommandResult::RESULT_SUCCESS); $result->setMessage('Successfully retrieved appointment'); $result->setData([ Entities::APPOINTMENT => $appointment->toArray() ]); return $result; } }