* @package taoDelivery */ class AttemptService extends ConfigurableService implements AttemptServiceInterface { const OPTION_STATES_TO_EXCLUDE = 'states_to_exclude'; /** * @inheritdoc */ public function getAttempts($deliveryId, User $user) { $executions = $this->getServiceLocator()->get(ServiceProxy::SERVICE_ID) ->getUserExecutions(new \core_kernel_classes_Resource($deliveryId), $user->getIdentifier()); return $this->filterStates($executions); } /** * @inheritdoc */ public function setStatesToExclude(array $deliveryExecutionsStates) { $this->setOption(self::OPTION_STATES_TO_EXCLUDE, $deliveryExecutionsStates); } /** * @return array|mixed */ public function getStatesToExclude() { $statesToExclude = $this->getOption(self::OPTION_STATES_TO_EXCLUDE); if (!is_array($statesToExclude)) { $statesToExclude = []; } return $statesToExclude; } /** * @param DeliveryExecutionInterface[] $executions * @return DeliveryExecutionInterface[] */ protected function filterStates(array $executions = []) { $statesToExclude = $this->getStatesToExclude(); if (!empty($statesToExclude)) { $result = array_filter($executions, function ($execution) use ($statesToExclude) { return !in_array($execution->getState()->getUri(), $statesToExclude); }); } else { $result = $executions; } return $result; } }