diff --git a/models/classes/import/class.TestImport.php b/models/classes/import/class.TestImport.php index 418f9d509..a24ca295d 100755 --- a/models/classes/import/class.TestImport.php +++ b/models/classes/import/class.TestImport.php @@ -48,9 +48,6 @@ class taoQtiTest_models_classes_import_TestImport implements use EventManagerAwareTrait; use ImportHandlerHelperTrait; - public const DISABLED_FIELDS = 'disabledFields'; - public const METADATA_FIELD = 'metadataImport'; - /** * (non-PHPdoc) * @see tao_models_classes_import_ImportHandler::getLabel() @@ -86,7 +83,13 @@ public function import($class, $form, $userId = null) helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::LONG); $report = taoQtiTest_models_classes_QtiTestService::singleton() - ->importMultipleTests($class, $uploadedFile, false, null, $form); + ->importMultipleTests( + $class, + $uploadedFile, + false, + $form[TestImportForm::ITEM_CLASS_DESTINATION_FIELD] ?? null, + $form + ); helpers_TimeOutHelper::reset(); @@ -108,7 +111,12 @@ public function getTaskParameters(tao_helpers_form_Form $importForm) return [ 'uploaded_file' => $file->getPrefix(), // because of Async, we need the full path of the uploaded file - TestImportForm::METADATA_FORM_ELEMENT_NAME => $importForm->getValue('metadata'), + TestImportForm::METADATA_FORM_ELEMENT_NAME => $importForm->getValue( + TestImportForm::METADATA_FORM_ELEMENT_NAME + ), + TestImportForm::ITEM_CLASS_DESTINATION_FIELD => $importForm->getValue( + TestImportForm::ITEM_CLASS_DESTINATION_FIELD + ) ]; } @@ -121,7 +129,8 @@ private function getFormOptions(): array { $options = []; if (!$this->getFeatureFlagChecker()->isEnabled(MetadataLomService::FEATURE_FLAG)) { - $options[self::DISABLED_FIELDS] = [self::METADATA_FIELD]; + $options[TestImportForm::DISABLED_FIELDS][] = TestImportForm::METADATA_FIELD; + $options[TestImportForm::DISABLED_FIELDS][] = TestImportForm::ITEM_CLASS_DESTINATION_FIELD; } return $options; } diff --git a/models/classes/import/class.TestImportForm.php b/models/classes/import/class.TestImportForm.php index 04e3b88ce..9a1387b03 100755 --- a/models/classes/import/class.TestImportForm.php +++ b/models/classes/import/class.TestImportForm.php @@ -19,6 +19,7 @@ * (under the project TAO-TRANSFER); * 2009-2012 (update and modification) Public Research Centre Henri Tudor * (under the project TAO-SUSTAIN & TAO-DEV); + * 2024 (update and modification) Open Assessment Technologies SA */ /** @@ -31,7 +32,12 @@ */ class taoQtiTest_models_classes_import_TestImportForm extends tao_helpers_form_FormContainer { + public const FORM_NAME = 'export'; public const METADATA_FORM_ELEMENT_NAME = 'metadata'; + public const DISABLED_FIELDS = 'disabledFields'; + + public const ITEM_CLASS_DESTINATION_FIELD = 'itemClassDestination'; + public const METADATA_FIELD = 'metadataImport'; /** * (non-PHPdoc) @@ -39,7 +45,7 @@ class taoQtiTest_models_classes_import_TestImportForm extends tao_helpers_form_F */ public function initForm() { - $this->form = new tao_helpers_form_xhtml_Form('export'); + $this->form = new tao_helpers_form_xhtml_Form(self::FORM_NAME); $this->form->setDecorators([ 'element' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div']), @@ -58,7 +64,6 @@ public function initForm() . __('Import') . '' ); - $this->form->setActions([$submitElt], 'bottom'); } @@ -107,24 +112,26 @@ public function initElements() ); $this->addMetadataImportElement(); + $this->addItemDestinationPlacementComponent(); $qtiSentElt = tao_helpers_form_FormFactory::getElement('import_sent_qti', 'Hidden'); $qtiSentElt->setValue(1); $this->form->addElement($qtiSentElt); } - private function isMetadataDisabled(): bool + private function isFieldDisabled(string $filedName): bool { - return isset($this->options[taoQtiTest_models_classes_import_TestImport::DISABLED_FIELDS]) && - in_array( - taoQtiTest_models_classes_import_TestImport::METADATA_FIELD, - $this->options[taoQtiTest_models_classes_import_TestImport::DISABLED_FIELDS] - ); + return isset($this->options[self::DISABLED_FIELDS]) + && in_array($filedName, $this->options[self::DISABLED_FIELDS]); } - private function addMetadataImportElement() + private function addMetadataImportElement(): void { - if (!$this->isMetadataDisabled()) { - $metadataImport = tao_helpers_form_FormFactory::getElement(self::METADATA_FORM_ELEMENT_NAME, 'Checkbox'); + if (!$this->isFieldDisabled(self::METADATA_FIELD)) { + $metadataImport = tao_helpers_form_FormFactory::getElement( + self::METADATA_FORM_ELEMENT_NAME, + 'Checkbox' + ); + $metadataImport->setOptions([self::METADATA_FORM_ELEMENT_NAME => __('QTI metadata as properties')]); $metadataImport->setDescription(__('Import')); $metadataImport->setLevel(1); @@ -132,4 +139,20 @@ private function addMetadataImportElement() $this->form->addToGroup('file', self::METADATA_FORM_ELEMENT_NAME); } } + + private function addItemDestinationPlacementComponent(): void + { + if (!$this->isFieldDisabled(self::ITEM_CLASS_DESTINATION_FIELD)) { + $selectElt = tao_helpers_form_FormFactory::getElement('selectelt', 'Free'); + $selectElt->setValue('
'); + + $itemClassDestination = tao_helpers_form_FormFactory::getElement( + self::ITEM_CLASS_DESTINATION_FIELD, + 'Hidden' + ); + + $this->form->addElement($itemClassDestination); + $this->form->addElement($selectElt); + } + } } diff --git a/models/classes/metadata/MetadataServiceProvider.php b/models/classes/metadata/MetadataServiceProvider.php index c252528ef..0abb494a2 100644 --- a/models/classes/metadata/MetadataServiceProvider.php +++ b/models/classes/metadata/MetadataServiceProvider.php @@ -25,6 +25,7 @@ use oat\generis\model\data\Ontology; use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface; use oat\generis\model\GenerisRdf; +use oat\generis\model\WidgetRdf; use oat\taoQtiItem\model\import\ChecksumGenerator; use oat\taoQtiTest\models\classes\metadata\metaMetadata\PropertyMapper; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; @@ -46,7 +47,8 @@ public function __invoke(ContainerConfigurator $configurator): void 'label' => RDFS_LABEL, 'domain' => RDFS_DOMAIN, 'alias' => GenerisRdf::PROPERTY_ALIAS, - 'multiple' => GenerisRdf::PROPERTY_MULTIPLE + 'multiple' => GenerisRdf::PROPERTY_MULTIPLE, + 'widget' => WidgetRdf::PROPERTY_WIDGET ] ]);