Skip to content

Commit ff5e27f

Browse files
committed
Merge branch 'develop' of https://github.com/oat-sa/tao-core into feature/adf-1794/advanced-search-support
2 parents a0756d4 + 23e0517 commit ff5e27f

File tree

62 files changed

+2251
-357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2251
-357
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"oat-sa/jig": "~0.2",
6868
"oat-sa/composer-npm-bridge": "~0.4.2||dev-master",
6969
"oat-sa/oatbox-extension-installer": "~1.1||dev-master",
70-
"oat-sa/generis": ">=15.36.4",
70+
"oat-sa/generis": ">=15.39.0",
7171
"composer/package-versions-deprecated": "^1.11",
7272
"paragonie/random_compat": "^2.0",
7373
"phpdocumentor/reflection-docblock": "^5.2",

manifest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use oat\tao\model\featureVisibility\FeatureVisibilityServiceProvider;
4545
use oat\tao\model\form\DataProvider\FormDataProviderServiceProvider;
4646
use oat\tao\model\form\ServiceProvider\FormServiceProvider as TaoFormServiceProvider;
47+
use oat\tao\model\IdentifierGenerator\ServiceProvider\IdentifierGeneratorServiceProvider;
4748
use oat\tao\model\import\ServiceProvider\ImportServiceProvider;
4849
use oat\tao\model\LanguageServiceProvider;
4950
use oat\tao\model\listener\PropertyServiceProvider;
@@ -361,9 +362,9 @@
361362
],
362363
'constants' => [
363364
#TAO version number
364-
'TAO_VERSION' => '2024.11 LTS',
365+
'TAO_VERSION' => '2024.12',
365366
#TAO version label
366-
'TAO_VERSION_NAME' => '2024.11 LTS',
367+
'TAO_VERSION_NAME' => '2024.12',
367368
#the name to display
368369
'PRODUCT_NAME' => 'TAO',
369370
#TAO release status, use to add specific footer to TAO, available alpha, beta, demo, stable
@@ -423,6 +424,7 @@
423424
DynamicConfigServiceProvider::class,
424425
TranslationServiceProvider::class,
425426
TaoFormServiceProvider::class,
427+
IdentifierGeneratorServiceProvider::class,
426428
],
427429
'middlewares' => [
428430
MiddlewareConfig::class,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace oat\tao\migrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use oat\tao\scripts\tools\migrations\AbstractMigration;
9+
use oat\tao\scripts\update\OntologyUpdater;
10+
11+
/**
12+
* phpcs:disable Squiz.Classes.ValidClassName
13+
*/
14+
final class Version202411111300522234_tao extends AbstractMigration
15+
{
16+
public function getDescription(): string
17+
{
18+
return 'Sync models';
19+
}
20+
21+
public function up(Schema $schema): void
22+
{
23+
OntologyUpdater::syncModels();
24+
}
25+
26+
public function down(Schema $schema): void
27+
{
28+
OntologyUpdater::syncModels();
29+
}
30+
}

models/classes/GenerisServiceTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ public function bindProperties(core_kernel_classes_Resource $instance, $properti
165165
}
166166

167167
/**
168+
* @deprecated Use `oat\tao\model\resources\Service\InstanceCopier::transfer()` instead for Items/Tests/Assets
169+
*
168170
* duplicate a resource
169171
*
170172
* @access public

models/classes/GenerisTreeFactory.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,8 @@ private function getQueryBuilder($class, $propertyFilter, $options)
277277
$queryBuilder = $search->query();
278278
$search->setLanguage($queryBuilder, \common_session_SessionManager::getSession()->getDataLanguage());
279279
$query = $search->searchType($queryBuilder, $class->getUri(), $options['recursive']);
280-
$featureFlagChecker = $this->getFeatureFlagChecker();
281280

282-
if (
283-
!$featureFlagChecker->isEnabled('FEATURE_FLAG_TRANSLATION_DEVELOPER_MODE') &&
284-
$featureFlagChecker->isEnabled('FEATURE_FLAG_TRANSLATION_ENABLED')
285-
) {
281+
if ($this->mustFilterTranslations($class)) {
286282
$query->addCriterion(
287283
TaoOntology::PROPERTY_TRANSLATION_TYPE,
288284
SupportedOperatorHelper::IN,
@@ -352,6 +348,31 @@ private function getSubClasses(core_kernel_classes_Class $class)
352348
return $result;
353349
}
354350

351+
private function mustFilterTranslations(core_kernel_classes_Class $class): bool
352+
{
353+
$featureFlagChecker = $this->getFeatureFlagChecker();
354+
355+
if ($featureFlagChecker->isEnabled('FEATURE_FLAG_TRANSLATION_DEVELOPER_MODE')) {
356+
return false;
357+
}
358+
359+
if (!$featureFlagChecker->isEnabled('FEATURE_FLAG_TRANSLATION_ENABLED')) {
360+
return false;
361+
}
362+
363+
$parentClassIds = $class->getParentClassesIds();
364+
$mainClass = array_pop($parentClassIds);
365+
366+
return in_array(
367+
$mainClass,
368+
[
369+
TaoOntology::CLASS_URI_ITEM,
370+
TaoOntology::CLASS_URI_TEST
371+
],
372+
true
373+
);
374+
}
375+
355376
private function getFeatureFlagChecker(): FeatureFlagCheckerInterface
356377
{
357378
return ServiceManager::getServiceManager()->getContainer()->get(FeatureFlagChecker::class);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; under version 2
7+
* of the License (non-upgradable).
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*
18+
* Copyright (c) 2024 (original work) Open Assessment Technologies SA.
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace oat\tao\model\IdentifierGenerator\Generator;
24+
25+
interface IdentifierGeneratorInterface
26+
{
27+
public const OPTION_RESOURCE = 'resource';
28+
public const OPTION_RESOURCE_ID = 'resourceId';
29+
30+
public function generate(array $options = []): string;
31+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
/**
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; under version 2
7+
* of the License (non-upgradable).
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*
18+
* Copyright (c) 2024 (original work) Open Assessment Technologies SA.
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace oat\tao\model\IdentifierGenerator\Generator;
24+
25+
use core_kernel_classes_Resource;
26+
use InvalidArgumentException;
27+
use oat\generis\model\data\Ontology;
28+
29+
class IdentifierGeneratorProxy implements IdentifierGeneratorInterface
30+
{
31+
private Ontology $ontology;
32+
private array $idGenerators = [];
33+
34+
public function __construct(Ontology $ontology)
35+
{
36+
$this->ontology = $ontology;
37+
}
38+
39+
public function addIdentifierGenerator(IdentifierGeneratorInterface $idGenerator, string $resourceType): void
40+
{
41+
if (isset($this->idGenerators[$resourceType])) {
42+
throw new InvalidArgumentException(
43+
sprintf(
44+
'Id generator for type %s already defined',
45+
$resourceType
46+
)
47+
);
48+
}
49+
50+
$this->idGenerators[$resourceType] = $idGenerator;
51+
}
52+
53+
public function generate(array $options = []): string
54+
{
55+
$this->assertRequiredOptionsProvided($options);
56+
$resourceType = $this->getResourceType($options);
57+
58+
return $this->getIdGenerator($resourceType)->generate($options);
59+
}
60+
61+
private function assertRequiredOptionsProvided(array $options): void
62+
{
63+
if (!isset($options[self::OPTION_RESOURCE]) && !isset($options[self::OPTION_RESOURCE_ID])) {
64+
throw new InvalidArgumentException(
65+
sprintf(
66+
'Option "%s" or "%s" is required to generate ID',
67+
self::OPTION_RESOURCE,
68+
self::OPTION_RESOURCE_ID
69+
)
70+
);
71+
}
72+
}
73+
74+
private function getResourceType(array $options): string
75+
{
76+
if (
77+
isset($options[self::OPTION_RESOURCE])
78+
&& !$options[self::OPTION_RESOURCE] instanceof core_kernel_classes_Resource
79+
) {
80+
throw new InvalidArgumentException(
81+
sprintf(
82+
'Option "%s" must be an instance of %s',
83+
self::OPTION_RESOURCE,
84+
core_kernel_classes_Resource::class
85+
)
86+
);
87+
}
88+
89+
$resource = $options[self::OPTION_RESOURCE] ?? $this->ontology->getResource($options[self::OPTION_RESOURCE_ID]);
90+
91+
return $resource->getRootId();
92+
}
93+
94+
private function getIdGenerator(string $resourceType): IdentifierGeneratorInterface
95+
{
96+
if (!isset($this->idGenerators[$resourceType])) {
97+
throw new InvalidArgumentException(
98+
sprintf(
99+
'ID generator for resource type %s not defined',
100+
$resourceType
101+
)
102+
);
103+
}
104+
105+
return $this->idGenerators[$resourceType];
106+
}
107+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; under version 2
7+
* of the License (non-upgradable).
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*
18+
* Copyright (c) 2024 (original work) Open Assessment Technologies SA.
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace oat\tao\model\IdentifierGenerator\Generator;
24+
25+
class NumericIdentifierGenerator implements IdentifierGeneratorInterface
26+
{
27+
/**
28+
* This will return 9 digits numeric identifier base on time and random number
29+
* i.e: 123456789
30+
*/
31+
public function generate(array $options = []): string
32+
{
33+
return substr((string) floor(time() / 1000), 0, 7)
34+
. substr((string) floor(mt_rand(10, 100)), 0, 2);
35+
}
36+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace oat\tao\model\IdentifierGenerator\ServiceProvider;
4+
5+
use oat\generis\model\data\Ontology;
6+
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
7+
use oat\tao\model\featureFlag\FeatureFlagChecker;
8+
use oat\tao\model\IdentifierGenerator\Generator\IdentifierGeneratorProxy;
9+
use oat\tao\model\IdentifierGenerator\Generator\NumericIdentifierGenerator;
10+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
11+
12+
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
13+
14+
class IdentifierGeneratorServiceProvider implements ContainerServiceProviderInterface
15+
{
16+
public function __invoke(ContainerConfigurator $configurator): void
17+
{
18+
$services = $configurator->services();
19+
20+
$services->set(NumericIdentifierGenerator::class, NumericIdentifierGenerator::class);
21+
22+
$services
23+
->set(IdentifierGeneratorProxy::class, IdentifierGeneratorProxy::class)
24+
->public()
25+
->args([
26+
service(Ontology::SERVICE_ID),
27+
]);
28+
}
29+
}

models/classes/Translation/Form/Modifier/TranslationFormModifier.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
namespace oat\tao\model\Translation\Form\Modifier;
2424

25+
use core_kernel_classes_Literal;
26+
use core_kernel_classes_Resource;
2527
use oat\generis\model\data\Ontology;
2628
use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
2729
use oat\tao\model\form\Modifier\AbstractFormModifier;
@@ -70,18 +72,21 @@ private function getTranslationElementsToRemove(tao_helpers_form_Form $form): ar
7072
$this->ontology->getProperty(TaoOntology::PROPERTY_TRANSLATION_TYPE)
7173
);
7274
$isTranslationTypeEmpty = empty($translationType);
75+
$translationTypeUri = $translationType instanceof core_kernel_classes_Literal
76+
? (string) $translationType
77+
: ($translationType instanceof core_kernel_classes_Resource ? $translationType->getUri() : null);
7378

7479
if (
7580
$isTranslationTypeEmpty
76-
|| $translationType->getUri() === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_ORIGINAL
81+
|| $translationTypeUri === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_ORIGINAL
7782
) {
7883
$elementsToRemove[] = TaoOntology::PROPERTY_TRANSLATION_PROGRESS;
7984
$elementsToRemove[] = TaoOntology::PROPERTY_TRANSLATION_ORIGINAL_RESOURCE_URI;
8085
}
8186

8287
if (
8388
$isTranslationTypeEmpty
84-
|| $translationType->getUri() === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_TRANSLATION
89+
|| $translationTypeUri === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_TRANSLATION
8590
) {
8691
$elementsToRemove[] = TaoOntology::PROPERTY_TRANSLATION_STATUS;
8792
}

0 commit comments

Comments
 (0)