MCPcopy Create free account
hub / github.com/Rello/analytics / aggregateRows

Method aggregateRows

lib/Controller/DatasourceController.php:726–778  ·  view source on GitHub ↗
(array $data)

Source from the content-addressed store, hash-verified

724 }
725
726 private function aggregateRows(array $data): array {
727 if (!isset($data['data']) || !is_array($data['data']) || empty($data['data'])) {
728 return $data;
729 }
730
731 $aggregatedData = [];
732 $groupDimensions = [];
733
734 foreach ($data['data'] as $row) {
735 if (!is_array($row) || empty($row)) {
736 continue;
737 }
738
739 $row = array_values($row);
740 $value = array_pop($row);
741 // Keep the existing string normalization without using dimension content as a delimiter.
742 $dimensions = array_map('strval', $row);
743 $key = serialize($dimensions);
744 $groupDimensions[$key] = $dimensions;
745
746 if (!isset($aggregatedData[$key])) {
747 $aggregatedData[$key] = 0;
748 }
749
750 if (is_numeric($value)) {
751 $aggregatedData[$key] += $value;
752 } elseif ($value !== null && $value !== '') {
753 $aggregatedData[$key] = $value;
754 }
755 }
756
757 if (empty($aggregatedData)) {
758 $data['data'] = [];
759 return $data;
760 }
761
762 $result = [];
763 foreach ($aggregatedData as $aKey => $aValue) {
764 if ($groupDimensions[$aKey] === []) {
765 if (!isset($data['header']) || !is_array($data['header'])) {
766 $data['header'] = [''];
767 } else {
768 array_unshift($data['header'], '');
769 }
770 $result[] = [$this->l10n->t('Total'), $aValue];
771 } else {
772 $components = $groupDimensions[$aKey];
773 $result[] = array_merge($components, [$aValue]);
774 }
775 }
776 $data['data'] = $result;
777 return $data;
778 }
779
780 private function encodeFilterOptions(array $options): string {
781 if (empty($options)) {

Callers 1

aggregateDataMethod · 0.95

Calls 1

tMethod · 0.45

Tested by

no test coverage detected