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

AutoSuggest.php « Dao « CustomDimensions « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6b6c35c3b58af04560edc55c24093714ecf4e36a (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\Dao;

use Piwik\API\Request;
use Piwik\Common;
use Piwik\DataTable;
use Piwik\Date;
use Piwik\Db;
use Piwik\Plugins\CustomDimensions\Archiver;

class AutoSuggest
{

    /**
     * @param array $dimension
     * @param int $idSite
     * @param int $maxValuesToReturn
     * @return array
     */
    public function getMostUsedActionDimensionValues($dimension, $idSite, $maxValuesToReturn)
    {
        // we use first day from the month so it only needs to aggregate archives of two/three months and no weeks etc
        $date = Date::now()->subMonth(2)->setDay(1)->toString() . ',today';
        /** @var DataTable $report */
        $report = Request::processRequest('CustomDimensions.getCustomDimension', array(
            'idDimension' => $dimension['idcustomdimension'],
            'idSite' => $idSite,
            'filter_offset' => 0,
            'filter_limit' => $maxValuesToReturn,
            'period' => 'range',
            'date' => $date,
            'disable_queued_filters' => 1
        ), array());

        $labels = $report->getColumn('label');
        $notDefinedKey = array_search(Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED, $labels);
        if ($notDefinedKey !== false) {
            unset($labels[$notDefinedKey]);
            $labels = array_values($labels);
        }

        return $labels;
    }

}