Skip to content

Commit b917ccb

Browse files
authored
Merge pull request #455 from jjrom/develop
Compute first level counts both for catalogs and collections
2 parents a5b235d + ed91fb2 commit b917ccb

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

app/resto/core/RestoConstants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RestoConstants
2020
// [IMPORTANT] Starting resto 7.x, default routes are defined in RestoRouter class
2121

2222
// resto version
23-
const VERSION = '9.0.0-RC18';
23+
const VERSION = '9.0.0-RC19';
2424

2525
/* ============================================================
2626
* NEVER EVER TOUCH THESE VALUES

app/resto/core/api/STACAPI.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,17 @@ private function getRootCatalogLinks($params)
15941594
'q' => $params['q'] ?? null
15951595
), $this->context->core['baseUrl'], false);
15961596

1597+
// Then compute subcatalogs for counts
1598+
for ($i = 0, $ii = count($catalogs); $i < $ii; $i++) {
1599+
$subCatalogs = $this->catalogsFunctions->getCatalogs(array(
1600+
'id' => $catalogs[$i]['id']
1601+
), $this->context->core['baseUrl'], true);
1602+
for ($j = 0, $jj = count($subCatalogs); $j < $jj; $j++) {
1603+
if ($subCatalogs[$j]['id'] === $catalogs[$i]['id']) {
1604+
$catalogs[$i] = $subCatalogs[$j];
1605+
}
1606+
}
1607+
}
15971608
for ($i = 0, $ii = count($catalogs); $i < $ii; $i++) {
15981609

15991610
// Returns only catalogs with count >= minMatch

app/resto/core/dbfunctions/CatalogsFunctions.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function getCatalogs($params, $baseUrl, $withChilds)
151151
/*
152152
* Recursively add child collection counters to catalog counters
153153
*/
154-
return $this->onTheFlyUpdateCountersWithCollection($catalogs, $params['id'] ?? null, $baseUrl);
154+
return $this->onTheFlyUpdateCountersWithCollection($catalogs, $baseUrl);
155155

156156
}
157157

@@ -589,7 +589,7 @@ public function getSummaries($types, $baseUrl)
589589
'collection' => array(
590590
array(
591591
'const' => $_collectionId,
592-
'count' => $catalogs[$i]['counters']['collections'][$_collectionId] ?? 0
592+
'count' => $catalogs[$i]['counters']['total'] ?? 0
593593
)
594594
)
595595
);
@@ -788,10 +788,9 @@ private function getCleanLinks($catalog, $userid, $context) {
788788
* to the input catalog
789789
*
790790
* @param array $catalogs
791-
* @param string $catalogId
792791
* @param string $baseUrl
793792
*/
794-
private function onTheFlyUpdateCountersWithCollection($catalogs, $catalogId, $baseUrl)
793+
private function onTheFlyUpdateCountersWithCollection($catalogs, $baseUrl)
795794
{
796795

797796
$collections = array();
@@ -814,7 +813,7 @@ private function onTheFlyUpdateCountersWithCollection($catalogs, $catalogId, $ba
814813
$catalogsUpdated = array();
815814
for ($i = 0, $ii = count($catalogs); $i < $ii; $i++)
816815
{
817-
$catalogsUpdated[] = $this->computeCountersSum($catalogs[$i], $catalogs, $collections);
816+
$catalogsUpdated[] = $this->computeCountersSum($catalogs[$i], $catalogs, $collections, $baseUrl);
818817
}
819818

820819
return $catalogsUpdated;
@@ -827,12 +826,14 @@ private function onTheFlyUpdateCountersWithCollection($catalogs, $catalogId, $ba
827826
* @param array $catalogs
828827
* @param array $collections
829828
*/
830-
private function computeCountersSum($parentCatalog, $catalogs, $collections) {
829+
private function computeCountersSum($parentCatalog, $catalogs, $collections, $baseUrl) {
831830

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

834833
// Iterate over all catalog entries
835-
foreach ($catalogs as $catalog) {
834+
for ($k = 0, $kk = count($catalogs); $k < $kk; $k++) {
835+
836+
$catalog = $catalogs[$k];
836837

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

0 commit comments

Comments
 (0)