diff --git a/plugins/Events/API.php b/plugins/Events/API.php index 23aa5bdc59b27ba7849b807fd7721e8a4c84bddd..0be6037596cb2685e7785dee72a37fe32e446ce7 100644 --- a/plugins/Events/API.php +++ b/plugins/Events/API.php @@ -55,7 +55,7 @@ class API extends \Piwik\Plugin\API /** * @ignore */ - public function getActionToLoadSubtables($apiMethod, $secondaryDimension) + public function getActionToLoadSubtables($apiMethod, $secondaryDimension = false) { $recordName = $this->getRecordNameForAction($apiMethod, $secondaryDimension); $apiMethod = array_search( $recordName, $this->mappingApiToRecord ); @@ -77,15 +77,17 @@ class API extends \Piwik\Plugin\API protected function getRecordNameForAction($apiMethod, $secondaryDimension = false) { if (empty($secondaryDimension)) { - $record = $this->mappingApiToRecord[$apiMethod]; - - if(!is_array($record)) { - return $record; - } $secondaryDimension = $this->getDefaultSecondaryDimension($apiMethod); } - - return $this->mappingApiToRecord[$apiMethod][$secondaryDimension]; + $record = $this->mappingApiToRecord[$apiMethod]; + if(!is_array($record)) { + return $record; + } + // when secondaryDimension is incorrectly set + if(empty($record[$secondaryDimension])) { + return key($record); + } + return $record[$secondaryDimension]; } /** @@ -96,6 +98,9 @@ class API extends \Piwik\Plugin\API public function getSecondaryDimensions($apiMethod) { $records = $this->mappingApiToRecord[$apiMethod]; + if(!is_array($records)) { + return false; + } return array_keys($records); } diff --git a/plugins/Events/Events.php b/plugins/Events/Events.php index 683425ea91e73f3dcf3ab0afe02b3540bd8b211c..ad7dd7d4bbe10d5abe83d8075c47c700e545a148 100644 --- a/plugins/Events/Events.php +++ b/plugins/Events/Events.php @@ -152,7 +152,7 @@ class Events extends \Piwik\Plugin $order = 0; foreach($labelTranslations as $action => $translations) { - $secondaryDimension = $this->getSecondaryDimensionFromRequest($action); + $secondaryDimension = $this->getSecondaryDimensionFromRequest(); $actionToLoadSubtables = API::getInstance()->getActionToLoadSubtables($action, $secondaryDimension); $reports[] = array( 'category' => Piwik::translate('Events_Events'), @@ -215,22 +215,15 @@ class Events extends \Piwik\Plugin // eg. 'Events.getCategory' $apiMethod = $view->requestConfig->getApiMethodToRequest(); - $secondaryDimension = $this->getSecondaryDimensionFromRequest($apiMethod); - + $secondaryDimension = $this->getSecondaryDimensionFromRequest(); $view->config->subtable_controller_action = API::getInstance()->getActionToLoadSubtables($apiMethod, $secondaryDimension); $view->config->columns_to_display = array('label', 'nb_events', 'sum_event_value'); $view->config->show_flatten_table = true; $view->config->show_table = false; $view->config->show_table_all_columns = false; - - //$view->config->custom_parameters['flat'] = 0; - //$view->config->custom_parameters['secondaryDimension'] = $secondaryDimension; - $view->requestConfig->filter_sort_column = 'nb_events'; - $labelTranslation = $this->getColumnTranslation($apiMethod); - $view->config->addTranslation('label', $labelTranslation); $view->config->addTranslations($this->getMetricTranslations()); $this->addRelatedReports($view, $secondaryDimension); @@ -244,6 +237,10 @@ class Events extends \Piwik\Plugin $apiMethod = $view->requestConfig->getApiMethodToRequest(); $secondaryDimensions = API::getInstance()->getSecondaryDimensions($apiMethod); + if(empty($secondaryDimensions)) { + return; + } + $secondaryDimensionTranslation = $this->getDimensionLabel($secondaryDimension); $view->config->related_reports_title = Piwik::translate('Events_SecondaryDimension', $secondaryDimensionTranslation) @@ -296,9 +293,8 @@ class Events extends \Piwik\Plugin /** * @return mixed */ - protected function getSecondaryDimensionFromRequest($apiMethod) + protected function getSecondaryDimensionFromRequest() { - $defaultSecondaryDimension = API::getInstance()->getDefaultSecondaryDimension($apiMethod); return Common::getRequestVar('secondaryDimension', false, 'string'); } }