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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\Contents;
use Piwik\Archive;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Metrics;
use Piwik\Piwik;
use Piwik\Plugins\Contents\Archiver;
/**
* API for plugin Contents
*
* @method static \Piwik\Plugins\Contents\API getInstance()
*/
class API extends \Piwik\Plugin\API
{
public function getContentNames($idSite, $period, $date, $segment = false, $idSubtable = false)
{
return $this->getDataTable(__FUNCTION__, $idSite, $period, $date, $segment, false, $idSubtable);
}
public function getContentPieces($idSite, $period, $date, $segment = false, $idSubtable = false)
{
return $this->getDataTable(__FUNCTION__, $idSite, $period, $date, $segment, false, $idSubtable);
}
private function getDataTable($name, $idSite, $period, $date, $segment, $expanded, $idSubtable)
{
Piwik::checkUserHasViewAccess($idSite);
$recordName = Dimensions::getRecordNameForAction($name);
$dataTable = Archive::getDataTableFromArchive($recordName, $idSite, $period, $date, $segment, $expanded, $idSubtable);
if (empty($idSubtable)) {
$dataTable->filter('AddSegmentValue', array(function ($label) {
if ($label === Archiver::CONTENT_PIECE_NOT_SET) {
return false;
}
return $label;
}));
}
$this->filterDataTable($dataTable);
return $dataTable;
}
/**
* @param DataTable $dataTable
*/
private function filterDataTable($dataTable)
{
$dataTable->queueFilter('ReplaceColumnNames');
$dataTable->queueFilter('ReplaceSummaryRowLabel');
$dataTable->filter(function (DataTable $table) {
$row = $table->getRowFromLabel(Archiver::CONTENT_PIECE_NOT_SET);
if ($row) {
$row->setColumn('label', Piwik::translate('General_NotDefined', Piwik::translate('Contents_ContentPiece')));
}
foreach ($table->getRows() as $row) {
if ($row->getMetadata('contentTarget') === Archiver::CONTENT_TARGET_NOT_SET) {
$row->setMetadata('contentTarget', '');
}
}
});
}
}
|