-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
models/classes/Form/Modifier/EditTranslationInstanceFormModifier.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace oat\taoQtiTest\models\Form\Modifier; | ||
|
||
use core_kernel_classes_Resource; | ||
use oat\generis\model\data\Ontology; | ||
use oat\tao\model\form\Modifier\FormModifierInterface; | ||
use oat\tao\model\TaoOntology; | ||
use tao_helpers_form_Form as Form; | ||
use tao_helpers_Uri; | ||
use taoQtiTest_models_classes_QtiTestService; | ||
|
||
class EditTranslationInstanceFormModifier implements FormModifierInterface | ||
{ | ||
public const ID = 'tao_qti_test.form_modifier.edit_translation_instance'; | ||
|
||
private Ontology $ontology; | ||
private taoQtiTest_models_classes_QtiTestService $testQtiService; | ||
|
||
public function __construct(Ontology $ontology, taoQtiTest_models_classes_QtiTestService $testQtiService) | ||
{ | ||
$this->ontology = $ontology; | ||
$this->testQtiService = $testQtiService; | ||
} | ||
|
||
public function supports(Form $form, array $options = []): bool | ||
{ | ||
$instanceUri = $form->getValue(self::FORM_INSTANCE_URI); | ||
|
||
if (!$instanceUri) { | ||
return false; | ||
} | ||
|
||
$instance = $this->ontology->getResource($instanceUri); | ||
|
||
// @TODO Check if FF for translation enabled | ||
return $instance->isInstanceOf($this->ontology->getClass(TaoOntology::CLASS_URI_TEST)); | ||
} | ||
|
||
public function modify(Form $form, array $options = []): void | ||
{ | ||
$uniqueIdElement = $form->getElement(tao_helpers_Uri::encode(TaoOntology::PROPERTY_UNIQUE_IDENTIFIER)); | ||
|
||
if (!$uniqueIdElement) { | ||
return; | ||
} | ||
|
||
$instance = $this->ontology->getResource($form->getValue(self::FORM_INSTANCE_URI)); | ||
$jsonTest = $this->testQtiService->getJsonTest($instance); | ||
$id = json_decode($jsonTest, true)['identifier'] ?? null; | ||
|
||
if ($id) { | ||
$uniqueIdElement->setValue($id); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
models/classes/Form/ServiceProvider/FormServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace oat\taoQtiTest\models\Form\ServiceProvider; | ||
|
||
use oat\generis\model\data\Ontology; | ||
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface; | ||
use oat\tao\model\form\Modifier\FormModifierManager; | ||
use oat\taoQtiTest\models\Form\Modifier\EditTranslationInstanceFormModifier; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
use taoQtiTest_models_classes_QtiTestService; | ||
use function Symfony\Component\DependencyInjection\Loader\Configurator\service; | ||
|
||
class FormServiceProvider implements ContainerServiceProviderInterface | ||
{ | ||
public function __invoke(ContainerConfigurator $configurator): void | ||
{ | ||
$services = $configurator->services(); | ||
|
||
$services | ||
->set(EditTranslationInstanceFormModifier::class, EditTranslationInstanceFormModifier::class) | ||
->args([ | ||
service(Ontology::SERVICE_ID), | ||
service(taoQtiTest_models_classes_QtiTestService::class), | ||
]); | ||
|
||
$formModifierManager = $services->get(FormModifierManager::class); | ||
$formModifierManager | ||
->call( | ||
'add', | ||
[ | ||
service(EditTranslationInstanceFormModifier::class), | ||
EditTranslationInstanceFormModifier::ID, | ||
] | ||
); | ||
} | ||
} |