@@ -151,7 +151,7 @@ public function getCatalogs($params, $baseUrl, $withChilds)
151
151
/*
152
152
* Recursively add child collection counters to catalog counters
153
153
*/
154
- return $ this ->onTheFlyUpdateCountersWithCollection ($ catalogs , $ params [ ' id ' ] ?? null , $ baseUrl );
154
+ return $ this ->onTheFlyUpdateCountersWithCollection ($ catalogs , $ baseUrl );
155
155
156
156
}
157
157
@@ -589,7 +589,7 @@ public function getSummaries($types, $baseUrl)
589
589
'collection ' => array (
590
590
array (
591
591
'const ' => $ _collectionId ,
592
- 'count ' => $ catalogs [$ i ]['counters ' ]['collections ' ][ $ _collectionId ] ?? 0
592
+ 'count ' => $ catalogs [$ i ]['counters ' ]['total ' ] ?? 0
593
593
)
594
594
)
595
595
);
@@ -788,10 +788,9 @@ private function getCleanLinks($catalog, $userid, $context) {
788
788
* to the input catalog
789
789
*
790
790
* @param array $catalogs
791
- * @param string $catalogId
792
791
* @param string $baseUrl
793
792
*/
794
- private function onTheFlyUpdateCountersWithCollection ($ catalogs , $ catalogId , $ baseUrl )
793
+ private function onTheFlyUpdateCountersWithCollection ($ catalogs , $ baseUrl )
795
794
{
796
795
797
796
$ collections = array ();
@@ -814,7 +813,7 @@ private function onTheFlyUpdateCountersWithCollection($catalogs, $catalogId, $ba
814
813
$ catalogsUpdated = array ();
815
814
for ($ i = 0 , $ ii = count ($ catalogs ); $ i < $ ii ; $ i ++)
816
815
{
817
- $ catalogsUpdated [] = $ this ->computeCountersSum ($ catalogs [$ i ], $ catalogs , $ collections );
816
+ $ catalogsUpdated [] = $ this ->computeCountersSum ($ catalogs [$ i ], $ catalogs , $ collections, $ baseUrl );
818
817
}
819
818
820
819
return $ catalogsUpdated ;
@@ -827,12 +826,14 @@ private function onTheFlyUpdateCountersWithCollection($catalogs, $catalogId, $ba
827
826
* @param array $catalogs
828
827
* @param array $collections
829
828
*/
830
- private function computeCountersSum ($ parentCatalog , $ catalogs , $ collections ) {
829
+ private function computeCountersSum ($ parentCatalog , $ catalogs , $ collections, $ baseUrl ) {
831
830
832
831
$ parentCatalogId = $ parentCatalog ['id ' ] . '/ ' ;
833
832
834
833
// 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 ];
836
837
837
838
// Check if the catalog's path starts with the parent path
838
839
if ( !str_starts_with ($ catalog ['id ' ], $ parentCatalogId ) ) {
@@ -854,7 +855,7 @@ private function computeCountersSum($parentCatalog, $catalogs, $collections) {
854
855
if ($ parentCatalog ['links ' ][$ j ]['rel ' ] === 'child ' ) {
855
856
$ exploded2 = explode ('/ ' , substr ($ parentCatalog ['links ' ][$ j ]['href ' ], strlen ($ baseUrl . RestoRouter::ROUTE_TO_COLLECTIONS ) + 1 ));
856
857
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 ]];
858
859
if ( isset ($ collections [$ exploded [0 ]]['title ' ]) ) {
859
860
$ parentCatalog ['links ' ][$ i ]['title ' ] = $ collections [$ exploded [0 ]]['title ' ];
860
861
}
0 commit comments