From 1fdc99dfeff94d9d56bb2287934828f4fde9cd07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Fri, 17 May 2024 16:46:25 +0200 Subject: [PATCH 1/6] fix: add searchbar --- models/classes/import/class.TestImportForm.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/models/classes/import/class.TestImportForm.php b/models/classes/import/class.TestImportForm.php index 04e3b88ce..57acc3fdc 100755 --- a/models/classes/import/class.TestImportForm.php +++ b/models/classes/import/class.TestImportForm.php @@ -31,6 +31,7 @@ */ class taoQtiTest_models_classes_import_TestImportForm extends tao_helpers_form_FormContainer { + public const FORM_NAME = 'export'; public const METADATA_FORM_ELEMENT_NAME = 'metadata'; /** @@ -39,7 +40,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']), @@ -52,6 +53,10 @@ public function initForm() 'actions-top' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-toolbar']) ]); + $selectElt = \tao_helpers_form_FormFactory::getElement('selectelt', 'Free'); + $selectElt->setValue('
'); + $this->form->addElement($selectElt); + $submitElt = tao_helpers_form_FormFactory::getElement('import', 'Free'); $submitElt->setValue( ' ' From 987dc1877c4f1ab9ab62482df5ad31cbcaae18f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Wed, 22 May 2024 10:19:59 +0200 Subject: [PATCH 2/6] fix: pass input TestImportForm::ITEM_CLASS_DESTINATION to form and handle it --- models/classes/import/class.TestImport.php | 13 +++++++++++-- models/classes/import/class.TestImportForm.php | 6 +++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/models/classes/import/class.TestImport.php b/models/classes/import/class.TestImport.php index 418f9d509..72cc276d7 100755 --- a/models/classes/import/class.TestImport.php +++ b/models/classes/import/class.TestImport.php @@ -86,7 +86,11 @@ 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] ?? null, + $form + ); helpers_TimeOutHelper::reset(); @@ -108,7 +112,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 => $importForm->getValue( + TestImportForm::ITEM_CLASS_DESTINATION + ) ]; } diff --git a/models/classes/import/class.TestImportForm.php b/models/classes/import/class.TestImportForm.php index 57acc3fdc..5aad9c766 100755 --- a/models/classes/import/class.TestImportForm.php +++ b/models/classes/import/class.TestImportForm.php @@ -33,6 +33,7 @@ class taoQtiTest_models_classes_import_TestImportForm extends tao_helpers_form_F { public const FORM_NAME = 'export'; public const METADATA_FORM_ELEMENT_NAME = 'metadata'; + public const ITEM_CLASS_DESTINATION = 'itemClassDestination'; /** * (non-PHPdoc) @@ -53,8 +54,11 @@ public function initForm() 'actions-top' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-toolbar']) ]); - $selectElt = \tao_helpers_form_FormFactory::getElement('selectelt', 'Free'); + $selectElt = tao_helpers_form_FormFactory::getElement('selectelt', 'Free'); $selectElt->setValue('
'); + + $itemClassDestination = tao_helpers_form_FormFactory::getElement('itemClassDestination', 'Hidden'); + $this->form->addElement($itemClassDestination); $this->form->addElement($selectElt); $submitElt = tao_helpers_form_FormFactory::getElement('import', 'Free'); From 25b0d91d3750facd0ee668da00009667f6fe369a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Wed, 22 May 2024 10:57:34 +0200 Subject: [PATCH 3/6] fix: enable itemClassDestination component by feature flag --- models/classes/import/class.TestImport.php | 12 +++--- .../classes/import/class.TestImportForm.php | 43 +++++++++++-------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/models/classes/import/class.TestImport.php b/models/classes/import/class.TestImport.php index 72cc276d7..e8d3d4623 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() @@ -88,7 +85,7 @@ public function import($class, $form, $userId = null) $report = taoQtiTest_models_classes_QtiTestService::singleton() ->importMultipleTests($class, $uploadedFile, false, - $form[TestImportForm::ITEM_CLASS_DESTINATION] ?? null, + $form[TestImportForm::ITEM_CLASS_DESTINATION_FIELD] ?? null, $form ); @@ -115,8 +112,8 @@ public function getTaskParameters(tao_helpers_form_Form $importForm) TestImportForm::METADATA_FORM_ELEMENT_NAME => $importForm->getValue( TestImportForm::METADATA_FORM_ELEMENT_NAME ), - TestImportForm::ITEM_CLASS_DESTINATION => $importForm->getValue( - TestImportForm::ITEM_CLASS_DESTINATION + TestImportForm::ITEM_CLASS_DESTINATION_FIELD => $importForm->getValue( + TestImportForm::ITEM_CLASS_DESTINATION_FIELD ) ]; } @@ -130,7 +127,8 @@ private function getFormOptions(): array { $options = []; if (!$this->getFeatureFlagChecker()->isEnabled(MetadataLomService::FEATURE_FLAG)) { - $options[self::DISABLED_FIELDS] = [self::METADATA_FIELD]; + $options[taoQtiTest_models_classes_import_TestImportForm::DISABLED_FIELDS][] = taoQtiTest_models_classes_import_TestImportForm::METADATA_FIELD; + $options[taoQtiTest_models_classes_import_TestImportForm::DISABLED_FIELDS][] = taoQtiTest_models_classes_import_TestImportForm::ITEM_CLASS_DESTINATION_FIELD; } return $options; } diff --git a/models/classes/import/class.TestImportForm.php b/models/classes/import/class.TestImportForm.php index 5aad9c766..3c050f5bb 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 */ /** @@ -33,7 +34,10 @@ class taoQtiTest_models_classes_import_TestImportForm extends tao_helpers_form_F { public const FORM_NAME = 'export'; public const METADATA_FORM_ELEMENT_NAME = 'metadata'; - public const ITEM_CLASS_DESTINATION = 'itemClassDestination'; + public const DISABLED_FIELDS = 'disabledFields'; + + public const ITEM_CLASS_DESTINATION_FIELD = 'itemClassDestination'; + public const METADATA_FIELD = 'metadataImport'; /** * (non-PHPdoc) @@ -54,20 +58,12 @@ public function initForm() 'actions-top' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-toolbar']) ]); - $selectElt = tao_helpers_form_FormFactory::getElement('selectelt', 'Free'); - $selectElt->setValue('
'); - - $itemClassDestination = tao_helpers_form_FormFactory::getElement('itemClassDestination', 'Hidden'); - $this->form->addElement($itemClassDestination); - $this->form->addElement($selectElt); - $submitElt = tao_helpers_form_FormFactory::getElement('import', 'Free'); $submitElt->setValue( '
' . __('Import') . '' ); - $this->form->setActions([$submitElt], 'bottom'); } @@ -116,23 +112,22 @@ 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()) { + 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')); @@ -141,4 +136,18 @@ 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); + } + + } } From 9ca1243b2e62758a378e780e679f7332534ab7bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Wed, 22 May 2024 16:53:11 +0200 Subject: [PATCH 4/6] fix: add widget to service provider --- models/classes/metadata/MetadataServiceProvider.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 ] ]); From 12a07ec2799be73fed1caa366423e5710d9af626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Wed, 22 May 2024 18:25:10 +0200 Subject: [PATCH 5/6] fix: phpcs fix --- models/classes/import/class.TestImport.php | 4 +++- models/classes/import/class.TestImportForm.php | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/classes/import/class.TestImport.php b/models/classes/import/class.TestImport.php index e8d3d4623..c50b72800 100755 --- a/models/classes/import/class.TestImport.php +++ b/models/classes/import/class.TestImport.php @@ -83,7 +83,9 @@ public function import($class, $form, $userId = null) helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::LONG); $report = taoQtiTest_models_classes_QtiTestService::singleton() - ->importMultipleTests($class, $uploadedFile, + ->importMultipleTests( + $class, + $uploadedFile, false, $form[TestImportForm::ITEM_CLASS_DESTINATION_FIELD] ?? null, $form diff --git a/models/classes/import/class.TestImportForm.php b/models/classes/import/class.TestImportForm.php index 3c050f5bb..5c8495ae1 100755 --- a/models/classes/import/class.TestImportForm.php +++ b/models/classes/import/class.TestImportForm.php @@ -122,7 +122,6 @@ private function isFieldDisabled(string $filedName): bool { return isset($this->options[self::DISABLED_FIELDS]) && in_array($filedName, $this->options[self::DISABLED_FIELDS]); - } private function addMetadataImportElement(): void @@ -148,6 +147,5 @@ private function addItemDestinationPlacementComponent(): void $this->form->addElement($itemClassDestination); $this->form->addElement($selectElt); } - } } From 15d499708e829d5afd2ea31bd8ae1a819723743d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Thu, 23 May 2024 15:01:59 +0200 Subject: [PATCH 6/6] fix: code style refactor --- models/classes/import/class.TestImport.php | 4 ++-- models/classes/import/class.TestImportForm.php | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/models/classes/import/class.TestImport.php b/models/classes/import/class.TestImport.php index c50b72800..a24ca295d 100755 --- a/models/classes/import/class.TestImport.php +++ b/models/classes/import/class.TestImport.php @@ -129,8 +129,8 @@ private function getFormOptions(): array { $options = []; if (!$this->getFeatureFlagChecker()->isEnabled(MetadataLomService::FEATURE_FLAG)) { - $options[taoQtiTest_models_classes_import_TestImportForm::DISABLED_FIELDS][] = taoQtiTest_models_classes_import_TestImportForm::METADATA_FIELD; - $options[taoQtiTest_models_classes_import_TestImportForm::DISABLED_FIELDS][] = taoQtiTest_models_classes_import_TestImportForm::ITEM_CLASS_DESTINATION_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 5c8495ae1..9a1387b03 100755 --- a/models/classes/import/class.TestImportForm.php +++ b/models/classes/import/class.TestImportForm.php @@ -127,7 +127,11 @@ private function isFieldDisabled(string $filedName): bool private function addMetadataImportElement(): void { if (!$this->isFieldDisabled(self::METADATA_FIELD)) { - $metadataImport = tao_helpers_form_FormFactory::getElement(self::METADATA_FORM_ELEMENT_NAME, 'Checkbox'); + $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); @@ -142,7 +146,10 @@ private function addItemDestinationPlacementComponent(): void $selectElt = tao_helpers_form_FormFactory::getElement('selectelt', 'Free'); $selectElt->setValue('
'); - $itemClassDestination = tao_helpers_form_FormFactory::getElement(self::ITEM_CLASS_DESTINATION_FIELD, 'Hidden'); + $itemClassDestination = tao_helpers_form_FormFactory::getElement( + self::ITEM_CLASS_DESTINATION_FIELD, + 'Hidden' + ); $this->form->addElement($itemClassDestination); $this->form->addElement($selectElt);