function google_analytics_reports_api_profiles_list in Google Analytics Reports 7.3
Same name and namespace in other branches
- 8.3 google_analytics_reports_api/google_analytics_reports_api.module \google_analytics_reports_api_profiles_list()
Google Analytics reports profiles for current authorized user.
Return value
array/null An associative array containing:
- options: list of current available profiles.
- profile_id: current default profile id.
- current_profile: current default profile object.
3 calls to google_analytics_reports_api_profiles_list()
- google_analytics_reports_api_admin in google_analytics_reports_api/
google_analytics_reports_api.admin.inc - Menu callback - admin form for OAuth and other settings.
- google_analytics_reports_plugin_query_google_analytics::options_form in plugins/
google_analytics_reports_plugin_query_google_analytics.inc - Add settings for the ui.
- google_analytics_reports_plugin_query_google_analytics::option_definition in plugins/
google_analytics_reports_plugin_query_google_analytics.inc - Definition of views options.
File
- google_analytics_reports_api/
google_analytics_reports_api.admin.inc, line 148 - Admin and OAuth callbacks for Google Analytics Reports API module.
Code
function google_analytics_reports_api_profiles_list() {
$account = google_analytics_reports_api_gafeed();
if ($account && $account
->isAuthenticated()) {
$web_properties = $account
->queryWebProperties()->results->items;
$profiles = $account
->queryProfiles()->results->items;
$options = array();
$profile_id = variable_get('google_analytics_reports_api_profile_id', 0);
$google_analytics_account = variable_get('googleanalytics_account');
$set_default = FALSE;
// Add optgroups for each web property.
if (!empty($profiles)) {
foreach ($profiles as $profile) {
$web_property = NULL;
foreach ($web_properties as $web_property_value) {
if ($web_property_value->id == $profile->webPropertyId) {
$web_property = $web_property_value;
break;
}
}
$options[$web_property->name][$profile->id] = theme('google_analytics_reports_api_profile_label', array(
'profile' => $profile,
));
// Find current site in the account list.
if (empty($profile_id)) {
// If Google Analytics module is enabled check it first.
if (isset($google_analytics_account) && $google_analytics_account == $profile->webPropertyId) {
$profile_id = $profile->id;
$set_default = TRUE;
}
elseif (parse_url($web_property->websiteUrl, PHP_URL_HOST) == $_SERVER['HTTP_HOST']) {
$profile_id = $profile->id;
$set_default = TRUE;
}
}
}
}
// If no profile ID is set yet, set the first profile in the list.
if (empty($profile_id)) {
$profile_id = key($options[key($options)]);
$set_default = TRUE;
}
if ($set_default) {
variable_set('google_analytics_reports_api_profile_id', $profile_id);
}
$current_profile = NULL;
// Load current profile object.
foreach ($profiles as $profile) {
if ($profile->id == $profile_id) {
$current_profile = $profile;
variable_set('google_analytics_reports_api_default_page', isset($current_profile->defaultPage) ? '/' . $current_profile->defaultPage : '/');
break;
}
}
$return = array(
'options' => $options,
'profile_id' => $profile_id,
'current_profile' => $current_profile,
);
return $return;
}
}