diff options
author | diosmosis <benaka@piwik.pro> | 2015-09-03 00:12:24 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-09-03 01:42:51 +0300 |
commit | 173259c446a6446936f3cfdea4735124a0d346b7 (patch) | |
tree | 4aa7a8f80605955ddfc31c10dab46ff4d59bc629 /plugins/API | |
parent | 76adbdc804d8ab9e2c7e938bf28b7ba0ff4481b7 (diff) |
Refactor API.getSegmentsMetadata and Plugin\Segment so segments are all defined through Plugin\Segment class in dimensions & make sure AutoSuggestAPITest data providers do not use database.
Diffstat (limited to 'plugins/API')
-rw-r--r-- | plugins/API/API.php | 51 |
1 files changed, 6 insertions, 45 deletions
diff --git a/plugins/API/API.php b/plugins/API/API.php index 90c7b1f45c..3c7d68c18e 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -120,10 +120,15 @@ class API extends \Piwik\Plugin\API public function getSegmentsMetadata($idSites = array(), $_hideImplementationData = true) { - $segments = array(); + $isAuthenticatedWithViewAccess = Piwik::isUserHasViewAccess($idSites) && !Piwik::isUserIsAnonymous(); + $segments = array(); foreach (Dimension::getAllDimensions() as $dimension) { foreach ($dimension->getSegments() as $segment) { + if ($segment->isRequiresAtLeastViewAccess()) { + $segment->setPermission($isAuthenticatedWithViewAccess); + } + $segments[] = $segment->toArray(); } } @@ -176,50 +181,6 @@ class API extends \Piwik\Plugin\API */ Piwik::postEvent('API.getSegmentDimensionMetadata', array(&$segments, $idSites)); - $isAuthenticatedWithViewAccess = Piwik::isUserHasViewAccess($idSites) && !Piwik::isUserIsAnonymous(); - - $segments[] = array( - 'type' => 'dimension', - 'category' => Piwik::translate('General_Visit'), - 'name' => 'General_UserId', - 'segment' => 'userId', - 'acceptedValues' => 'any non empty unique string identifying the user (such as an email address or a username).', - 'sqlSegment' => 'log_visit.user_id', - 'permission' => $isAuthenticatedWithViewAccess, - ); - - $segments[] = array( - 'type' => 'dimension', - 'category' => Piwik::translate('General_Visit'), - 'name' => 'General_VisitorID', - 'segment' => 'visitorId', - 'acceptedValues' => '34c31e04394bdc63 - any 16 Hexadecimal chars ID, which can be fetched using the Tracking API function getVisitorId()', - 'sqlSegment' => 'log_visit.idvisitor', - 'sqlFilterValue' => array('Piwik\Common', 'convertVisitorIdToBin'), - 'permission' => $isAuthenticatedWithViewAccess, - ); - - $segments[] = array( - 'type' => 'dimension', - 'category' => Piwik::translate('General_Visit'), - 'name' => Piwik::translate('General_Visit') . " ID", - 'segment' => 'visitId', - 'acceptedValues' => 'Any integer. ', - 'sqlSegment' => 'log_visit.idvisit', - 'permission' => $isAuthenticatedWithViewAccess, - ); - - $segments[] = array( - 'type' => 'metric', - 'category' => Piwik::translate('General_Visit'), - 'name' => 'General_VisitorIP', - 'segment' => 'visitIp', - 'acceptedValues' => '13.54.122.1. </code>Select IP ranges with notation: <code>visitIp>13.54.122.0;visitIp<13.54.122.255', - 'sqlSegment' => 'log_visit.location_ip', - 'sqlFilterValue' => array('Piwik\Network\IPUtils', 'stringToBinaryIP'), - 'permission' => $isAuthenticatedWithViewAccess, - ); - foreach ($segments as &$segment) { $segment['name'] = Piwik::translate($segment['name']); $segment['category'] = Piwik::translate($segment['category']); |