Skip to content

Commit

Permalink
Merge pull request #455 from jjrom/develop
Browse files Browse the repository at this point in the history
Compute first level counts both for catalogs and collections
  • Loading branch information
jjrom authored Oct 18, 2024
2 parents a5b235d + ed91fb2 commit b917ccb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/resto/core/RestoConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RestoConstants
// [IMPORTANT] Starting resto 7.x, default routes are defined in RestoRouter class

// resto version
const VERSION = '9.0.0-RC18';
const VERSION = '9.0.0-RC19';

/* ============================================================
* NEVER EVER TOUCH THESE VALUES
Expand Down
11 changes: 11 additions & 0 deletions app/resto/core/api/STACAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,17 @@ private function getRootCatalogLinks($params)
'q' => $params['q'] ?? null
), $this->context->core['baseUrl'], false);

// Then compute subcatalogs for counts
for ($i = 0, $ii = count($catalogs); $i < $ii; $i++) {
$subCatalogs = $this->catalogsFunctions->getCatalogs(array(
'id' => $catalogs[$i]['id']
), $this->context->core['baseUrl'], true);
for ($j = 0, $jj = count($subCatalogs); $j < $jj; $j++) {
if ($subCatalogs[$j]['id'] === $catalogs[$i]['id']) {
$catalogs[$i] = $subCatalogs[$j];
}
}
}
for ($i = 0, $ii = count($catalogs); $i < $ii; $i++) {

// Returns only catalogs with count >= minMatch
Expand Down
17 changes: 9 additions & 8 deletions app/resto/core/dbfunctions/CatalogsFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function getCatalogs($params, $baseUrl, $withChilds)
/*
* Recursively add child collection counters to catalog counters
*/
return $this->onTheFlyUpdateCountersWithCollection($catalogs, $params['id'] ?? null, $baseUrl);
return $this->onTheFlyUpdateCountersWithCollection($catalogs, $baseUrl);

}

Expand Down Expand Up @@ -589,7 +589,7 @@ public function getSummaries($types, $baseUrl)
'collection' => array(
array(
'const' => $_collectionId,
'count' => $catalogs[$i]['counters']['collections'][$_collectionId] ?? 0
'count' => $catalogs[$i]['counters']['total'] ?? 0
)
)
);
Expand Down Expand Up @@ -788,10 +788,9 @@ private function getCleanLinks($catalog, $userid, $context) {
* to the input catalog
*
* @param array $catalogs
* @param string $catalogId
* @param string $baseUrl
*/
private function onTheFlyUpdateCountersWithCollection($catalogs, $catalogId, $baseUrl)
private function onTheFlyUpdateCountersWithCollection($catalogs, $baseUrl)
{

$collections = array();
Expand All @@ -814,7 +813,7 @@ private function onTheFlyUpdateCountersWithCollection($catalogs, $catalogId, $ba
$catalogsUpdated = array();
for ($i = 0, $ii = count($catalogs); $i < $ii; $i++)
{
$catalogsUpdated[] = $this->computeCountersSum($catalogs[$i], $catalogs, $collections);
$catalogsUpdated[] = $this->computeCountersSum($catalogs[$i], $catalogs, $collections, $baseUrl);
}

return $catalogsUpdated;
Expand All @@ -827,12 +826,14 @@ private function onTheFlyUpdateCountersWithCollection($catalogs, $catalogId, $ba
* @param array $catalogs
* @param array $collections
*/
private function computeCountersSum($parentCatalog, $catalogs, $collections) {
private function computeCountersSum($parentCatalog, $catalogs, $collections, $baseUrl) {

$parentCatalogId = $parentCatalog['id'] . '/';

// Iterate over all catalog entries
foreach ($catalogs as $catalog) {
for ($k = 0, $kk = count($catalogs); $k < $kk; $k++) {

$catalog = $catalogs[$k];

// Check if the catalog's path starts with the parent path
if ( !str_starts_with($catalog['id'], $parentCatalogId) ) {
Expand All @@ -854,7 +855,7 @@ private function computeCountersSum($parentCatalog, $catalogs, $collections) {
if ($parentCatalog['links'][$j]['rel'] === 'child') {
$exploded2 = explode('/', substr($parentCatalog['links'][$j]['href'], strlen($baseUrl . RestoRouter::ROUTE_TO_COLLECTIONS) + 1));
if (count($exploded2) === 1 && $exploded2[0] === $exploded[0]) {
$parentCatalog['links'][$j]['matched'] = $collectionCounters[$exploded[0]];
$parentCatalog['links'][$j]['matched'] = $parentCatalog['counters']['collections'][$exploded[0]];
if ( isset($collections[$exploded[0]]['title']) ) {
$parentCatalog['links'][$i]['title'] = $collections[$exploded[0]]['title'];
}
Expand Down

0 comments on commit b917ccb

Please sign in to comment.