diff options
-rw-r--r-- | plugins/Contents/API.php | 13 | ||||
-rw-r--r-- | plugins/Contents/Archiver.php | 10 | ||||
-rw-r--r-- | plugins/Contents/Contents.php | 4 | ||||
-rw-r--r-- | plugins/Contents/Controller.php | 7 | ||||
-rw-r--r-- | plugins/Contents/Dimensions.php | 81 | ||||
-rw-r--r-- | plugins/Contents/Reports/Base.php | 17 |
6 files changed, 40 insertions, 92 deletions
diff --git a/plugins/Contents/API.php b/plugins/Contents/API.php index 15cd14179e..ef4bdaf781 100644 --- a/plugins/Contents/API.php +++ b/plugins/Contents/API.php @@ -21,21 +21,20 @@ use Piwik\Piwik; */ class API extends \Piwik\Plugin\API { - public function getContentNames($idSite, $period, $date, $segment = false, $idSubtable = false, $secondaryDimension = false) + public function getContentNames($idSite, $period, $date, $segment = false, $idSubtable = false) { - return $this->getDataTable(__FUNCTION__, $idSite, $period, $date, $segment, false, $idSubtable, $secondaryDimension); + return $this->getDataTable(__FUNCTION__, $idSite, $period, $date, $segment, false, $idSubtable); } - public function getContentPieces($idSite, $period, $date, $segment = false, $idSubtable = false, $secondaryDimension = false) + public function getContentPieces($idSite, $period, $date, $segment = false, $idSubtable = false) { - return $this->getDataTable(__FUNCTION__, $idSite, $period, $date, $segment, false, $idSubtable, $secondaryDimension); + return $this->getDataTable(__FUNCTION__, $idSite, $period, $date, $segment, false, $idSubtable); } - private function getDataTable($name, $idSite, $period, $date, $segment, $expanded, $idSubtable, $secondaryDimension) + private function getDataTable($name, $idSite, $period, $date, $segment, $expanded, $idSubtable) { Piwik::checkUserHasViewAccess($idSite); - Dimensions::checkSecondaryDimension($name, $secondaryDimension); - $recordName = Dimensions::getRecordNameForAction($name, $secondaryDimension); + $recordName = Dimensions::getRecordNameForAction($name); $dataTable = Archive::getDataTableFromArchive($recordName, $idSite, $period, $date, $segment, $expanded, $idSubtable); $this->filterDataTable($dataTable); return $dataTable; diff --git a/plugins/Contents/Archiver.php b/plugins/Contents/Archiver.php index c1175fc8b6..c5888b29a8 100644 --- a/plugins/Contents/Archiver.php +++ b/plugins/Contents/Archiver.php @@ -249,7 +249,7 @@ class Archiver extends \Piwik\Plugin\Archiver $mainLabel = $row[$mainDimension]; $dataArray->sumMetricsImpressions($mainLabel, $row); - $this->rememberMetadataForRow($row, $mainLabel, $mainDimension); + $this->rememberMetadataForRow($row, $mainLabel); $subDimension = $dimensions[1]; $subLabel = $row[$subDimension]; @@ -283,16 +283,10 @@ class Archiver extends \Piwik\Plugin\Archiver } } - private function rememberMetadataForRow($row, $mainLabel, $mainDimension) + private function rememberMetadataForRow($row, $mainLabel) { $this->metadata[$mainLabel] = array(); - if ($mainDimension === 'contentPiece') { - $this->metadata[$mainLabel]['contentName'] = $row['contentName']; - } elseif ($mainDimension === 'contentName') { - $this->metadata[$mainLabel]['contentPiece'] = $row['contentPiece']; - } - $target = $row['contentTarget']; if (empty($target)) { $target = Archiver::CONTENT_TARGET_NOT_SET; diff --git a/plugins/Contents/Contents.php b/plugins/Contents/Contents.php index 5a81979ed3..0fd5993742 100644 --- a/plugins/Contents/Contents.php +++ b/plugins/Contents/Contents.php @@ -22,8 +22,8 @@ class Contents extends \Piwik\Plugin public function addMetricTranslations(&$translations) { - $translations['nb_impressions'] = 'Contents_Impressions'; - $translations['nb_interactions'] = 'Contents_Interactions'; + $translations['nb_impressions'] = 'Contents_Impressions'; + $translations['nb_interactions'] = 'Contents_Interactions'; $translations['interaction_rate'] = 'Contents_InteractionRate'; } diff --git a/plugins/Contents/Controller.php b/plugins/Contents/Controller.php index d7cde20a24..daf319bb53 100644 --- a/plugins/Contents/Controller.php +++ b/plugins/Contents/Controller.php @@ -24,15 +24,10 @@ class Controller extends \Piwik\Plugin\Controller $reports = array(new GetContentNames(), new GetContentPieces()); foreach($reports as $report) { - $params = array( - 'secondaryDimension' => Dimensions::getDefaultSecondaryDimension($report->getAction()) - ); - $reportsView->addReport( $report->getCategory(), $report->getName(), - 'Contents.menu' . ucfirst($report->getAction()), - $params + 'Contents.menu' . ucfirst($report->getAction()) ); } diff --git a/plugins/Contents/Dimensions.php b/plugins/Contents/Dimensions.php index aab79450ca..ce74022924 100644 --- a/plugins/Contents/Dimensions.php +++ b/plugins/Contents/Dimensions.php @@ -10,81 +10,24 @@ namespace Piwik\Plugins\Contents; class Dimensions { - - private static $defaultMappingApiToSecondaryDimension = array( - 'getContentNames' => 'getContentPieces', - 'getContentPieces' => 'getContentNames' - ); - - private static $mappingApiToRecord = array( - 'getContentNames' => array( - 'getContentPieces' => Archiver::CONTENTS_NAME_PIECE_RECORD_NAME - ), - 'getContentPieces' => array( - 'getContentNames' => Archiver::CONTENTS_PIECE_NAME_RECORD_NAME, - ) - ); - - public static function getDefaultSecondaryDimension($apiMethod) - { - if (isset(self::$defaultMappingApiToSecondaryDimension[$apiMethod])) { - return self::$defaultMappingApiToSecondaryDimension[$apiMethod]; - } - - return false; - } - - public static function getRecordNameForAction($apiMethod, $secondaryDimension = false) - { - if (empty($secondaryDimension)) { - $secondaryDimension = self::getDefaultSecondaryDimension($apiMethod); - } - - $record = self::$mappingApiToRecord[$apiMethod]; - if (!is_array($record)) { - return $record; - } - - // when secondaryDimension is incorrectly set - if (empty($record[$secondaryDimension])) { - return key($record); - } - - return $record[$secondaryDimension]; - } - - /** - * @ignore - * @param $apiMethod - * @return array - */ - public static function getSecondaryDimensions($apiMethod) + public static function getRecordNameForAction($apiMethod) { - $records = self::$mappingApiToRecord[$apiMethod]; - - if(!is_array($records)) { - return false; - } + $apiToRecord = array( + 'getContentNames' => Archiver::CONTENTS_NAME_PIECE_RECORD_NAME, + 'getContentPieces' => Archiver::CONTENTS_PIECE_NAME_RECORD_NAME + ); - return array_keys($records); + return $apiToRecord[$apiMethod]; } - public static function checkSecondaryDimension($apiMethod, $secondaryDimension) + public static function getSubtableLabelForApiMethod($apiMethod) { - if (empty($secondaryDimension)) { - return; - } - - $isSecondaryDimensionValid = - isset(self::$mappingApiToRecord[$apiMethod]) - && isset(self::$mappingApiToRecord[$apiMethod][$secondaryDimension]); + $labelToMethod = array( + 'getContentNames' => 'Contents_ContentPiece', + 'getContentPieces' => 'Contents_ContentName' + ); - if (!$isSecondaryDimensionValid) { - throw new \Exception( - "Secondary dimension '$secondaryDimension' is not valid for the API $apiMethod. ". - "Use one of: " . implode(", ", self::getSecondaryDimensions($apiMethod)) - ); - } + return $labelToMethod[$apiMethod]; } } diff --git a/plugins/Contents/Reports/Base.php b/plugins/Contents/Reports/Base.php index e972078eee..d4c61e605a 100644 --- a/plugins/Contents/Reports/Base.php +++ b/plugins/Contents/Reports/Base.php @@ -8,8 +8,12 @@ */ namespace Piwik\Plugins\Contents\Reports; +use Piwik\Columns\Dimension; +use Piwik\Common; +use Piwik\Piwik; use Piwik\Plugin\Report; use Piwik\Plugin\ViewDataTable; +use Piwik\Plugins\Contents\Dimensions; abstract class Base extends Report { @@ -32,5 +36,18 @@ abstract class Base extends Report $view->config->columns_to_display = array_merge(array('label'), $this->metrics); $view->requestConfig->filter_sort_column = 'nb_impressions'; + + if ($this->hasSubtableId()) { + $apiMethod = $view->requestConfig->getApiMethodToRequest(); + $label = Dimensions::getSubtableLabelForApiMethod($apiMethod); + $view->config->addTranslation('label', Piwik::translate($label)); + } + } + + private function hasSubtableId() + { + $subtable = Common::getRequestVar('idSubtable', false, 'integer'); + + return !empty($subtable); } } |