* @package taoQTIItem */ class QtiItemImport implements tao_models_classes_import_ImportHandler, PhpSerializable, ServiceLocatorAwareInterface, TaskParameterProviderInterface { use PhpSerializeStateless; use EventManagerAwareTrait; use ImportHandlerHelperTrait; /** * @see tao_models_classes_import_ImportHandler::getLabel() */ public function getLabel() { return __('QTI/APIP XML Item Document'); } /** * @see tao_models_classes_import_ImportHandler::getForm() */ public function getForm() { $form = new QtiItemImportForm(); return $form->getForm(); } /** * @see tao_models_classes_import_ImportHandler::import() * @param \core_kernel_classes_Class $class * @param \tao_helpers_form_Form|array $form * @param string|null $userId owner of the resource * @return Report * @throws \oat\oatbox\service\ServiceNotFoundException */ public function import($class, $form, $userId = null) { try { $uploadedFile = $this->fetchUploadedFile($form); $importService = ImportService::singleton(); $report = Report::createSuccess(__('1 item imported from the given QTI/APIP XML Item Document.')); $subReport = $importService->importQTIFile($uploadedFile, $class, true); $report->add($subReport); $this->getUploadService()->remove($uploadedFile); if (Report::TYPE_SUCCESS == $report->getType()) { $this->getEventManager()->trigger(new QtiItemImportEvent($report)); } } catch (UnsupportedQtiElement $e) { $report = Report::createFailure(__("A QTI component is not supported. The system returned the following error: %s\n", $e->getUserMessage())); } catch (QtiModelException $e) { $report = Report::createFailure(__("One or more QTI components are not supported by the system. The system returned the following error: %s\n", $e->getUserMessage())); } catch (ParsingException $e) { $report = Report::createFailure(__("The validation of the imported QTI item failed. The system returned the following error:%s\n", $e->getMessage())); } catch (ValidationException $e) { $report = $e->getReport(); } catch (common_Exception $e) { $report = Report::createFailure(__("An unexpected error occurred during the import of the QTI Item. The system returned the following error: %s\n", $e->getMessage())); } return $report; } }