forked from johsin18/DevicePixelRatioMatomoPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
API.php
67 lines (62 loc) · 2 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
<?php
/**
* Matomo - free/libre analytics platform
*
* @link http://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\DevicePixelRatio;
use Piwik\Archive;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Piwik;
/**
* API for plugin DevicePixelRatio
*
* @method static \Piwik\Plugins\DevicePixelRatio\API getInstance()
*/
class API extends \Piwik\Plugin\API
{
/**
* @param int $idSite
* @param string $period
* @param string $date
* @param bool|string $segment
* @return DataTable
*/
public function getDevicePixelRatio($idSite, $period, $date, $segment = false)
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Archive::build($idSite, $period, $date, $segment);
/** @var DataTable|DataTable\Map $dataTable */
$dataTable = $archive->getDataTable(Archiver::DEVICEPIXELRATIO_ARCHIVE_RECORD);
$dataTable->queueFilter('ReplaceColumnNames');
$dataTable->queueFilter('ReplaceSummaryRowLabel');
$dataTable->filter('Piwik\Plugins\DevicePixelRatio\DataTable\Filter\ReplaceNullByUnknown');
$dataTable->filter('AddSegmentValue');
return $dataTable;
}
/**
* @param int $idSite
* @param string $period
* @param string $date
* @param bool|string $segment
* @return DataTable
*/
public function getDevicePixelRatioRanges($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDevicePixelRatio($idSite, $period, $date, $segment);
$dataTable->filter('GroupBy', array(
'label',
function ($label) {
if (!is_numeric($label))
return $label;
$f = floatval($label);
$c = number_format(ceil($f), 2);
return Piwik::translate("DevicePixelRatio_upToX", $c);
}
));
return $dataTable;
}
}