You are here

public static function ClientsServicesDrupal::call in Web Service Clients 6

Executes call and processes data

Overrides ClientsServicesBase::call

1 call to ClientsServicesDrupal::call()
clients_drupal_clients_call in backends/clients_drupal/clients_drupal.module
Implementation of hook_clients_call

File

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

Class

ClientsServicesDrupal

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
}