(non-PHPdoc)
@see \oat\taoDelivery\model\authorization\AuthorizationProvider::verifyResumeAuthorization()
@param DeliveryExecution $deliveryExecution
@param User $user
481305
public function verifyResumeAuthorization(DeliveryExecutionInterface $deliveryExecution, User $user)
    {
        /** @var TestTakerAuthorizationService $service */
        $service = $this->getServiceLocator()->get(TestTakerAuthorizationService::SERVICE_ID);
        $service->verifyResumeAuthorization($deliveryExecution, $user);
    }
1039176
protected function isUserExcluded(\core_kernel_classes_Resource $delivery, User $user){
        $excludedUsers = $delivery->getPropertyValues(new \core_kernel_classes_Property(DeliveryContainerService::PROPERTY_EXCLUDED_SUBJECTS));
        return in_array($user->getIdentifier(), $excludedUsers);
    }
601071
public function reportExecution(DeliveryExecution $deliveryExecution, $reason)
    {
        $deliveryLog = $this->getDeliveryLogService();
        $data = [
            'reason' => $reason,
            'timestamp' => microtime(true),
            'itemId' => $this->getCurrentItemId($deliveryExecution),
            'context' => $this->getContext($deliveryExecution)
        ];
        $returnValue = $deliveryLog->log($deliveryExecution->getIdentifier(), 'TEST_IRREGULARITY', $data);

        // Trigger a report event.
        /** @var EventManager $eventManager */
        $eventManager = $this->getServiceManager()->get(EventManager::SERVICE_ID);
        $eventManager->trigger(new DeliveryExecutionIrregularityReport($deliveryExecution));

        return $returnValue;
    }
1135728
protected function approveTranslation($access, TranslationEntity $translation, UserEntity $user, $packageVersionID)
    {
        if ($access < Access::ADMIN) {
            throw new UserMessageException(t('Access denied'));
        }
        if ($translation->isCurrent()) {
            throw new UserMessageException(t('The selected translation is already the current one'));
        }
        $translationID = $translation->getID();
        $translations = $this->convertTranslationToGettext($translation, false);
        $importer = $this->app->make(Importer::class);
        $importer->import($translations, $translation->getLocale(), $user, ImportOptions::forAdministrators());
        $this->getEntityManager()->clear();
        $translation = $this->app->make(TranslationRepository::class)->find($translationID);
        $result = $this->app->make(Editor::class)->getTranslations($translation->getLocale(), $translation->getTranslatable());

        return $this->app->make(ResponseFactoryInterface::class)->json($result);
    }
1052277
public function doAuthentication(UserInterface $user)
    {
        /** @var \PServerCore\Entity\Repository\User $repository */
        $repository = $this->entityManager->getRepository($this->getUserEntityClassName());

        // fix if we have a proxy we don´t have a valid entity, so we have to clear before we can create a new select
        $username = $user->getUsername();
        $repository->clear();

        $userNew = $repository->getUser4UserName($username);

        $authService = $this->getAuthService();

        $authService->getStorage()->write($userNew);
    }
806795
public function initResultServer($compiledDelivery, $executionIdentifier, $userUri)
    {
        $storage = $this->getResultStorage($compiledDelivery);
        //$storage->spawnResult($executionIdentifier);

        //link test taker identifier with results
        $storage->storeRelatedTestTaker($executionIdentifier, $userUri);

        //link delivery identifier with results
        $storage->storeRelatedDelivery($executionIdentifier, $compiledDelivery->getUri());
    }
566514
public function initResultServer($compiledDelivery, $executionIdentifier, $userUri) {
        $this->getServiceManager()->get(\oat\taoResultServer\models\classes\ResultServerService::SERVICE_ID)
            ->initResultServer($compiledDelivery, $executionIdentifier, $userUri);
    }
1274248
public static function pauseExecutions($deliveryExecutions, $reason = null)
    {
        /** @var DeliveryExecutionStateService $deliveryExecutionStateService */
        $deliveryExecutionStateService = ServiceManager::getServiceManager()->get(DeliveryExecutionStateService::SERVICE_ID);

        $result = [ 'processed' => [], 'unprocessed' => [] ];
        foreach($deliveryExecutions as $deliveryExecution) {
            if (is_string($deliveryExecution)) {
                $deliveryExecution = self::getDeliveryExecutionById($deliveryExecution);
            }

            try {
                $isPaused = $deliveryExecutionStateService->pauseExecution($deliveryExecution, $reason);
                if ($isPaused) {
                    $result['processed'][$deliveryExecution->getIdentifier()] = true;
                } else {
                    $result['unprocessed'][$deliveryExecution->getIdentifier()] = self::createErrorMessage($deliveryExecution, __('paused'));
                }
            } catch (\Exception $exception) {
                $result['unprocessed'][$deliveryExecution->getIdentifier()] = $exception->getMessage();
            }
        }

        return $result;
    }
719370
protected function canBeAuthorised(DeliveryExecution $deliveryExecution)
    {
        $result = false;
        $user = \common_session_SessionManager::getSession()->getUser();
        $stateUri = $deliveryExecution->getState()->getUri();
        if ($stateUri === ProctoredDeliveryExecution::STATE_AWAITING) {
            $result = true;
        }

        if (
            $user instanceof GuestTestUser &&
            !in_array($stateUri, [
                ProctoredDeliveryExecution::STATE_FINISHED,
                ProctoredDeliveryExecution::STATE_TERMINATED,
                ProctoredDeliveryExecution::STATE_CANCELED,
            ])
        ){
            $result = true;
        }

        return $result;
    }
360604
private function reApplyOrderAddresses($cart, $user)
    {
        // validate addresses
        $this->validateOrCreateAddresses($cart, $user);

        // reapply invoice address of cart
        if ($cart->getInvoiceAddress()->getContactAddress()) {
            $this->orderAddressManager->getAndSetOrderAddressByContactAddress(
                $cart->getInvoiceAddress()->getContactAddress(),
                null,
                null,
                $cart->getInvoiceAddress()
            );
        }

        // reapply delivery address of cart
        if ($cart->getDeliveryAddress()->getContactAddress()) {
            $this->orderAddressManager->getAndSetOrderAddressByContactAddress(
                $cart->getDeliveryAddress()->getContactAddress(),
                null,
                null,
                $cart->getDeliveryAddress()
            );
        }

        // reapply delivery-addresses of every item
        foreach ($cart->getItems() as $item) {
            if ($item->getDeliveryAddress() &&
                $item->getDeliveryAddress()->getContactAddress()
            ) {
                $this->orderAddressManager->getAndSetOrderAddressByContactAddress(
                    $item->getDeliveryAddress()->getContactAddress(),
                    null,
                    null,
                    $item->getDeliveryAddress()
                );
            }
        }
    }
213535
public function getInitialStatus($deliveryId, User $user)
    {
        $service = $this->getServiceLocator()->get(TestTakerAuthorizationService::SERVICE_ID);
        return $service->isProctored($deliveryId, $user)
            ? DeliveryExecution::STATE_PAUSED
            : DeliveryExecution::STATE_ACTIVE;
    }
390208
public function terminateExecution(DeliveryExecution $deliveryExecution, $reason = null)
    {
        $executionState = $deliveryExecution->getState()->getUri();
        $result = false;

        if (ProctoredDeliveryExecution::STATE_TERMINATED !== $executionState && ProctoredDeliveryExecution::STATE_FINISHED !== $executionState) {
            $proctor = \common_session_SessionManager::getSession()->getUser();
            $eventManager = $this->getServiceManager()->get(EventManager::CONFIG_ID);

            $session = $this->getTestSessionService()->getTestSession($deliveryExecution);
            $logData = [
                'reason' => $reason,
                'timestamp' => microtime(true),
                'context' => $this->getContext($deliveryExecution),
                'itemId' => $session ? $this->getCurrentItemId($deliveryExecution) : null,
            ];

            $this->getDeliveryLogService()->log($deliveryExecution->getIdentifier(), 'TEST_TERMINATE', $logData);

            if ($session) {
                if ($session->isRunning()) {
                    $session->endTestSession();
                }
                $this->getTestSessionService()->persist($session);
                $this->getServiceLocator()->get(ExtendedStateService::SERVICE_ID)->persist($session->getSessionId());
            }

            // Delivery execution state changes after test session ends, in the same way as it happens
            // when a human test taker takes the test.
            $this->setState($deliveryExecution, ProctoredDeliveryExecution::STATE_TERMINATED);
            $eventManager->trigger(new DeliveryExecutionTerminated($deliveryExecution, $proctor, $reason));
            $result = true;
        }

        return $result;
    }
646448
public function updateDeliveryExecutionStatus(KVDeliveryExecution $deliveryExecution, $old, $new)
    {
        $this->update($deliveryExecution);
        $userId = $deliveryExecution->getUserIdentifier();
        if ($old != null) {
            $oldReferences = $this->getDeliveryExecutionsByStatus($userId, $old);
            foreach (array_keys($oldReferences) as $key) {
                if ($oldReferences[$key]->getIdentifier() == $deliveryExecution->getIdentifier()) {
                    unset($oldReferences[$key]);
                }
            }
            $this->setDeliveryExecutions($userId, $old, $oldReferences);
        }

        $newReferences = $this->getDeliveryExecutionsByStatus($userId, $new);
        $newReferences[$deliveryExecution->getIdentifier()] = $deliveryExecution;
        return $this->setDeliveryExecutions($userId, $new, $newReferences);
    }
872381
public function startDelivery(core_kernel_classes_Resource $delivery, core_kernel_classes_Resource $link, User $user) {
        $this->getAuthorizationProvider()->verifyStartAuthorization($delivery->getUri(), $user);

        /** @var LtiAssignment $assignmentService */
        $assignmentService = $this->getServiceLocator()->get(LtiAssignment::SERVICE_ID);
        if (!$assignmentService->isDeliveryExecutionAllowed($delivery->getUri(), $user) ) {
            throw new \common_exception_Unauthorized(__('User is not authorized to run this delivery'));
        }
        $stateService = $this->getServiceLocator()->get(StateServiceInterface::SERVICE_ID);
        $deliveryExecution = $stateService->createDeliveryExecution($delivery->getUri(), $user, $delivery->getLabel());

        $this->getServiceLocator()->get(LtiDeliveryExecutionService::SERVICE_ID)->createDeliveryExecutionLink($user->getIdentifier(), $link->getUri(), $deliveryExecution->getIdentifier());

	    return $deliveryExecution;
	}
348844
public function createDeliveryExecution($deliveryId, User $user, $label)
    {
        $status = $this->getInitialStatus($deliveryId, $user);
        $deliveryExecution = $this->getStorageEngine()->spawnDeliveryExecution($label, $deliveryId, $user->getIdentifier(), $status);
        // trigger event
        $event = new DeliveryExecutionCreated($deliveryExecution, $user);
        $this->getServiceLocator()->get(EventManager::SERVICE_ID)->trigger($event);
        return $deliveryExecution;
    }
1184526
protected function terminateExecution(DeliveryExecution $deliveryExecution) {
        if ($this->wetRun === true) {
            $deliveryExecutionStateService = ServiceManager::getServiceManager()->get(DeliveryExecutionStateService::SERVICE_ID);
            $deliveryExecutionStateService->terminateExecution(
                $deliveryExecution,
                [
                    'reasons' => $this->getTerminationReasons(),
                    'comment' => __('The assessment was automatically terminated by the system due to inactivity.'),
                ]
            );
            $this->addReport(Report::TYPE_INFO, "Delivery execution {$deliveryExecution->getIdentifier()} has been terminated.");
        } else {
            $this->addReport(Report::TYPE_INFO, "Delivery execution {$deliveryExecution->getIdentifier()} should be terminated.");
        }
    }
1252041
public function isExpired(DeliveryExecution $deliveryExecution)
    {
        $result = false;
        $executionState = $deliveryExecution->getState()->getUri();
        $lastTestTakersEvent = $this->getLastTestTakersEvent($deliveryExecution);

        if (in_array($executionState, [
                DeliveryExecutionState::STATE_AWAITING,
                DeliveryExecutionState::STATE_AUTHORIZED,
            ]) &&
            $lastTestTakersEvent)
        {
            /** @var \oat\taoProctoring\model\implementation\DeliveryExecutionStateService $deliveryExecutionStateService */
            $deliveryExecutionStateService = $this->getServiceLocator()->get(DeliveryExecutionStateService::SERVICE_ID);
            $delay = $deliveryExecutionStateService->getOption(DeliveryExecutionStateService::OPTION_CANCELLATION_DELAY);
            $lastTestEventTime = (new DateTimeImmutable())->setTimestamp($lastTestTakersEvent['created_at']);
            $result = ($lastTestEventTime->add(new DateInterval($delay)) < (new DateTimeImmutable()));
        }

        return $result;
    }