You are here

function _cmis_sync_drupal_to_cmis_prepare in CMIS API 6.2

Maps a drupal node to a cmis_object

Parameters

$node:

Return value

stdClass $cmis_object wrapper

1 call to _cmis_sync_drupal_to_cmis_prepare()
cmis_sync_nodeapi in cmis_sync/cmis_sync.module
Implementation of hook_nodeapi() for CMIS sync module.

File

cmis_sync/cmis_sync.module, line 191

Code

function _cmis_sync_drupal_to_cmis_prepare($node) {
  $sync_map = variable_get('cmis_sync_map', array());

  // Is cmis sync enabled for this node type?
  if ($sync_map[$node->type] && $sync_map[$node->type]['enabled']) {
    $cmis_object = new stdClass();

    // CMIS destination type
    $cmis_object->type = $sync_map[$node->type]['cmis_type'];

    // CMIS destination folder id
    $cmis_object->parentId = drupal_urlencode($sync_map[$node->type]['cmis_root']);

    // Map Drupal node fields to cmis object properties
    $cmis_object->properties = array(
      'title' => $node->title,
    );
    foreach ($sync_map[$node->type]['fields'] as $drupal_field => $cmis_field) {
      if (is_string($cmis_field)) {
        $cmis_object->properties[$cmis_field] = _cmis_sync_node_field_value($nodem, $drupal_field);
      }
      elseif (is_array($cmis_field)) {
        if (array_key_exists('drupal to cmis', $cmis_field) && $cmis_field['drupal to cmis'] === False) {
          continue;
        }
        $cmis_object->properties[$cmis_field['cmis']] = _cmis_sync_node_field_value($node, $cmis_field['drupal']);
      }
      else {
        throw new CMISException(t('Unknown field map type. Expects "string" or "array". Received @type', array(
          '@type' => gettype($cmis_field),
        )));
      }
    }

    // Map Drupal node field as object's content
    if (array_key_exists('content_field', $sync_map[$node->type])) {
      $cmis_object->content = _cmis_sync_node_field_value($node, $sync_map[$node->type]['content_field']);

      // Setting content's content-type
      $cmis_object->properties['content-type'] = 'text/html';
      $content_type = content_types($node->type);
      $content_field_name = $sync_map[$node->type]['content_field'];
      if (array_key_exists($content_field_name, $content_type['fields'])) {
        if ($content_type['fields'][$content_field_name]['type'] == 'filefield') {
          $content_field = $node->{$content_field_name};
          $cmis_object->properties['content-type'] = $content_field[0]['filemime'];
        }
      }
    }

    // Sync deletes flag
    $cmis_object->sync_deletes = $sync_map[$node->type]['deletes'];
    return $cmis_object;
  }
  return FALSE;
}