Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DataArray.php « CustomDimensions « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c5c8565b5d34a94210efe7ee49ea25dd8d4a270d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 */
namespace Piwik\Plugins\CustomDimensions;


/**
 * The DataArray is a data structure used to aggregate datasets,
 * ie. sum arrays made of rows made of columns,
 * data from the logs is stored in a DataArray before being converted in a DataTable
 *
 */

class DataArray extends \Piwik\DataArray
{
    private static $actionMetrics = array();

    public function setActionMetricsIds($metrics)
    {
        self::$actionMetrics = $metrics;
    }

    protected static function makeEmptyActionRow()
    {
        $metrics = array();

        foreach (self::$actionMetrics as $key) {
            $metrics[$key] = 0;
        }

        return $metrics;
    }

    protected function doSumActionsMetrics($newRowToAdd, &$oldRowToUpdate)
    {
        foreach (self::$actionMetrics as $actionMetric) {
            $oldRowToUpdate[$actionMetric] += $newRowToAdd[$actionMetric];
        }
    }

    public function sumMetricsActionCustomDimensionsPivot($parentLabel, $label, $row)
    {
        if (!isset($this->dataTwoLevels[$parentLabel][$label])) {
            $this->dataTwoLevels[$parentLabel][$label] = $this->makeEmptyActionRow();
        }
        $this->doSumActionsMetrics($row, $this->dataTwoLevels[$parentLabel][$label]);
    }
}