You are here

function _biblio_feeds_set__type_target in Bibliography Module 7

Same name and namespace in other branches
  1. 7.2 includes/biblio.feeds.inc \_biblio_feeds_set__type_target()
1 string reference to '_biblio_feeds_set__type_target'
_biblio_feeds_processor_targets_alter in includes/biblio.feeds.inc

File

includes/biblio.feeds.inc, line 43

Code

function _biblio_feeds_set__type_target($source, $entity, $target, $value) {
  static $types = array();
  if (empty($value)) {
    return;
  }

  // Handle non-multiple value fields.
  if (!is_array($value)) {
    $value = array(
      $value,
    );
  }
  if (isset($value[0]) && !empty($value[0])) {
    if (intval($value[0]) > 0) {

      // value[0] is the bibio type ID.
      if (empty($types)) {
        $result = db_query('SELECT t.* FROM {biblio_types} as t WHERE t.tid > 0');
        foreach ($result as $row) {
          $types[$row->tid] = $row->tid;
        }
      }
      $type_id = $value[0];
      $entity->biblio_type = isset($types[$type_id]) ? $type_id : 129;
    }
    elseif (is_string($value[0])) {

      // value[0] is the bibio type name.
      if (empty($types)) {
        $result = db_query('SELECT t.* FROM {biblio_types} as t WHERE t.tid > 0');
        foreach ($result as $row) {
          $types[$row->tid] = str_replace(" ", "_", strtolower($row->name));
        }
      }
      $type = array_search($value[0], $types);
      $entity->biblio_type = !empty($type) ? $type : 129;
    }
  }
}