Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| AbstractLtiDeliveryExecutionService | |
0.00% |
0 / 31 |
|
0.00% |
0 / 4 |
132 | |
0.00% |
0 / 1 |
| getActiveDeliveryExecution | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| executionStateChanged | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| executionCreated | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| getPersistence | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2017 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\ltiDeliveryProvider\model\execution\implementation; |
| 23 | |
| 24 | use oat\ltiDeliveryProvider\model\execution\LtiDeliveryExecutionService as LtiDeliveryExecutionServiceInterface; |
| 25 | use oat\taoDelivery\model\execution\DeliveryExecution; |
| 26 | use oat\oatbox\service\ConfigurableService; |
| 27 | use oat\taoDelivery\models\classes\execution\event\DeliveryExecutionState; |
| 28 | use oat\tao\model\actionQueue\ActionQueue; |
| 29 | use oat\ltiDeliveryProvider\model\actions\GetActiveDeliveryExecution; |
| 30 | use oat\taoDelivery\models\classes\execution\event\DeliveryExecutionCreated; |
| 31 | use oat\taoLti\models\classes\LtiLaunchData; |
| 32 | use oat\taoLti\models\classes\TaoLtiSession; |
| 33 | use oat\taoResultServer\models\classes\ResultService; |
| 34 | use oat\tao\model\search\Search; |
| 35 | |
| 36 | /** |
| 37 | * Class AbstractLtiDeliveryExecutionService |
| 38 | * @author Antoine Robin, <antoine@taotesting.com> |
| 39 | * @package oat\ltiDeliveryProvider\model\execution |
| 40 | */ |
| 41 | abstract class AbstractLtiDeliveryExecutionService extends ConfigurableService implements |
| 42 | LtiDeliveryExecutionServiceInterface |
| 43 | { |
| 44 | public const OPTION_QUEUE_PERSISTENCE = 'queue_persistence'; |
| 45 | |
| 46 | /** |
| 47 | * @inheritdoc |
| 48 | */ |
| 49 | public function getActiveDeliveryExecution(\core_kernel_classes_Resource $delivery) |
| 50 | { |
| 51 | /** @var ActionQueue $actionQueue */ |
| 52 | $actionQueue = $this->getServiceManager()->get(ActionQueue::SERVICE_ID); |
| 53 | $action = new GetActiveDeliveryExecution($delivery); |
| 54 | if ($actionQueue->perform($action)) { |
| 55 | return $action->getResult(); |
| 56 | } else { |
| 57 | throw new \oat\tao\model\actionQueue\ActionFullException($actionQueue->getPosition($action)); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @param DeliveryExecutionState $event |
| 63 | */ |
| 64 | public function executionStateChanged(DeliveryExecutionState $event) |
| 65 | { |
| 66 | $persistence = $this->getPersistence(); |
| 67 | if ($event->getState() === DeliveryExecution::STATE_ACTIVE) { |
| 68 | $persistence->incr(self::class . '_' . 'active_executions'); |
| 69 | } elseif ($event->getPreviousState() === DeliveryExecution::STATE_ACTIVE) { |
| 70 | $persistence->decr(self::class . '_' . 'active_executions'); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @param DeliveryExecutionCreated $event |
| 76 | * @throws |
| 77 | */ |
| 78 | public function executionCreated(DeliveryExecutionCreated $event) |
| 79 | { |
| 80 | $persistence = $this->getPersistence(); |
| 81 | if ($event->getDeliveryExecution()->getState()->getUri() === DeliveryExecution::STATE_ACTIVE) { |
| 82 | $persistence->incr(self::class . '_' . 'active_executions'); |
| 83 | } |
| 84 | $searchService = $this->getServiceLocator()->get(Search::SERVICE_ID); |
| 85 | if ($searchService->supportCustomIndex()) { |
| 86 | $session = \common_session_SessionManager::getSession(); |
| 87 | if ($session instanceof TaoLtiSession) { |
| 88 | $deliveryExecution = $event->getDeliveryExecution(); |
| 89 | $body = [ |
| 90 | 'label' => $deliveryExecution->getLabel(), |
| 91 | 'delivery' => $deliveryExecution->getDelivery()->getUri(), |
| 92 | 'type' => ResultService::DELIVERY_RESULT_CLASS_URI |
| 93 | ]; |
| 94 | $lunchData = $session->getLaunchData(); |
| 95 | if ($lunchData->hasVariable(LtiLaunchData::RESOURCE_LINK_ID)) { |
| 96 | $body[LtiLaunchData::RESOURCE_LINK_ID] = $lunchData->getVariable(LtiLaunchData::RESOURCE_LINK_ID); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @return \common_persistence_KeyValuePersistence |
| 104 | */ |
| 105 | protected function getPersistence() |
| 106 | { |
| 107 | $persistenceId = $this->getOption(self::OPTION_QUEUE_PERSISTENCE); |
| 108 | |
| 109 | return $this |
| 110 | ->getServiceManager() |
| 111 | ->get(\common_persistence_Manager::SERVICE_ID) |
| 112 | ->getPersistenceById($persistenceId); |
| 113 | } |
| 114 | } |