Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| DeliveryLogTimerAdjustedEventListener | |
100.00% |
20 / 20 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
| logTimeAdjustment | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
2 | |||
| getDeliveryLogService | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTestSessionService | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCurrentItemId | |
100.00% |
5 / 5 |
|
100.00% |
1 / 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) 2020 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoProctoring\model\deliveryLog\listener; |
| 24 | |
| 25 | use common_Exception; |
| 26 | use common_exception_Error; |
| 27 | use common_exception_NotFound; |
| 28 | use common_ext_ExtensionException; |
| 29 | use oat\oatbox\service\ConfigurableService; |
| 30 | use oat\oatbox\service\exception\InvalidServiceManagerException; |
| 31 | use oat\taoProctoring\model\deliveryLog\DeliveryLog; |
| 32 | use oat\taoProctoring\model\deliveryLog\event\DeliveryLogEvent; |
| 33 | use oat\taoProctoring\model\event\DeliveryExecutionTimerAdjusted; |
| 34 | use oat\taoProctoring\model\implementation\TestSessionService; |
| 35 | use oat\taoQtiTest\models\QtiTestExtractionFailedException; |
| 36 | use qtism\runtime\tests\AssessmentTestSession; |
| 37 | |
| 38 | class DeliveryLogTimerAdjustedEventListener extends ConfigurableService |
| 39 | { |
| 40 | /** |
| 41 | * @param DeliveryExecutionTimerAdjusted $event |
| 42 | * @throws InvalidServiceManagerException |
| 43 | * @throws QtiTestExtractionFailedException |
| 44 | * @throws common_Exception |
| 45 | * @throws common_exception_Error |
| 46 | * @throws common_exception_NotFound |
| 47 | * @throws common_ext_ExtensionException |
| 48 | */ |
| 49 | public function logTimeAdjustment(DeliveryExecutionTimerAdjusted $event): void |
| 50 | { |
| 51 | $data = [ |
| 52 | 'reason' => $event->getReason(), |
| 53 | 'increment' => $event->getSeconds(), |
| 54 | 'context' => '' |
| 55 | ]; |
| 56 | |
| 57 | $session = $this->getTestSessionService()->getTestSession($event->getDeliveryExecution()); |
| 58 | if ($session) { |
| 59 | $data['context'] = $data['itemId'] = $this->getCurrentItemId($session); |
| 60 | } |
| 61 | |
| 62 | $this->getDeliveryLogService()->log( |
| 63 | $event->getDeliveryExecution()->getIdentifier(), |
| 64 | DeliveryLogEvent::EVENT_ID_TEST_ADJUST_TIME, |
| 65 | $data |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @return DeliveryLog|object |
| 71 | */ |
| 72 | private function getDeliveryLogService() |
| 73 | { |
| 74 | return $this->getServiceLocator()->get(DeliveryLog::SERVICE_ID); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @return TestSessionService|object |
| 79 | */ |
| 80 | private function getTestSessionService(): TestSessionService |
| 81 | { |
| 82 | return $this->getServiceLocator()->get(TestSessionService::SERVICE_ID); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @param $session |
| 87 | * @return string|null |
| 88 | */ |
| 89 | private function getCurrentItemId(AssessmentTestSession $session): ?string |
| 90 | { |
| 91 | $result = null; |
| 92 | $item = $session->getCurrentAssessmentItemRef(); |
| 93 | if ($item) { |
| 94 | $result = $item->getIdentifier(); |
| 95 | } |
| 96 | return $result; |
| 97 | } |
| 98 | } |