diff options
author | diosmosis <benaka@piwik.pro> | 2015-09-11 05:20:42 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-09-15 02:39:40 +0300 |
commit | c990532b31a051852aec12d0914a2b047339ea01 (patch) | |
tree | d662be0ac0e51862e513f91aabf24109c0fbc54b /plugins/API | |
parent | 45c929d831a0e0c1c31cd10099f8f399e911b1fa (diff) |
Allow new CustomVariable segments to provide all custom variable suggested values by allowing the suggestedValuesCallback to accept Live.getLastVisitDetails data.
Diffstat (limited to 'plugins/API')
-rw-r--r-- | plugins/API/API.php | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/plugins/API/API.php b/plugins/API/API.php index dcdacf40b2..3bc1b3baef 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -487,8 +487,14 @@ class API extends \Piwik\Plugin\API } // if segment has suggested values callback then return result from it instead + $suggestedValuesCallbackRequiresTable = false; if (isset($segmentFound['suggestedValuesCallback'])) { - return call_user_func($segmentFound['suggestedValuesCallback'], $idSite, $maxSuggestionsToReturn); + $suggestedValuesCallbackRequiresTable = $this->doesSuggestedValuesCallbackNeedData( + $segmentFound['suggestedValuesCallback']); + + if (!$suggestedValuesCallbackRequiresTable) { + return call_user_func($segmentFound['suggestedValuesCallback'], $idSite, $maxSuggestionsToReturn); + } } // if period=range is disabled, do not proceed @@ -523,12 +529,16 @@ class API extends \Piwik\Plugin\API throw new \Exception("There was no data to suggest for $segmentName"); } - // Cleanup data to return the top suggested (non empty) labels for this segment - $values = $table->getColumn($segmentName); + if ($suggestedValuesCallbackRequiresTable) { + $values = call_user_func($segmentFound['suggestedValuesCallback'], $idSite, $maxSuggestionsToReturn, $table); + } else { + // Cleanup data to return the top suggested (non empty) labels for this segment + $values = $table->getColumn($segmentName); - // Select also flattened keys (custom variables "page" scope, page URLs for one visit, page titles for one visit) - $valuesBis = $table->getColumnsStartingWith($segmentName . ColumnDelete::APPEND_TO_COLUMN_NAME_TO_KEEP); - $values = array_merge($values, $valuesBis); + // Select also flattened keys (custom variables "page" scope, page URLs for one visit, page titles for one visit) + $valuesBis = $table->getColumnsStartingWith($segmentName . ColumnDelete::APPEND_TO_COLUMN_NAME_TO_KEEP); + $values = array_merge($values, $valuesBis); + } $values = $this->getMostFrequentValues($values); @@ -579,6 +589,13 @@ class API extends \Piwik\Plugin\API $values = array_keys($values); return $values; } + + private function doesSuggestedValuesCallbackNeedData($suggestedValuesCallback) + { + $methodMetadata = new \ReflectionFunction($suggestedValuesCallback); + $parametersCount = $methodMetadata->getNumberOfParameters(); + return $parametersCount >= 3; + } } /** |