-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/oat-sa/tao-core into fea…
…ture/adf-1794/advanced-search-support
- Loading branch information
Showing
62 changed files
with
2,251 additions
and
357 deletions.
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
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
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,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(); | ||
} | ||
} |
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
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
31 changes: 31 additions & 0 deletions
31
models/classes/IdentifierGenerator/Generator/IdentifierGeneratorInterface.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,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; | ||
} |
107 changes: 107 additions & 0 deletions
107
models/classes/IdentifierGenerator/Generator/IdentifierGeneratorProxy.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,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]; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
models/classes/IdentifierGenerator/Generator/NumericIdentifierGenerator.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 | ||
|
||
/** | ||
* 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); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
models/classes/IdentifierGenerator/ServiceProvider/IdentifierGeneratorServiceProvider.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,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), | ||
]); | ||
} | ||
} |
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
Oops, something went wrong.