diff --git a/app/resto/core/RestoConstants.php b/app/resto/core/RestoConstants.php index 91aed449..25362a58 100644 --- a/app/resto/core/RestoConstants.php +++ b/app/resto/core/RestoConstants.php @@ -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 diff --git a/app/resto/core/api/STACAPI.php b/app/resto/core/api/STACAPI.php index cb676562..efe5d818 100644 --- a/app/resto/core/api/STACAPI.php +++ b/app/resto/core/api/STACAPI.php @@ -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 diff --git a/app/resto/core/dbfunctions/CatalogsFunctions.php b/app/resto/core/dbfunctions/CatalogsFunctions.php index bb4b52f5..ef8654a1 100755 --- a/app/resto/core/dbfunctions/CatalogsFunctions.php +++ b/app/resto/core/dbfunctions/CatalogsFunctions.php @@ -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); } @@ -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 ) ) ); @@ -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(); @@ -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; @@ -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) ) { @@ -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']; }