You are here

protected function gapi::accountObjectMapper in Google Analytics Statistics 7

Same name and namespace in other branches
  1. 7.2 includes/gapi.class.php \gapi::accountObjectMapper()
  2. 7.x inc/gapi.class.php \gapi::accountObjectMapper()

Report Account Mapper to convert the XML to array of useful PHP objects

Parameters

String $xml_string:

Return value

Array of gapiAccountEntry objects

1 call to gapi::accountObjectMapper()
gapi::requestAccountData in includes/gapi.class.php
Request account data from Google Analytics

File

includes/gapi.class.php, line 256

Class

gapi
GAPI - Google Analytics PHP Interface

Code

protected function accountObjectMapper($xml_string) {
  $xml = simplexml_load_string($xml_string);
  $this->results = null;
  $results = array();
  $account_root_parameters = array();

  //Load root parameters
  $account_root_parameters['updated'] = strval($xml->updated);
  $account_root_parameters['generator'] = strval($xml->generator);
  $account_root_parameters['generatorVersion'] = strval($xml->generator
    ->attributes());
  $open_search_results = $xml
    ->children('http://a9.com/-/spec/opensearchrss/1.0/');
  foreach ($open_search_results as $key => $open_search_result) {
    $report_root_parameters[$key] = intval($open_search_result);
  }

  //ADDED: If statement to avoid error messages
  if (isset($google_results)) {
    $account_root_parameters['startDate'] = strval($google_results->startDate);
    $account_root_parameters['endDate'] = strval($google_results->endDate);
  }

  //Load result entries
  foreach ($xml->entry as $entry) {
    $properties = array();
    foreach ($entry
      ->children('http://schemas.google.com/analytics/2009')->property as $property) {
      $properties[str_replace('ga:', '', $property
        ->attributes()->name)] = strval($property
        ->attributes()->value);
    }
    $properties['title'] = strval($entry->title);
    $properties['updated'] = strval($entry->updated);
    $results[] = new gapiAccountEntry($properties);
  }
  $this->account_root_parameters = $account_root_parameters;
  $this->results = $results;
  return $results;
}