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

Method aggregateRows

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

Source from the content-addressed store, hash-verified

657 }
658
659 private function aggregateRows(array $data): array {
660 if (!isset($data['data']) || !is_array($data['data']) || empty($data['data'])) {
661 return $data;
662 }
663
664 $aggregatedData = [];
665 $groupDimensions = [];
666
667 foreach ($data['data'] as $row) {
668 if (!is_array($row) || empty($row)) {
669 continue;
670 }
671
672 $row = array_values($row);
673 $value = array_pop($row);
674 // Keep the existing string normalization without using dimension content as a delimiter.
675 $dimensions = array_map('strval', $row);
676 $key = serialize($dimensions);
677 $groupDimensions[$key] = $dimensions;
678
679 if (!isset($aggregatedData[$key])) {
680 $aggregatedData[$key] = 0;
681 }
682
683 if (is_numeric($value)) {
684 $aggregatedData[$key] += $value;
685 } elseif ($value !== null && $value !== '') {
686 $aggregatedData[$key] = $value;
687 }
688 }
689
690 if (empty($aggregatedData)) {
691 $data['data'] = [];
692 return $data;
693 }
694
695 $result = [];
696 foreach ($aggregatedData as $aKey => $aValue) {
697 if ($groupDimensions[$aKey] === []) {
698 if (!isset($data['header']) || !is_array($data['header'])) {
699 $data['header'] = [''];
700 } else {
701 array_unshift($data['header'], '');
702 }
703 $result[] = [$this->l10n->t('Total'), $aValue];
704 } else {
705 $components = $groupDimensions[$aKey];
706 $result[] = array_merge($components, [$aValue]);
707 }
708 }
709 $data['data'] = $result;
710 return $data;
711 }
712
713 private function encodeFilterOptions(array $options): string {
714 if (empty($options)) {

Callers 1

aggregateDataMethod · 0.95

Calls 1

tMethod · 0.45

Tested by

no test coverage detected