*/ class QtiTimerFactory extends ConfigurableService implements DeliveryExecutionDelete { const SERVICE_ID = 'taoQtiTest/QtiTimerFactory'; const OPTION_TIMER_CLASS = 'timer-class'; const OPTION_STORAGE_CLASS = 'storage-class'; const OPTION_STORAGE_FORMAT_CLASS = 'storage-format'; /** * @return string */ public function getTimerClass() { $timerClass = $this->getOption(self::OPTION_TIMER_CLASS); if (!$timerClass) { $timerClass = QtiTimer::class; } return $timerClass; } /** * @return string */ public function getStorageClass() { $storageClass = $this->getOption(self::OPTION_STORAGE_CLASS); if (!$storageClass) { $storageClass = QtiTimeStorage::class; } return $storageClass; } /** * @return string */ public function getStorageFormatClass() { $storageFormat = $this->getOption(self::OPTION_STORAGE_FORMAT_CLASS); if (!$storageFormat) { $storageFormat = QtiTimeStorageJsonFormat::class; } return $storageFormat; } /** * @param string $testSessionId * @param string $userUri * @return Timer * @throws \Exception */ public function getTimer($testSessionId, $userUri) { /* @var TimeStorage $timerStorage */ $storageClass = $this->getStorageClass(); $timerStorage = new $storageClass($testSessionId, $userUri); $timerStorage->setStorageService($this->getServiceLocator()->get(StorageManager::SERVICE_ID)); if ($timerStorage instanceof QtiTimeStorageFormatAware) { $storageFormatClass = $this->getStorageFormatClass(); $timerStorage->setStorageFormat(new $storageFormatClass()); } /* @var Timer $timer */ $timerClass = $this->getTimerClass(); $timer = new $timerClass(); return $timer->setStorage($timerStorage) ->setStrategy($this->getServiceLocator()->get(TimerStrategyInterface::SERVICE_ID)) ->load(); } /** * @inheritdoc */ public function deleteDeliveryExecutionData(DeliveryExecutionDeleteRequest $request) { $sessionId = $request->getDeliveryExecution()->getIdentifier(); $timer = $this->getTimer($sessionId, $request->getDeliveryExecution()->getUserIdentifier()); return $timer->delete(); } }