Skip to content

Commit

Permalink
Merge pull request #2472 from oat-sa/fix/AUT-3654/import-test-with-it…
Browse files Browse the repository at this point in the history
…em-class-search

Fix/aut 3654/import test with item class search
  • Loading branch information
bartlomiejmarszal authored Jun 4, 2024
2 parents 74d7a79 + 15d4997 commit b5a0eab
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 18 deletions.
21 changes: 15 additions & 6 deletions models/classes/import/class.TestImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();

Expand All @@ -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
)
];
}

Expand All @@ -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;
}
Expand Down
45 changes: 34 additions & 11 deletions models/classes/import/class.TestImportForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand All @@ -31,15 +32,20 @@
*/
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)
* @see tao_helpers_form_FormContainer::initForm()
*/
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']),
Expand All @@ -58,7 +64,6 @@ public function initForm()
. __('Import') . '</a>'
);


$this->form->setActions([$submitElt], 'bottom');
}

Expand Down Expand Up @@ -107,29 +112,47 @@ 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);
$this->form->addElement($metadataImport);
$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('<div class="item-select-container"></div>');

$itemClassDestination = tao_helpers_form_FormFactory::getElement(
self::ITEM_CLASS_DESTINATION_FIELD,
'Hidden'
);

$this->form->addElement($itemClassDestination);
$this->form->addElement($selectElt);
}
}
}
4 changes: 3 additions & 1 deletion models/classes/metadata/MetadataServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
]
]);

Expand Down

0 comments on commit b5a0eab

Please sign in to comment.