Load data instead of searching
Returns false on failure
@param string $deliveryExecutionId
@return array
762797
protected function loadData($deliveryExecutionId)
    {
        $qb = $this->getPersistence()->getPlatForm()->getQueryBuilder();
        $qb->select('*')
            ->from(self::TABLE_NAME)
            ->where(self::DELIVERY_EXECUTION_ID.'= :deid')
            ->setParameter('deid', $deliveryExecutionId);
        $data = $qb->execute()->fetch(\PDO::FETCH_ASSOC);
        $kvData = $this->getKvData([$deliveryExecutionId]);
        if (isset($kvData[$deliveryExecutionId])) {
            $data =  array_merge($data, $kvData[$deliveryExecutionId]);
        }
        return $data;
    }
632153
public function getAllDeliveryIds()
    {
        $returnValue = array();
        $sql = 'SELECT ' . self::RESULTS_TABLE_ID . ', ' . self::DELIVERY_COLUMN . ' FROM ' . self::RESULTS_TABLENAME;
        $results = $this->getPersistence()->query($sql);
        foreach ($results as $value) {
            $returnValue[] = array(
                "deliveryResultIdentifier" => $value[self::RESULTS_TABLE_ID],
                "deliveryIdentifier" => $value[self::DELIVERY_COLUMN]
            );
        }
        return $returnValue;
    }
1307595
public function getRelatedItemCallIds($deliveryResultIdentifier)
    {
        $keys = $this->getPersistence()->keys(self::PREFIX_CALL_ID . $deliveryResultIdentifier . '.*');
        array_walk($keys, 'self::subStrPrefix', self::PREFIX_CALL_ID);

        return $keys;
    }
927871
protected function action($deliveryExecution, $executionId, $isEndDate = false)
    {
        $this->getDeliveryStateService()->terminateExecution($deliveryExecution, [
            'reasons' =>[
                'category' => 'Technical'
            ],
            'comment' => $isEndDate
                ? 'The assessment was automatically terminated because end time expired.'
                : 'The assessment was automatically terminated.'
        ]);
        $this->report->add(Report::createSuccess('Execution terminated with success:'. $executionId ));
    }
1100361
private function loadCategoryNames($categoryIds, $storeId)
    {
        $loadCategoryIds = $categoryIds;

        if (isset($this->categoryNameCache[$storeId])) {
            $loadCategoryIds = array_diff($categoryIds, array_keys($this->categoryNameCache[$storeId]));
        }

        $loadCategoryIds  = array_map('intval', $loadCategoryIds);
        $useNameAttribute = $this->getUseNameInSearchAttribute();

        if (!empty($loadCategoryIds) && $useNameAttribute && $useNameAttribute->getId()) {
            $select = $this->prepareCategoryNameSelect($loadCategoryIds, $storeId);
            $entityIdField = $this->getEntityMetaData(CategoryInterface::class)->getIdentifierField();

            foreach ($this->getConnection()->fetchAll($select) as $row) {
                $categoryId = (int) $row[$entityIdField];
                $this->categoryNameCache[$storeId][$categoryId] = '';
                if ((bool) $row['use_name']) {
                    $this->categoryNameCache[$storeId][$categoryId] = $row['name'];
                }
            }
        }

        return isset($this->categoryNameCache[$storeId]) ? $this->categoryNameCache[$storeId] : [];
    }
355122
public function getProviders(DeliveryExecution $execution)
    {
        $serviceManager = $this->getServiceManager();
        $providerService = $serviceManager->get(TestProviderService::SERVICE_ID);
        $providers = $providerService->getAllProviders();
        return array_filter($providers, function ($provider) {
            return !is_null($provider) && $provider->isActive();
        });
    }
569007
public function loadByTransactionId($transactionId)
    {
        $db = $this->getDb();
        $data = $db->getRow('SELECT * FROM `oepaypal_orderpayments` WHERE `oepaypal_transactionid` = ' . $db->quote($transactionId));

        return $data;
    }
283070
protected function getProvidesForPackage($packageId)
    {
        $cacheKey = 'packageProvides.'.$packageId;
        $packageProvides = $this->getCachedValue($cacheKey);
        if ($packageProvides === false) {
            $packageProvides = array();

            $data = $this->dataProvider->getData();
            if (isset($data[$packageId])) {
                $info = $data[$packageId];
                if (isset($info['Provides']) && is_array($info['Provides'])) {
                    $packageProvides = $info['Provides'];
                }
            }

            $this->setCachedValue($cacheKey, $packageProvides);
        }

        return $packageProvides;
    }
1069205
public function getDeliveryThemeIdFromCache($deliveryId)
    {
        $cache    = $this->getCache();
        $cacheKey = $this->getCacheKey($deliveryId);
        if ($cache->has($cacheKey)) {
            return $cache->get($cacheKey);
        }

        return false;
    }
950186
private static function createErrorMessage($deliveryExecution, $action)
    {
        if ($deliveryExecution->getState()->getUri() === DeliveryExecution::STATE_FINISHED) {
            $errorMsg = __('%s could not be %s because it is finished. Please refresh your data.', $deliveryExecution->getLabel(), $action);
        } else if ($deliveryExecution->getState()->getUri() === DeliveryExecution::STATE_TERMINATED) {
            $errorMsg = __('%s could not be %s because it is terminated. Please refresh your data.', $deliveryExecution->getLabel(), $action);
        } else {
            $errorMsg = __('%s could not be %s.', $deliveryExecution->getLabel(), $action);
        }

        return $errorMsg;
    }
353844
public function getDeliveryThemeId($deliveryId)
    {
        $themeId = $this->getDeliveryThemeIdFromCache($deliveryId);
        if ($themeId === false) {
            $themeId = $this->getDeliveryThemeIdFromDb($deliveryId);
            $this->storeDeliveryThemeIdToCache($deliveryId, $themeId);
        }

        return $themeId;
    }
632327
public function getDeliveryThemeIdFromDb($deliveryId)
    {
        try {
            $delivery = new core_kernel_classes_Resource($deliveryId);
            $property = $delivery->getProperty(static::DELIVERY_THEME_ID_URI);

            return (string)$delivery->getOnePropertyValue($property);
        } catch (common_exception_Error $e) {
            return '';
        }
    }
1252481
public function getAssignedUsers($deliveryId)
    {
        $users = [];
        foreach ($this->getInternalServices() as $service) {
            $users = array_merge($users, $service->getAssignedUsers($deliveryId));
        }

        return $users;
    }
538058
protected function isExpired(DeliveryExecution $deliveryExecution)
    {
        $result = false;
        $executionState = $deliveryExecution->getState()->getUri();

        if (in_array($executionState, [
                DeliveryExecutionState::STATE_PAUSED,
                DeliveryExecutionState::STATE_ACTIVE,
            ])
        ) {
            /** @var \oat\taoProctoring\model\implementation\DeliveryExecutionStateService $deliveryExecutionStateService */
            $deliveryExecutionStateService = $this->getServiceLocator()->get(DeliveryExecutionStateService::SERVICE_ID);

            if ($executionState === DeliveryExecutionState::STATE_ACTIVE) {
                $lastTestTakersEvent = $this->getLastTestTakersEvent($deliveryExecution);
                $lastEventTime = (new DateTimeImmutable())->setTimestamp($lastTestTakersEvent['created_at']);
            } else {
                $lastEventTime = $this->getLastPause($deliveryExecution);
            }

            if ($lastEventTime && $deliveryExecutionStateService->hasOption(DeliveryExecutionStateService::OPTION_TERMINATION_DELAY_AFTER_PAUSE)) {
                $delay = $deliveryExecutionStateService->getOption(DeliveryExecutionStateService::OPTION_TERMINATION_DELAY_AFTER_PAUSE);
                $result = ($lastEventTime->add(new DateInterval($delay)) < (new DateTimeImmutable('now')));
            }
        }

        return $result;
    }
83822
public function authoriseExecutions()
    {
        $deliveryExecution = $this->getRequestParameter('execution');
        $reason = $this->getRequestParameter('reason');
        $testCenter = $this->getRequestParameter('testCenter');

        if (!is_array($deliveryExecution)) {
            $deliveryExecution = array($deliveryExecution);
        }

        try {

            $data = DeliveryHelper::authoriseExecutions($deliveryExecution, $reason, $testCenter);

            $response = [
                'success' => !count($data['unprocessed']),
                'data' => $data
            ];

            if (!$response['success']) {
                $response['errorCode'] = self::ERROR_AUTHORIZE_EXECUTIONS;
                $response['errorMsg'] = __('Some delivery executions have not been authorized');
            }

            $this->returnJson($response);
        } catch (QtiTestExtractionFailedException $e) {
            $response = [
                'success' => false,
                'data' => [],
                'errorCode' => self::ERROR_AUTHORIZE_EXECUTIONS,
                'errorMsg' => __('Decryption failed because of using the wrong customer app key.'),
            ];

            $this->returnJson($response);
        } catch (ServiceNotFoundException $e) {
            \common_Logger::w('No delivery service defined for proctoring');
            $this->returnError('Proctoring interface not available');
        }
    }
420087
public function storeDeliveryThemeIdToCache($deliveryId, $themeId)
    {
        try {
            if ($this->getCachePersistence() !== null) {
                return $this->getCachePersistence()->set($this->getCacheKey($deliveryId), $themeId, $this->getCacheTtl());
            }
        } catch (common_exception_NotImplemented $e) {
        }

        return false;
    }
56904
protected function getDeliveryExecutionId()
    {
        $request = \Context::getInstance()->getRequest();

        $deliveryExecutionId = '';
        if ($request->hasParameter('deliveryExecution')) {
            $deliveryExecutionId = \tao_helpers_Uri::decode(
                $request->getParameter('deliveryExecution')
            );
        } elseif ($request->hasParameter('testServiceCallId')) {
            $deliveryExecutionId = \tao_helpers_Uri::decode(
                $request->getParameter('testServiceCallId')
            );
        } elseif ($request->hasParameter('serviceCallId')) {
            $deliveryExecutionId = \tao_helpers_Uri::decode(
                $request->getParameter('serviceCallId')
            );
        }

        return $deliveryExecutionId;
    }