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:
authorThomas Steur <thomas.steur@googlemail.com>2014-08-21 18:16:08 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-08-21 18:16:08 +0400
commitd079edfc7eaf000e9e9d1f71cf0b7cc12dff6e8c (patch)
tree409bf8afdfb3cef9f00c43d6e1cd9fdaa352416f /plugins/Contents/API.php
parentd44cce7e3b49c8a74d30b0b35e042491409a7f45 (diff)
refs #4996 actually archive the tracked data and display the actual data in a report
Diffstat (limited to 'plugins/Contents/API.php')
-rw-r--r--plugins/Contents/API.php47
1 files changed, 39 insertions, 8 deletions
diff --git a/plugins/Contents/API.php b/plugins/Contents/API.php
index da5c6f1081..f9c2b8d9ab 100644
--- a/plugins/Contents/API.php
+++ b/plugins/Contents/API.php
@@ -8,8 +8,11 @@
*/
namespace Piwik\Plugins\Contents;
+use Piwik\Archive;
use Piwik\DataTable;
use Piwik\DataTable\Row;
+use Piwik\Metrics;
+use Piwik\Piwik;
/**
* API for plugin Contents
@@ -19,6 +22,10 @@ use Piwik\DataTable\Row;
class API extends \Piwik\Plugin\API
{
+ protected $mappingApiToRecord = array(
+ 'getContents' => Archiver::CONTENTS_NAME_RECORD_NAME
+ );
+
/**
* Another example method that returns a data table.
* @param int $idSite
@@ -29,15 +36,39 @@ class API extends \Piwik\Plugin\API
*/
public function getContents($idSite, $period, $date, $segment = false)
{
- $table = new DataTable();
+ return $this->getDataTable(__FUNCTION__, $idSite, $period, $date, $segment);
+ }
+
+ protected function getDataTable($name, $idSite, $period, $date, $segment)
+ {
+ Piwik::checkUserHasViewAccess($idSite);
+ $recordName = $this->getRecordNameForAction($name);
+ $dataTable = Archive::getDataTableFromArchive($recordName, $idSite, $period, $date, $segment, false);
+ $this->filterDataTable($dataTable);
+ return $dataTable;
+ }
- $table->addRowFromArray(array(Row::COLUMNS => array(
- 'label' => 'My banner',
- 'nb_impressions' => 50,
- 'nb_conversions' => 5,
- 'conversion_rate' => '10%'
- )));
+ protected function getRecordNameForAction($apiMethod, $secondaryDimension = false)
+ {
+ return $this->mappingApiToRecord[$apiMethod];
+ }
+
+ /**
+ * @param DataTable $dataTable
+ */
+ protected function filterDataTable($dataTable)
+ {
+ $dataTable->filter('Sort', array(Metrics::INDEX_NB_VISITS));
+ $dataTable->queueFilter('ReplaceColumnNames');
+ $dataTable->queueFilter('ReplaceSummaryRowLabel');
+ $dataTable->filter(function (DataTable $table) {
+ $row = $table->getRowFromLabel(Archiver::CONTENT_TARGET_NOT_SET);
+ if ($row) {
+ $row->setColumn('label', Piwik::translate('General_NotDefined', Piwik::translate('Contents_ContentTarget')));
+ }
+ });
- return $table;
+ // Content conversion rate = conversions / impressions
+ $dataTable->queueFilter('ColumnCallbackAddColumnPercentage', array('conversion_rate', 'nb_conversions', 'nb_impressions', $precision = 2));
}
}