You are here

function _fe_taxonomy_save_term in Features Extra 6

Save a term.

1 call to _fe_taxonomy_save_term()
_fe_taxonomy_save_term_tree in ./fe_taxonomy.module
Save a term tree.

File

./fe_taxonomy.module, line 447

Code

function _fe_taxonomy_save_term($settings = array()) {
  if (empty($settings['vid']) || empty($settings['name'])) {
    return FALSE;
  }

  // Don't count those I have saved/updated.
  static $tid_array = array();
  if (empty($settings['tid'])) {
    $placeholders = db_placeholders($tid_array);
    $args = array(
      $settings['name'],
      $settings['vid'],
    ) + $tid_array;

    // TODO
    // Try to find a same term, and avoid using it twice.
    $tid = db_result(db_query("SELECT tid FROM {term_data} WHERE UPPER(TRIM(name)) = UPPER('%s') AND vid = %d AND tid NOT IN ()", $args));
    if (!empty($tid)) {
      $settings['tid'] = $tid;
    }
  }

  // Default
  $default_settings = array(
    'description' => '',
    'weight' => 0,
    'relations' => array(),
    'parent' => array(
      0,
    ),
    'synonyms' => '',
  );
  $settings = array_merge($default_settings, $settings);
  taxonomy_save_term($settings);
  if (empty($settings['tid'])) {
    return FALSE;
  }
  $tid_array[] = $settings['tid'];
  return $settings;
}