Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/oat-sa/tao-core into fea…
Browse files Browse the repository at this point in the history
…ture/adf-1794/advanced-search-support
  • Loading branch information
shpran committed Nov 12, 2024
2 parents a0756d4 + 23e0517 commit ff5e27f
Show file tree
Hide file tree
Showing 62 changed files with 2,251 additions and 357 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"oat-sa/jig": "~0.2",
"oat-sa/composer-npm-bridge": "~0.4.2||dev-master",
"oat-sa/oatbox-extension-installer": "~1.1||dev-master",
"oat-sa/generis": ">=15.36.4",
"oat-sa/generis": ">=15.39.0",
"composer/package-versions-deprecated": "^1.11",
"paragonie/random_compat": "^2.0",
"phpdocumentor/reflection-docblock": "^5.2",
Expand Down
6 changes: 4 additions & 2 deletions manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use oat\tao\model\featureVisibility\FeatureVisibilityServiceProvider;
use oat\tao\model\form\DataProvider\FormDataProviderServiceProvider;
use oat\tao\model\form\ServiceProvider\FormServiceProvider as TaoFormServiceProvider;
use oat\tao\model\IdentifierGenerator\ServiceProvider\IdentifierGeneratorServiceProvider;
use oat\tao\model\import\ServiceProvider\ImportServiceProvider;
use oat\tao\model\LanguageServiceProvider;
use oat\tao\model\listener\PropertyServiceProvider;
Expand Down Expand Up @@ -361,9 +362,9 @@
],
'constants' => [
#TAO version number
'TAO_VERSION' => '2024.11 LTS',
'TAO_VERSION' => '2024.12',
#TAO version label
'TAO_VERSION_NAME' => '2024.11 LTS',
'TAO_VERSION_NAME' => '2024.12',
#the name to display
'PRODUCT_NAME' => 'TAO',
#TAO release status, use to add specific footer to TAO, available alpha, beta, demo, stable
Expand Down Expand Up @@ -423,6 +424,7 @@
DynamicConfigServiceProvider::class,
TranslationServiceProvider::class,
TaoFormServiceProvider::class,
IdentifierGeneratorServiceProvider::class,
],
'middlewares' => [
MiddlewareConfig::class,
Expand Down
30 changes: 30 additions & 0 deletions migrations/Version202411111300522234_tao.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace oat\tao\migrations;

use Doctrine\DBAL\Schema\Schema;
use oat\tao\scripts\tools\migrations\AbstractMigration;
use oat\tao\scripts\update\OntologyUpdater;

/**
* phpcs:disable Squiz.Classes.ValidClassName
*/
final class Version202411111300522234_tao extends AbstractMigration
{
public function getDescription(): string
{
return 'Sync models';
}

public function up(Schema $schema): void
{
OntologyUpdater::syncModels();
}

public function down(Schema $schema): void
{
OntologyUpdater::syncModels();
}
}
2 changes: 2 additions & 0 deletions models/classes/GenerisServiceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ public function bindProperties(core_kernel_classes_Resource $instance, $properti
}

/**
* @deprecated Use `oat\tao\model\resources\Service\InstanceCopier::transfer()` instead for Items/Tests/Assets
*
* duplicate a resource
*
* @access public
Expand Down
31 changes: 26 additions & 5 deletions models/classes/GenerisTreeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,8 @@ private function getQueryBuilder($class, $propertyFilter, $options)
$queryBuilder = $search->query();
$search->setLanguage($queryBuilder, \common_session_SessionManager::getSession()->getDataLanguage());
$query = $search->searchType($queryBuilder, $class->getUri(), $options['recursive']);
$featureFlagChecker = $this->getFeatureFlagChecker();

if (
!$featureFlagChecker->isEnabled('FEATURE_FLAG_TRANSLATION_DEVELOPER_MODE') &&
$featureFlagChecker->isEnabled('FEATURE_FLAG_TRANSLATION_ENABLED')
) {
if ($this->mustFilterTranslations($class)) {
$query->addCriterion(
TaoOntology::PROPERTY_TRANSLATION_TYPE,
SupportedOperatorHelper::IN,
Expand Down Expand Up @@ -352,6 +348,31 @@ private function getSubClasses(core_kernel_classes_Class $class)
return $result;
}

private function mustFilterTranslations(core_kernel_classes_Class $class): bool
{
$featureFlagChecker = $this->getFeatureFlagChecker();

if ($featureFlagChecker->isEnabled('FEATURE_FLAG_TRANSLATION_DEVELOPER_MODE')) {
return false;
}

if (!$featureFlagChecker->isEnabled('FEATURE_FLAG_TRANSLATION_ENABLED')) {
return false;
}

$parentClassIds = $class->getParentClassesIds();
$mainClass = array_pop($parentClassIds);

return in_array(
$mainClass,
[
TaoOntology::CLASS_URI_ITEM,
TaoOntology::CLASS_URI_TEST
],
true
);
}

private function getFeatureFlagChecker(): FeatureFlagCheckerInterface
{
return ServiceManager::getServiceManager()->getContainer()->get(FeatureFlagChecker::class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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\tao\model\IdentifierGenerator\Generator;

interface IdentifierGeneratorInterface
{
public const OPTION_RESOURCE = 'resource';
public const OPTION_RESOURCE_ID = 'resourceId';

public function generate(array $options = []): string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?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\tao\model\IdentifierGenerator\Generator;

use core_kernel_classes_Resource;
use InvalidArgumentException;
use oat\generis\model\data\Ontology;

class IdentifierGeneratorProxy implements IdentifierGeneratorInterface
{
private Ontology $ontology;
private array $idGenerators = [];

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

public function addIdentifierGenerator(IdentifierGeneratorInterface $idGenerator, string $resourceType): void
{
if (isset($this->idGenerators[$resourceType])) {
throw new InvalidArgumentException(
sprintf(
'Id generator for type %s already defined',
$resourceType
)
);
}

$this->idGenerators[$resourceType] = $idGenerator;
}

public function generate(array $options = []): string
{
$this->assertRequiredOptionsProvided($options);
$resourceType = $this->getResourceType($options);

return $this->getIdGenerator($resourceType)->generate($options);
}

private function assertRequiredOptionsProvided(array $options): void
{
if (!isset($options[self::OPTION_RESOURCE]) && !isset($options[self::OPTION_RESOURCE_ID])) {
throw new InvalidArgumentException(
sprintf(
'Option "%s" or "%s" is required to generate ID',
self::OPTION_RESOURCE,
self::OPTION_RESOURCE_ID
)
);
}
}

private function getResourceType(array $options): string
{
if (
isset($options[self::OPTION_RESOURCE])
&& !$options[self::OPTION_RESOURCE] instanceof core_kernel_classes_Resource
) {
throw new InvalidArgumentException(
sprintf(
'Option "%s" must be an instance of %s',
self::OPTION_RESOURCE,
core_kernel_classes_Resource::class
)
);
}

$resource = $options[self::OPTION_RESOURCE] ?? $this->ontology->getResource($options[self::OPTION_RESOURCE_ID]);

return $resource->getRootId();
}

private function getIdGenerator(string $resourceType): IdentifierGeneratorInterface
{
if (!isset($this->idGenerators[$resourceType])) {
throw new InvalidArgumentException(
sprintf(
'ID generator for resource type %s not defined',
$resourceType
)
);
}

return $this->idGenerators[$resourceType];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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\tao\model\IdentifierGenerator\Generator;

class NumericIdentifierGenerator implements IdentifierGeneratorInterface
{
/**
* This will return 9 digits numeric identifier base on time and random number
* i.e: 123456789
*/
public function generate(array $options = []): string
{
return substr((string) floor(time() / 1000), 0, 7)
. substr((string) floor(mt_rand(10, 100)), 0, 2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace oat\tao\model\IdentifierGenerator\ServiceProvider;

use oat\generis\model\data\Ontology;
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use oat\tao\model\IdentifierGenerator\Generator\IdentifierGeneratorProxy;
use oat\tao\model\IdentifierGenerator\Generator\NumericIdentifierGenerator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

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

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

$services->set(NumericIdentifierGenerator::class, NumericIdentifierGenerator::class);

$services
->set(IdentifierGeneratorProxy::class, IdentifierGeneratorProxy::class)
->public()
->args([
service(Ontology::SERVICE_ID),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

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

use core_kernel_classes_Literal;
use core_kernel_classes_Resource;
use oat\generis\model\data\Ontology;
use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
use oat\tao\model\form\Modifier\AbstractFormModifier;
Expand Down Expand Up @@ -70,18 +72,21 @@ private function getTranslationElementsToRemove(tao_helpers_form_Form $form): ar
$this->ontology->getProperty(TaoOntology::PROPERTY_TRANSLATION_TYPE)
);
$isTranslationTypeEmpty = empty($translationType);
$translationTypeUri = $translationType instanceof core_kernel_classes_Literal
? (string) $translationType
: ($translationType instanceof core_kernel_classes_Resource ? $translationType->getUri() : null);

if (
$isTranslationTypeEmpty
|| $translationType->getUri() === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_ORIGINAL
|| $translationTypeUri === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_ORIGINAL
) {
$elementsToRemove[] = TaoOntology::PROPERTY_TRANSLATION_PROGRESS;
$elementsToRemove[] = TaoOntology::PROPERTY_TRANSLATION_ORIGINAL_RESOURCE_URI;
}

if (
$isTranslationTypeEmpty
|| $translationType->getUri() === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_TRANSLATION
|| $translationTypeUri === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_TRANSLATION
) {
$elementsToRemove[] = TaoOntology::PROPERTY_TRANSLATION_STATUS;
}
Expand Down
Loading

0 comments on commit ff5e27f

Please sign in to comment.