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

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Becker <halfdan@xnorfz.de>2013-04-18 04:03:29 +0400
committerFabian Becker <halfdan@xnorfz.de>2013-04-18 04:03:29 +0400
commit8adee3386257f77afc426f8783c318398dc247be (patch)
tree8a7def7354d9f55d1318f17cbb4cac0378009774 /plugins/API
parente227defdef5b9a9f23c9edd4a5968f5177ceb05b (diff)
parent8e95c379781dd65a97f33f9a58b9f35bcd7c7ac8 (diff)
Merge master
Diffstat (limited to 'plugins/API')
-rw-r--r--plugins/API/API.php112
1 files changed, 80 insertions, 32 deletions
diff --git a/plugins/API/API.php b/plugins/API/API.php
index 90d39d1c0d..96ecbe8af5 100644
--- a/plugins/API/API.php
+++ b/plugins/API/API.php
@@ -584,14 +584,6 @@ class Piwik_API_API
// set metric documentation to default if it's not set
$availableReport['metricsDocumentation'] = $this->getDefaultMetricsDocumentation();
}
-
- // if hide/show columns specified, hide/show metrics & docs
- $availableReport['metrics'] = $this->hideShowMetrics($availableReport['metrics']);
- $availableReport['processedMetrics'] = $this->hideShowMetrics($availableReport['processedMetrics']);
- if (isset($availableReport['metricsDocumentation'])) {
- $availableReport['metricsDocumentation'] =
- $this->hideShowMetrics($availableReport['metricsDocumentation']);
- }
}
// Some plugins need to add custom metrics after all plugins hooked in
@@ -623,6 +615,16 @@ class Piwik_API_API
}
$availableReport['metrics'] = $cleanedMetrics;
+ // if hide/show columns specified, hide/show metrics & docs
+ $availableReport['metrics'] = $this->hideShowMetrics($availableReport['metrics']);
+ if (isset($availableReport['processedMetrics'])) {
+ $availableReport['processedMetrics'] = $this->hideShowMetrics($availableReport['processedMetrics']);
+ }
+ if (isset($availableReport['metricsDocumentation'])) {
+ $availableReport['metricsDocumentation'] =
+ $this->hideShowMetrics($availableReport['metricsDocumentation']);
+ }
+
// Remove array elements that are false (to clean up API output)
foreach ($availableReport as $attributeName => $attributeValue) {
if (empty($attributeValue)) {
@@ -1057,8 +1059,10 @@ class Piwik_API_API
$meta = Piwik_API_API::getInstance()->getReportMetadata($idSite, $period, $date);
foreach ($meta as $reportMeta) {
// scan all *.get reports
- if ($reportMeta['action'] == 'get' && !isset($reportMeta['parameters'])
+ if ($reportMeta['action'] == 'get'
+ && !isset($reportMeta['parameters'])
&& $reportMeta['module'] != 'API'
+ && !empty($reportMeta['metrics'])
) {
$plugin = $reportMeta['module'];
foreach ($reportMeta['metrics'] as $column => $columnTranslation) {
@@ -1175,9 +1179,29 @@ class Piwik_API_API
$labels = array_merge($labels, $table->getColumn('label'));
}
$labels = array_values(array_unique($labels));
+
+ // if the filter_limit query param is set, treat it as a request to limit
+ // the number of labels used
+ $limit = Piwik_Common::getRequestVar('filter_limit', false);
+ if ($limit != false
+ && $limit >= 0
+ ) {
+ $labels = array_slice($labels, 0, $limit);
+ }
+
+ // set label index metadata
+ $labelsToIndex = array_flip($labels);
+ foreach ($dataTable->getArray() as $table) {
+ foreach ($table->getRows() as $row) {
+ $label = $row->getColumn('label');
+ if (isset($labelsToIndex[$label])) {
+ $row->setMetadata('label_index', $labelsToIndex[$label]);
+ }
+ }
+ }
}
- if (count($labels) > 1) {
+ if (count($labels) != 1) {
$data = $this->getMultiRowEvolution(
$dataTable,
$idSite,
@@ -1219,7 +1243,7 @@ class Piwik_API_API
{
$metadata = $this->getRowEvolutionMetaData($idSite, $period, $date, $apiModule, $apiAction, $language, $idGoal);
$metricNames = array_keys($metadata['metrics']);
-
+
$logo = $actualLabel = false;
$urlFound = false;
foreach ($dataTable->getArray() as $date => $subTable) {
@@ -1306,19 +1330,23 @@ class Piwik_API_API
$label = array_map('rawurlencode', $label);
$parameters = array(
- 'method' => $apiModule . '.' . $apiAction,
- 'label' => $label,
- 'idSite' => $idSite,
- 'period' => $period,
- 'date' => $date,
- 'format' => 'original',
- 'serialize' => '0',
- 'segment' => $segment,
- 'idGoal' => $idGoal,
-
- // if more than one label is used, we add empty rows for labels we can't
- // find to ensure we know the order of the rows in the returned data table
- 'labelFilterAddEmptyRows' => count($label) > 1 ? 1 : 0,
+ 'method' => $apiModule . '.' . $apiAction,
+ 'label' => $label,
+ 'idSite' => $idSite,
+ 'period' => $period,
+ 'date' => $date,
+ 'format' => 'original',
+ 'serialize' => '0',
+ 'segment' => $segment,
+ 'idGoal' => $idGoal,
+
+ // data for row evolution should NOT be limited
+ 'filter_limit' => -1,
+
+ // if more than one label is used, we add metadata to ensure we know which
+ // row corresponds with which label (since the labels can change, and rows
+ // can be sorted in a different order)
+ 'labelFilterAddLabelIndex' => count($label) > 1 ? 1 : 0,
);
// add "processed metrics" like actions per visit or bounce rate
@@ -1330,7 +1358,7 @@ class Piwik_API_API
$apiModule != 'Actions'
&&
($apiModule != 'Goals' || ($apiAction != 'getVisitsUntilConversion' && $apiAction != 'getDaysToConversion'))
- && $label // do not request processed metrics when retrieving top n labels
+ && !empty($label)
) {
$parameters['filter_add_columns_when_show_all_columns'] = '1';
}
@@ -1466,15 +1494,12 @@ class Piwik_API_API
$metrics = array_keys($metadata['metrics']);
$column = reset($metrics);
}
-
+
// get the processed label and logo (if any) for every requested label
$actualLabels = $logos = array();
foreach ($labels as $labelIdx => $label) {
foreach ($dataTable->getArray() as $table) {
- // find row for this label. LabelFilter will add empty rows and
- // keep them ordered in the same way the labels array is, so we
- // assume the $labelIdx is also the row Id
- $labelRow = $table->getRowFromId($labelIdx);
+ $labelRow = $this->getRowEvolutionRowFromLabelIdx($table, $labelIdx);
if ($labelRow) {
$actualLabels[$labelIdx] = $this->getRowUrlForEvolutionLabel(
@@ -1500,7 +1525,7 @@ class Piwik_API_API
$newRow = new Piwik_DataTable_Row();
foreach ($labels as $labelIdx => $label) {
- $row = $table->getRowFromId($labelIdx);
+ $row = $this->getRowEvolutionRowFromLabelIdx($table, $labelIdx);
$value = 0;
if ($row) {
@@ -1517,7 +1542,10 @@ class Piwik_API_API
}
$newTable = $table->getEmptyClone();
- $newTable->addRow($newRow);
+ if (!empty($labels)) { // only add a row if the row has data (no labels === no data)
+ $newTable->addRow($newRow);
+ }
+
$dataTableMulti->addTable($newTable, $tableLabel);
}
@@ -1547,6 +1575,26 @@ class Piwik_API_API
'metadata' => $metadata
);
}
+
+ /**
+ * Returns the row in a datatable by its label_index metadata.
+ *
+ * @param Piwik_DataTable $table
+ * @param int $labelIdx
+ * @return Piwik_DataTable_Row|false
+ */
+ private function getRowEvolutionRowFromLabelIdx($table, $labelIdx)
+ {
+ $labelIdx = (int)$labelIdx;
+ foreach ($table->getRows() as $row)
+ {
+ if ($row->getMetadata('label_index') === $labelIdx)
+ {
+ return $row;
+ }
+ }
+ return false;
+ }
/**
* Returns a prettier, more comprehensible version of a row evolution label