Skip to content

Commit

Permalink
fix: enable itemClassDestination component by feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomiejmarszal committed May 22, 2024
1 parent 987dc18 commit 25b0d91
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
12 changes: 5 additions & 7 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 @@ -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
);

Expand All @@ -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
)
];
}
Expand All @@ -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;
}
Expand Down
43 changes: 26 additions & 17 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 @@ -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)
Expand All @@ -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('<div class="item-select-container"></div>');

$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(
'<a href="#" class="form-submitter btn-success small"><span class="icon-import"></span> '
. __('Import') . '</a>'
);


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

Expand Down Expand Up @@ -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'));
Expand All @@ -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('<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);
}

}
}

0 comments on commit 25b0d91

Please sign in to comment.