You are here

function gathercontent_get_destination_node in GatherContent 7.3

Parameters

int $gathercontent_id: ID of item in GatherContent.

string $node_update_method: Name of the node update method.

int $node_type_id: ID of the node type.

Return value

EntityMetadataWrapper

1 call to gathercontent_get_destination_node()
_gathercontent_fetcher in ./gathercontent.module
Helper function for fetching data from GatherContent.

File

./gathercontent.module, line 632

Code

function gathercontent_get_destination_node($gathercontent_id, $node_update_method, $node_type_id) {
  switch ($node_update_method) {
    case 'update_if_not_changed':
      $query = new EntityFieldQuery();
      $query
        ->entityCondition('entity_type', 'node')
        ->propertyCondition('gathercontent_id', $gathercontent_id)
        ->propertyOrderBy('created', 'DESC')
        ->range(0, 1);
      $result = $query
        ->execute();
      if (!empty($result['node'])) {
        $node = node_load(reset($result['node'])->nid);
        $operation_query = new EntityFieldQuery();
        $operation_query
          ->entityCondition('entity_type', 'gathercontent_operation_item')
          ->propertyCondition('gathercontent_id', $gathercontent_id)
          ->propertyOrderBy('created', 'DESC')
          ->range(0, 1);
        $o_result = $operation_query
          ->execute();
        $operation_item = entity_load('gathercontent_operation_item', reset($o_result['gathercontent_operation_item']));
        $operation_item = reset($operation_item);
        if ($node->changed === $operation_item->changed) {
          return entity_metadata_wrapper('node', $node);
        }
      }
      break;
    case 'always_update':
      $query = new EntityFieldQuery();
      $query
        ->entityCondition('entity_type', 'node')
        ->propertyCondition('gathercontent_id', $gathercontent_id)
        ->propertyOrderBy('created', 'DESC')
        ->range(0, 1);
      $result = $query
        ->execute();
      if (!empty($result['node'])) {
        return entity_metadata_wrapper('node', reset($result['node'])->nid);
      }
      break;
  }
  return entity_metadata_wrapper('node', entity_create('node', [
    'type' => $node_type_id,
  ]));
}