diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-07-21 12:01:35 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-07-21 12:01:36 +0400 |
commit | aca8ec33a85e0a70b818b6227145041717d7a69e (patch) | |
tree | 41377e3a9737d63222522ef93ecf8483f3faddfa /plugins/MultiSites/API.php | |
parent | 0a63210e3eae7562af1a3dbee340eb1ee140db3d (diff) |
Refs #4059 Work in progress: Conversion to use Namespaces: Period*, Metrics, Segment, SegmentExpression, PluginsManager.
Removed some deprecated code.
Diffstat (limited to 'plugins/MultiSites/API.php')
-rwxr-xr-x | plugins/MultiSites/API.php | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/plugins/MultiSites/API.php b/plugins/MultiSites/API.php index 0c75406004..2906edc981 100755 --- a/plugins/MultiSites/API.php +++ b/plugins/MultiSites/API.php @@ -9,9 +9,11 @@ * @package Piwik_MultiSites */ use Piwik\Archive; -use Piwik\Period_Range; +use Piwik\DataTable\Filter\CalculateEvolutionFilter; +use Piwik\Period\Range; use Piwik\Piwik; use Piwik\Common; +use Piwik\DataTable; use Piwik\Site; /** @@ -95,7 +97,7 @@ class Piwik_MultiSites_API * Only used when a scheduled task is running * @param bool|string $enhanced When true, return additional goal & ecommerce metrics * @param bool|string $pattern If specified, only the website which names (or site ID) match the pattern will be returned using SitesManager.getPatternMatchSites - * @return Piwik_DataTable + * @return DataTable */ public function getAll($period, $date, $segment = false, $_restrictSitesToLogin = false, $enhanced = false, $pattern = false) { @@ -104,7 +106,7 @@ class Piwik_MultiSites_API $idSites = $this->getSitesIdFromPattern($pattern); if(empty($idSites)) { - return new Piwik_DataTable(); + return new DataTable(); } return $this->buildDataTable( $idSites, @@ -154,7 +156,7 @@ class Piwik_MultiSites_API * @param bool|string $_restrictSitesToLogin Hack used to enforce we restrict the returned data to the specified username * Only used when a scheduled task is running * @param bool|string $enhanced When true, return additional goal & ecommerce metrics - * @return Piwik_DataTable + * @return DataTable */ public function getOne($idSite, $period, $date, $segment = false, $_restrictSitesToLogin = false, $enhanced = false) { @@ -214,16 +216,16 @@ class Piwik_MultiSites_API } // get the data - // $dataTable instanceOf Piwik_DataTable_Array + // $dataTable instanceOf Set $dataTable = $archive->getDataTableFromNumeric($fieldsToGet); // get rid of the DataTable_Array that is created by the IndexedBySite archive type - if ($dataTable instanceof Piwik_DataTable_Array + if ($dataTable instanceof DataTable\Map && $multipleWebsitesRequested ) { $dataTable = $dataTable->mergeChildren(); } else { - if (!($dataTable instanceof Piwik_DataTable_Array) + if (!($dataTable instanceof DataTable\Map) && $dataTable->getRowsCount() > 0 ) { $firstSite = is_array($sites) ? reset($sites) : $sites; @@ -238,18 +240,18 @@ class Piwik_MultiSites_API // if the period isn't a range & a lastN/previousN date isn't used, we get the same // data for the last period to show the evolution of visits/actions/revenue - list($strLastDate, $lastPeriod) = Period_Range::getLastDate($date, $period); + list($strLastDate, $lastPeriod) = Range::getLastDate($date, $period); if ($strLastDate !== false) { if ($lastPeriod !== false) { // NOTE: no easy way to set last period date metadata when range of dates is requested. // will be easier if DataTable_Array::metadata is removed, and metadata that is - // put there is put directly in Piwik_DataTable::metadata. + // put there is put directly in DataTable::metadata. $dataTable->setMetadata(self::getLastPeriodMetadataName('date'), $lastPeriod); } $pastArchive = Archive::build($sites, $period, $strLastDate, $segment, $_restrictSitesToLogin); $pastData = $pastArchive->getDataTableFromNumeric($fieldsToGet); - if ($pastData instanceof Piwik_DataTable_Array + if ($pastData instanceof DataTable\Map && $multipleWebsitesRequested ) { $pastData = $pastData->mergeChildren(); @@ -264,7 +266,7 @@ class Piwik_MultiSites_API // remove eCommerce related metrics on non eCommerce Piwik sites // note: this is not optimal in terms of performance: those metrics should not be retrieved in the first place if ($enhanced) { - // $dataTableRows instanceOf Piwik_DataTable_Row[] + // $dataTableRows instanceOf Row[] $dataTableRows = $dataTable->getRows(); foreach ($dataTableRows as $dataTableRow) { @@ -283,8 +285,7 @@ class Piwik_MultiSites_API // set the label of each row to the site name if ($multipleWebsitesRequested) { - $getNameFor = array('Site', 'getNameFor'); - $dataTable->filter('ColumnCallbackReplace', array('label', $getNameFor)); + $dataTable->filter('ColumnCallbackReplace', array('label', '\Piwik\Site::getNameFor')); } else { $dataTable->filter('ColumnDelete', array('label')); } @@ -317,8 +318,8 @@ class Piwik_MultiSites_API * Performs a binary filter of two * DataTables in order to correctly calculate evolution metrics. * - * @param Piwik_DataTable|Piwik_DataTable_Array $currentData - * @param Piwik_DataTable|Piwik_DataTable_Array $pastData + * @param DataTable|DataTable\Map $currentData + * @param DataTable|DataTable\Map $pastData * @param array $apiMetrics The array of string fields to calculate evolution * metrics for. * @throws Exception @@ -330,7 +331,7 @@ class Piwik_MultiSites_API . get_class($pastData)."."); } - if ($currentData instanceof Piwik_DataTable_Array) { + if ($currentData instanceof DataTable\Map) { $pastArray = $pastData->getArray(); foreach ($currentData->getArray() as $subTable) { $this->calculateEvolutionPercentages($subTable, current($pastArray), $apiMetrics); @@ -354,13 +355,13 @@ class Piwik_MultiSites_API * Sets the total visits, actions & revenue for a DataTable returned by * $this->buildDataTable. * - * @param Piwik_DataTable $dataTable + * @param DataTable $dataTable * @param array $apiMetrics Metrics info. * @return array Array of three values: total visits, total actions, total revenue */ private function setMetricsTotalsMetadata($dataTable, $apiMetrics) { - if ($dataTable instanceof Piwik_DataTable_Array) { + if ($dataTable instanceof DataTable\Map) { foreach ($dataTable->getArray() as $table) { $this->setMetricsTotalsMetadata($table, $apiMetrics); } @@ -393,13 +394,13 @@ class Piwik_MultiSites_API * Sets the total evolution metadata for a datatable returned by $this->buildDataTable * given data for the last period. * - * @param Piwik_DataTable $dataTable - * @param Piwik_DataTable $pastData + * @param DataTable $dataTable + * @param DataTable $pastData * @param array $apiMetrics Metrics info. */ private function setPastDataMetadata($dataTable, $pastData, $apiMetrics) { - if ($dataTable instanceof Piwik_DataTable_Array) { + if ($dataTable instanceof DataTable\Map) { $pastArray = $pastData->getArray(); foreach ($dataTable->getArray() as $subTable) { $this->setPastDataMetadata($subTable, current($pastArray), $apiMetrics); @@ -422,7 +423,7 @@ class Piwik_MultiSites_API // calculate & set evolution $currentTotal = $dataTable->getMetadata($totalMetadataName); - $evolution = Piwik_DataTable_Filter_CalculateEvolutionFilter::calculate($currentTotal, $pastTotal); + $evolution = CalculateEvolutionFilter::calculate($currentTotal, $pastTotal); $dataTable->setMetadata($totalEvolutionMetadataName, $evolution); } } |