Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| QtiTimerFactory | |
0.00% |
0 / 26 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
| getTimerClass | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getStorageClass | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getStorageFormatClass | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getTimer | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| deleteDeliveryExecutionData | |
0.00% |
0 / 3 |
|
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\taoQtiTest\models\runner\time; |
| 23 | |
| 24 | use oat\oatbox\service\ConfigurableService; |
| 25 | use oat\taoDelivery\model\execution\Delete\DeliveryExecutionDelete; |
| 26 | use oat\taoDelivery\model\execution\Delete\DeliveryExecutionDeleteRequest; |
| 27 | use oat\taoQtiTest\models\runner\StorageManager; |
| 28 | use oat\taoQtiTest\models\runner\time\storageFormat\QtiTimeStorageJsonFormat; |
| 29 | use oat\taoQtiTest\models\TestSessionService; |
| 30 | use oat\taoTests\models\runner\time\Timer; |
| 31 | use oat\taoTests\models\runner\time\TimerStrategyInterface; |
| 32 | use oat\taoTests\models\runner\time\TimeStorage; |
| 33 | |
| 34 | /** |
| 35 | * Class QtiTimerFactory |
| 36 | * @package oat\taoQtiTest\models\runner\time |
| 37 | * @author Jean-Sébastien Conan <jean-sebastien@taotesting.com> |
| 38 | */ |
| 39 | class QtiTimerFactory extends ConfigurableService implements DeliveryExecutionDelete |
| 40 | { |
| 41 | public const SERVICE_ID = 'taoQtiTest/QtiTimerFactory'; |
| 42 | |
| 43 | public const OPTION_TIMER_CLASS = 'timer-class'; |
| 44 | public const OPTION_STORAGE_CLASS = 'storage-class'; |
| 45 | public const OPTION_STORAGE_FORMAT_CLASS = 'storage-format'; |
| 46 | |
| 47 | /** |
| 48 | * @return string |
| 49 | */ |
| 50 | public function getTimerClass() |
| 51 | { |
| 52 | $timerClass = $this->getOption(self::OPTION_TIMER_CLASS); |
| 53 | if (!$timerClass) { |
| 54 | $timerClass = QtiTimer::class; |
| 55 | } |
| 56 | return $timerClass; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @return string |
| 61 | */ |
| 62 | public function getStorageClass() |
| 63 | { |
| 64 | $storageClass = $this->getOption(self::OPTION_STORAGE_CLASS); |
| 65 | if (!$storageClass) { |
| 66 | $storageClass = QtiTimeStorage::class; |
| 67 | } |
| 68 | return $storageClass; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @return string |
| 73 | */ |
| 74 | public function getStorageFormatClass() |
| 75 | { |
| 76 | $storageFormat = $this->getOption(self::OPTION_STORAGE_FORMAT_CLASS); |
| 77 | if (!$storageFormat) { |
| 78 | $storageFormat = QtiTimeStorageJsonFormat::class; |
| 79 | } |
| 80 | return $storageFormat; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @param string $testSessionId |
| 85 | * @param string $userUri |
| 86 | * @return Timer |
| 87 | * @throws \Exception |
| 88 | */ |
| 89 | public function getTimer($testSessionId, $userUri) |
| 90 | { |
| 91 | /* @var TimeStorage $timerStorage */ |
| 92 | $storageClass = $this->getStorageClass(); |
| 93 | $timerStorage = new $storageClass($testSessionId, $userUri); |
| 94 | $timerStorage->setStorageService($this->getServiceLocator()->get(StorageManager::SERVICE_ID)); |
| 95 | |
| 96 | if ($timerStorage instanceof QtiTimeStorageFormatAware) { |
| 97 | $storageFormatClass = $this->getStorageFormatClass(); |
| 98 | $timerStorage->setStorageFormat(new $storageFormatClass()); |
| 99 | } |
| 100 | |
| 101 | /* @var Timer $timer */ |
| 102 | $timerClass = $this->getTimerClass(); |
| 103 | $timer = new $timerClass(); |
| 104 | |
| 105 | return $timer->setStorage($timerStorage) |
| 106 | ->setStrategy($this->getServiceLocator()->get(TimerStrategyInterface::SERVICE_ID)) |
| 107 | ->load(); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * @inheritdoc |
| 112 | */ |
| 113 | public function deleteDeliveryExecutionData(DeliveryExecutionDeleteRequest $request) |
| 114 | { |
| 115 | $sessionId = $request->getDeliveryExecution()->getIdentifier(); |
| 116 | $timer = $this->getTimer($sessionId, $request->getDeliveryExecution()->getUserIdentifier()); |
| 117 | return $timer->delete(); |
| 118 | } |
| 119 | } |