Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| SessionStateHelper | |
0.00% |
0 / 15 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
| onExecutionReactivation | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |||
| getTestSessionService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTestSessionStateRestorationService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLoggerService | |
0.00% |
0 / 1 |
|
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) 2018-2022 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoDeliveryRdf\helper; |
| 24 | |
| 25 | use common_Exception; |
| 26 | use common_exception_Error; |
| 27 | use common_exception_NotFound; |
| 28 | use common_ext_ExtensionException; |
| 29 | use oat\oatbox\log\LoggerService; |
| 30 | use oat\oatbox\service\exception\InvalidServiceManagerException; |
| 31 | use oat\oatbox\service\ServiceManager; |
| 32 | use oat\taoDelivery\models\classes\execution\event\DeliveryExecutionReactivated; |
| 33 | use oat\taoQtiTest\models\QtiTestExtractionFailedException; |
| 34 | use oat\taoQtiTest\models\TestSessionService; |
| 35 | use oat\taoQtiTest\models\TestSessionState\Api\TestSessionStateRestorationInterface; |
| 36 | use oat\taoQtiTest\models\TestSessionState\Exception\RestorationImpossibleException; |
| 37 | use qtism\runtime\storage\common\StorageException; |
| 38 | use qtism\runtime\tests\AssessmentTestSessionState; |
| 39 | |
| 40 | class SessionStateHelper |
| 41 | { |
| 42 | /** |
| 43 | * @param DeliveryExecutionReactivated $event |
| 44 | * @throws StorageException |
| 45 | * @throws common_Exception |
| 46 | * @throws common_exception_NotFound |
| 47 | * @throws common_ext_ExtensionException |
| 48 | * @throws InvalidServiceManagerException |
| 49 | * @throws QtiTestExtractionFailedException |
| 50 | * @throws common_exception_Error |
| 51 | */ |
| 52 | public static function onExecutionReactivation(DeliveryExecutionReactivated $event) |
| 53 | { |
| 54 | $testSessionService = self::getTestSessionService(); |
| 55 | $deliveryExecution = $event->getDeliveryExecution(); |
| 56 | $session = $testSessionService->getTestSession($deliveryExecution); |
| 57 | if (!$session) { |
| 58 | try { |
| 59 | self::getTestSessionStateRestorationService()->restore($event->getDeliveryExecution()); |
| 60 | } catch (RestorationImpossibleException $e) { |
| 61 | self::getLoggerService()->warning($e->getMessage()); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | $session = $testSessionService->getTestSession($deliveryExecution); |
| 66 | } |
| 67 | |
| 68 | if ($session) { |
| 69 | $session->setState(AssessmentTestSessionState::SUSPENDED); |
| 70 | $testSessionService->persist($session); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | private static function getTestSessionService(): TestSessionService |
| 75 | { |
| 76 | return ServiceManager::getServiceManager()->getContainer()->get(TestSessionService::SERVICE_ID); |
| 77 | } |
| 78 | |
| 79 | private static function getTestSessionStateRestorationService(): TestSessionStateRestorationInterface |
| 80 | { |
| 81 | return ServiceManager::getServiceManager()->getContainer()->get(TestSessionStateRestorationInterface::class); |
| 82 | } |
| 83 | |
| 84 | private static function getLoggerService(): LoggerService |
| 85 | { |
| 86 | return ServiceManager::getServiceManager()->getContainer()->get(LoggerService::SERVICE_ID); |
| 87 | } |
| 88 | } |