-
Notifications
You must be signed in to change notification settings - Fork 0
/
API.php
78 lines (72 loc) · 2.72 KB
/
API.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* The SDG Single Digital Gateway plugin for Matomo.
*
* Copyright (C) 2024 Digitalist Open Cloud <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Piwik\Plugins\SDG;
use Piwik\Archive;
use Piwik\DataTable;
use Piwik\DataTable\Map;
use Piwik\Metrics;
use Piwik\Plugin\API as PiwikAPI;
/**
* API for plugin SDGWebStatistics
*
* @method static \Piwik\Plugins\SDGWebStatistics\API getInstance()
*/
class API extends PiwikAPI
{
/**
* @param int $idSite
* @param string $period
* @param string $date
* @param bool|string $segment
* @return DataTable
*/
public function getSingleDigitalGateway($idSite, $period, $date, $segment = false)
{
$archive = Archive::build($idSite, $period, $date, $segment);
$statisticsArchiveData = $archive->getDataTable(Archiver::SDG_STATITICS);
$statisticsDataTables = [];
if ($statisticsArchiveData instanceof Map) {
$statisticsDataTables = $statisticsArchiveData->getDataTables();
} else {
$statisticsDataTables[] = $statisticsArchiveData;
}
$dataTable = new DataTable();
foreach ($statisticsDataTables as $statisticsDataTable) {
foreach ($statisticsDataTable->getRows() as $row) {
$dataTable->addRowFromSimpleArray([
'url' => $row->getMetadata(Archiver::PAGE_URL_INDEX),
'pageTitle' => $row->getMetadata(Archiver::PAGE_TITLE_INDEX),
'country' => $row->getMetadata(Archiver::COUNTRY_CODE_INDEX),
'deviceType' => $row->getMetadata(Archiver::DEVICE_TYPE_INDEX),
'nb_visits' => (string)$row->getColumn(Metrics::INDEX_NB_VISITS),
]);
}
}
$dataTable->queueFilter(
'ColumnCallbackReplace',
['country', 'Piwik\Plugins\UserCountry\countryTranslate']
);
$dataTable->queueFilter(
'ColumnCallbackReplace',
['deviceType', 'Piwik\Plugins\DevicesDetection\getDeviceTypeLabel']
);
return $dataTable;
}
}