Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: provide new form modifier, remove type from item properties #478

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions actions/class.Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use oat\tao\model\controller\SignedFormInstance;
use oat\tao\model\resources\Service\ClassDeleter;
use oat\tao\model\routing\AnnotationReader\security;
use oat\taoTests\models\Form\Modifier\FormModifierProxy;
use oat\taoTests\models\Translation\Form\Modifier\TranslationFormModifierProxy;
use tao_helpers_form_FormContainer as FormContainer;
use oat\generis\model\resource\Service\ResourceDeleter;
Expand Down Expand Up @@ -116,6 +117,7 @@ public function editTest()
],
],
FormContainer::FORM_MODIFIERS => [
FormModifierProxy::class,
TranslationFormModifierProxy::class,
],
]
Expand Down
2 changes: 2 additions & 0 deletions manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use oat\tao\model\accessControl\func\AccessRule;
use oat\tao\model\user\TaoRoles;
use oat\taoTests\models\Copier\CopierServiceProvider;
use oat\taoTests\models\Form\ServiceProvider\FormServiceProvider;
use oat\taoTests\models\Translation\ServiceProvider\TranslationServiceProvider;
use oat\taoTests\models\user\TaoTestsRoles;
use oat\taoTests\scripts\install\RegisterFrontendPaths;
Expand Down Expand Up @@ -134,5 +135,6 @@
'containerServiceProviders' => [
CopierServiceProvider::class,
TranslationServiceProvider::class,
FormServiceProvider::class,
],
];
29 changes: 29 additions & 0 deletions models/classes/Form/Modifier/FormModifierProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA.
*/

declare(strict_types=1);

namespace oat\taoTests\models\Form\Modifier;

use oat\tao\model\form\Modifier\AbstractFormModifier;

final class FormModifierProxy extends AbstractFormModifier
{
}
51 changes: 51 additions & 0 deletions models/classes/Form/ServiceProvider/FormServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA.
*/

declare(strict_types=1);

namespace oat\taoTests\models\Form\ServiceProvider;

use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\tao\model\form\Modifier\UniqueIdFormModifier;
use oat\taoTests\models\Form\Modifier\FormModifierProxy;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

class FormServiceProvider implements ContainerServiceProviderInterface
{
public function __invoke(ContainerConfigurator $configurator): void
{
$services = $configurator->services();

$services
->set(FormModifierProxy::class, FormModifierProxy::class)
->public();

$services
->get(FormModifierProxy::class)
->call(
'addModifier',
[
service(UniqueIdFormModifier::class),
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

namespace oat\taoTests\models\Translation\Form\Modifier;

use oat\generis\model\data\Ontology;
use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
use oat\tao\model\form\Modifier\AbstractFormModifier;
use oat\tao\model\TaoOntology;
Expand All @@ -32,10 +33,12 @@
class TranslationFormModifier extends AbstractFormModifier
{
private FeatureFlagCheckerInterface $featureFlagChecker;
private Ontology $ontology;

public function __construct(FeatureFlagCheckerInterface $featureFlagChecker)
public function __construct(FeatureFlagCheckerInterface $featureFlagChecker, Ontology $ontology)
{
$this->featureFlagChecker = $featureFlagChecker;
$this->ontology = $ontology;
}

public function modify(Form $form, array $options = []): void
Expand All @@ -44,11 +47,15 @@ public function modify(Form $form, array $options = []): void
$form->removeElement(tao_helpers_Uri::encode(TaoTestOntology::PROPERTY_TRANSLATION_COMPLETION));
}

$translationTypeValue = $form->getValue(tao_helpers_Uri::encode(TaoOntology::PROPERTY_TRANSLATION_TYPE));
$instance = $this->ontology->getResource($form->getValue('uri'));

$translationType = $instance->getOnePropertyValue(
$this->ontology->getProperty(TaoOntology::PROPERTY_TRANSLATION_TYPE)
);

if (
empty($translationTypeValue)
|| $translationTypeValue === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_ORIGINAL
empty($translationType)
|| $translationType->getUri() === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_ORIGINAL
) {
$form->removeElement(tao_helpers_Uri::encode(TaoTestOntology::PROPERTY_TRANSLATION_COMPLETION));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function __invoke(ContainerConfigurator $configurator): void
->set(TranslationFormModifier::class, TranslationFormModifier::class)
->args([
service(FeatureFlagChecker::class),
service(Ontology::SERVICE_ID),
]);

$services
Expand Down
5 changes: 1 addition & 4 deletions models/ontology/taotest.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#Language">
<rdfs:domain rdf:resource="http://www.tao.lu/Ontologies/TAOTest.rdf#Test"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#TranslationType">
<rdfs:domain rdf:resource="http://www.tao.lu/Ontologies/TAOTest.rdf#Test"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#TranslationStatus">
<rdfs:domain rdf:resource="http://www.tao.lu/Ontologies/TAOTest.rdf#Test"/>
</rdf:Description>
Expand All @@ -133,7 +130,7 @@
<rdfs:label xml:lang="en-US"><![CDATA[Translation Completion]]></rdfs:label>
<rdfs:comment xml:lang="en-US"><![CDATA[Translation Completion]]></rdfs:comment>
<rdfs:range rdf:resource="http://www.tao.lu/Ontologies/TAOTest.rdf#TranslationCompletionStatuses"/>
<widget:widget rdf:resource="http://www.tao.lu/datatypes/WidgetDefinitions.rdf#ComboBox"/>
<widget:widget rdf:resource="http://www.tao.lu/datatypes/WidgetDefinitions.rdf#Readonly"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shpran this cannot be read only. This will be changed in the Item/Test form

<tao:TAOGUIOrder><![CDATA[2005]]></tao:TAOGUIOrder>
</rdf:Description>
</rdf:RDF>