getContainer()->getPermissionsService()->currentUserCanRead(Entities::EMPLOYEES) && !$this->getContainer()->getPermissionsService()->currentUserCanRead(Entities::CUSTOMERS) ) { throw new AccessDeniedException('You are not allowed to read user'); } $result = new CommandResult(); /** @var UserApplicationService $userAS */ $userAS = $this->getContainer()->get('application.user.service'); $appointmentsCount = $userAS->getAppointmentsCountForUser($command->getArg('id')); $message = ''; if ($appointmentsCount['futureAppointments'] > 0) { $appointmentString = $appointmentsCount['futureAppointments'] === 1 ? 'appointment' : 'appointments'; $message = "Could not delete user. This user has {$appointmentsCount['futureAppointments']} {$appointmentString} in the future."; } elseif ($appointmentsCount['pastAppointments'] > 0) { $appointmentString = $appointmentsCount['pastAppointments'] === 1 ? 'appointment' : 'appointments'; $message = "This user has {$appointmentsCount['pastAppointments']} {$appointmentString} in the past."; } $result->setResult(CommandResult::RESULT_SUCCESS); $result->setMessage('Successfully retrieved message.'); $result->setData([ 'valid' => $appointmentsCount['futureAppointments'] ? false : true, 'message' => $message ]); return $result; } }