Skip to content

Commit

Permalink
Merge branch 'release-12.2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jun 4, 2024
2 parents 703cdad + 6034f9a commit a97c4c4
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 1 deletion.
16 changes: 16 additions & 0 deletions actions/class.SaSItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

use oat\generis\model\OntologyRdfs;
use oat\taoItems\model\search\ItemClassListService;
use tao_helpers_form_FormContainer as FormContainer;

/**
Expand Down Expand Up @@ -158,11 +159,26 @@ public function viewItem()
$this->setView('view.tpl');
}

public function getItemClasses()
{
$this->returnJson(
$this->getItemClassListService()->getList(
$this->getGetParameter('q'),
$this->getGetParameter('page')
)
);
}

/**
* Load the standalone mode
*/
protected function loadStandaloneMode()
{
tao_helpers_Context::load('STANDALONE_MODE');
}

private function getItemClassListService(): ItemClassListService
{
return $this->getServiceManager()->getContainer()->get(ItemClassListService::class);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"require": {
"oat-sa/oatbox-extension-installer": "~1.1||dev-master",
"oat-sa/generis": ">=15.24",
"oat-sa/generis": ">=15.36.1",
"oat-sa/tao-core": ">=53.0.0",
"oat-sa/extension-tao-backoffice": ">=6.0.0"
},
Expand Down
8 changes: 8 additions & 0 deletions manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

use oat\tao\model\user\TaoRoles;
use oat\taoBackOffice\controller\Lists;
use oat\taoItems\model\search\ItemClassListService;
use oat\taoItems\model\search\ItemClassListServiceProvider;
use oat\taoItems\model\user\TaoItemsRoles;
use oat\tao\model\accessControl\func\AccessRule;
use oat\taoItems\scripts\install\RegisterNpmPaths;
Expand Down Expand Up @@ -200,6 +202,11 @@
TaoItemsRoles::ITEM_IMPORTER,
['ext' => 'taoItems', 'mod' => 'ItemImport', 'act' => 'index'],
],
[
AccessRule::GRANT,
TaoItemsRoles::ITEM_IMPORTER,
['ext' => 'taoItems', 'mod' => 'RestItem', 'act' => 'getItemClasses'],
],
[
AccessRule::GRANT,
TaoItemsRoles::ITEM_DELETER,
Expand Down Expand Up @@ -247,5 +254,6 @@
],
'containerServiceProviders' => [
CopierServiceProvider::class,
ItemClassListServiceProvider::class
],
];
99 changes: 99 additions & 0 deletions models/classes/search/ItemClassListService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?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\taoItems\model\search;

use core_kernel_classes_Resource;
use oat\generis\model\data\Ontology;
use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService;
use oat\generis\model\OntologyRdfs;
use oat\tao\model\TaoOntology;

class ItemClassListService
{
private const CLASS_LIST_LIMIT = 10;
private ComplexSearchService $complexSearchService;
private Ontology $ontology;
public function __construct(ComplexSearchService $complexSearchService, Ontology $ontology)
{
$this->complexSearchService = $complexSearchService;
$this->ontology = $ontology;
}

public function getList(string $query, string $page): array
{
$page = (int) $page;
$root = $this->ontology->getClass(TaoOntology::CLASS_URI_ITEM);
$basicQueryParameters = [
'recursive' => true,
'like' => true,
'onlyClass' => true
];

$query = [
OntologyRdfs::RDFS_LABEL => $query
];

$searchResult = $root->searchInstances(
$query,
$this->getDynamicQueryParameters($page, $basicQueryParameters)
);

$result['total'] = $root->countInstances($query, $basicQueryParameters) ?? 0;
$result['items'] = [];

foreach ($searchResult as $row) {
$result['items'][] = [
'id' => $row->getUri(),
'uri' => $row->getUri(),
'text' => $row->getLabel(),
'path' => $this->getListElementText($row)
];
}
return $result;
}

private function getListElementText(core_kernel_classes_Resource $row): string
{
$displayText = '';
foreach ($row->getParentClassesIds() as $parent) {
if ($parent !== TaoOntology::CLASS_URI_ITEM) {
$displayText .= $this->ontology->getResource($parent)->getLabel();
$displayText .= '/';
}
}

$displayText .= $row->getLabel();
return $displayText;
}

private function getDynamicQueryParameters(int $page, array $basicQueryParameters)
{
return array_merge(
$basicQueryParameters,
[
'limit' => self::CLASS_LIST_LIMIT,
'offset' => ($page - 1) * self::CLASS_LIST_LIMIT
]
);
}
}
44 changes: 44 additions & 0 deletions models/classes/search/ItemClassListServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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\taoItems\model\search;

use oat\generis\model\data\Ontology;
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

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

class ItemClassListServiceProvider implements ContainerServiceProviderInterface
{
public function __invoke(ContainerConfigurator $configurator): void
{
$services = $configurator->services();
$services->set(ItemClassListService::class, ItemClassListService::class)
->args([
service(ComplexSearchService::SERVICE_ID),
service(Ontology::SERVICE_ID),
])
->public();
}
}

0 comments on commit a97c4c4

Please sign in to comment.