You are here

public static function clients_connection_drupal_services::call in Web Service Clients 7

Executes call and processes data

Overrides clients_connection_base::call

File

backends/clients_drupal/clients_drupal.inc, line 322
Defines methods and calls to Drupal services

Class

clients_connection_drupal_services
General Drupal client class.

Code

public static function call($connection, $resource) {
  if ($resource->configuration['options']['method'] == 'views.get') {
    $user = self::getUser($connection);

    // gets raw result
    $result = self::fetch($connection, $resource, $user);

    // needs some post-processing
    $processed_result = new stdClass();
    $processed_result->created = $result->created;
    $processed_result->data = array();
    foreach ($result->data as $item) {
      foreach ($item as $k => $v) {

        // handle CCK field data structure
        if (strpos($k, 'field_') !== FALSE) {
          $item[$k] = $v[0]['value'];
        }
      }

      // nid will interfere with local nids in client
      $item['remote_nid'] = $item['nid'];
      unset($item['nid']);

      // remote taxonomy is not understood locally so flatten to RSS-style bag of tags (TODO: develop this to preserve vocabs)
      $tags = array();
      if (isset($item['taxonomy'])) {
        foreach ((array) $item['taxonomy'] as $term) {
          $tags = $term['name'];
        }
        unset($item['taxonomy']);
      }
      $item['tags'] = $tags;
      $processed_result->data[] = $item;
    }
    return $processed_result;
  }

  // else method not supported yet
}