* @package taoQtiTest */ class TestModelService extends ConfigurableService implements TestModel, \tao_models_classes_import_ImportProvider, \tao_models_classes_export_ExportProvider { const SERVICE_ID = 'taoQtiTest/TestModel'; const SUBSERVICE_COMPILATION = 'CompilationService'; /** * {@inheritDoc} * @see \taoTests_models_classes_TestModel::prepareContent() */ public function prepareContent(\core_kernel_classes_Resource $test, $items = []) { $service = $this->getServiceLocator()->get(\taoQtiTest_models_classes_QtiTestService::class); $service->save($test, $items); } /** * {@inheritDoc} * @see \taoTests_models_classes_TestModel::deleteContent() */ public function deleteContent(\core_kernel_classes_Resource $test) { $service = $this->getServiceLocator()->get(\taoQtiTest_models_classes_QtiTestService::class); $service->deleteContent($test); } /** * {@inheritDoc} * @see \taoTests_models_classes_TestModel::getItems() */ public function getItems(\core_kernel_classes_Resource $test) { $service = $this->getServiceLocator()->get(\taoQtiTest_models_classes_QtiTestService::class); return $service->getItems($test); } /** * {@inheritDoc} * @see \taoTests_models_classes_TestModel::onChangeTestLabel() */ public function onChangeTestLabel(\core_kernel_classes_Resource $test) { // do nothing } /** * {@inheritDoc} * @see \taoTests_models_classes_TestModel::getAuthoringUrl() */ public function getAuthoringUrl(\core_kernel_classes_Resource $test) { return _url('index', 'Creator', 'taoQtiTest', ['uri' => $test->getUri()]); } /** * Clone a QTI Test Resource. * * @param \core_kernel_classes_Resource $source The resource to be cloned. * @param \core_kernel_classes_Resource $destination An existing resource to be filled as the clone of $source. */ public function cloneContent(\core_kernel_classes_Resource $source, \core_kernel_classes_Resource $destination) { $service = \taoQtiTest_models_classes_QtiTestService::singleton(); $existingDir = $service->getQtiTestDir($source); $destinationDir = $service->getQtiTestDir($destination, false); if ($existingDir->exists()) { $iterator = $existingDir->getFlyIterator(Directory::ITERATOR_FILE | Directory::ITERATOR_RECURSIVE); /** @var File $file */ foreach ($iterator as $file) { $destinationDir->getFile($existingDir->getRelPath($file))->write($file->readStream()); } } else { \common_Logger::w('Test "' . $source->getUri() . '" had no content, nothing to clone'); } } public function getImportHandlers() { if ($this->hasOption('importHandlers')) { return $this->getOption('importHandlers'); } else { return []; } } public function getExportHandlers() { if ($this->hasOption('exportHandlers')) { return $this->getOption('exportHandlers'); } else { return []; } } /** * {@inheritDoc} * @see \oat\taoTests\models\TestModel::getCompiler() */ public function getCompiler(\core_kernel_classes_Resource $test, ServiceFileStorage $storage) { $service = $this->getSubService('CompilationService'); return $service->getCompiler($test, $storage); } public function getCompilerClass() { return $this->getSubService(self::SUBSERVICE_COMPILATION)->getCompilerClass(); } public function getPackerClass() { return 'oat\\taoQtiTest\\models\\pack\\QtiTestPacker'; } }