12 private array $seriesList = [];
13 private array $columns;
19 $this->combiner = $combiner;
30 if (!isset($this->seriesList[$seriesId]))
32 $this->seriesList[$seriesId] = $stores;
36 $this->seriesList[$seriesId] = $this->summarizeStores(...$this->seriesList[$seriesId], ...$stores);
40 private function summarizeStores(
StoreInfo ...$stores): array
45 foreach ($stores as $store)
47 if (isset($outputStores[$store->getStoreId()]))
49 $outputStores[$store->getStoreId()] = $this->combiner->summarizeStores($outputStores[$store->getStoreId()], $store);
53 $outputStores[$store->getStoreId()] = $store;
57 return array_values($outputStores);
69 $combinedColumn = array_reduce($this->getCalculatedColumns(),
static function ($carry, $item) use (&$combinedTitle, $maxLabelLength) {
70 foreach ($item as $series => $value)
72 if ($series !==
'TITLE')
74 $carry[$series] += $value;
78 if ($combinedTitle ===
'' || (mb_strlen($combinedTitle) < $maxLabelLength + 2))
80 $combinedTitle .=
', ';
81 $combinedTitle .= $item[
'TITLE'];
85 }, array_fill_keys(array_keys($this->seriesList), 0.0));
87 $combinedTitle = mb_substr($combinedTitle, 2);
88 $combinedColumn[
'TITLE'] = $combinedTitle;
90 return $combinedColumn;
97 public function getCalculatedColumns(): array
99 if (isset($this->columns))
101 return $this->columns;
106 foreach ($this->seriesList as $seriesId => $series)
109 foreach ($series as $store)
111 $storeId = $store->getStoreId();
112 if (!isset($columns[$storeId]))
114 $columns[$storeId] = array_fill_keys(array_keys($this->seriesList), 0.0);
115 $columns[$storeId][
'TITLE'] = $store->getStoreName();
118 $columns[$storeId][$seriesId] += $store->getCalculatedSumPrice();
122 $this->columns = $columns;
123 return $this->columns;
132 return count($this->getCalculatedColumns());