You are here

function word_link_exchange_import_from_taxonomy in Word Link 7.2

Same name and namespace in other branches
  1. 8 modules/word_link_exchange/word_link_exchange.module \word_link_exchange_import_from_taxonomy()
  2. 7 modules/word_link_exchange/word_link_exchange.module \word_link_exchange_import_from_taxonomy()

Import links from taxonomy terms to DB.

1 string reference to 'word_link_exchange_import_from_taxonomy'
word_link_exchange_import_form_submit in modules/word_link_exchange/word_link_exchange.module
Submit for word_link_exchange_import_form.

File

modules/word_link_exchange/word_link_exchange.module, line 329
Code for the Word link exchange module.

Code

function word_link_exchange_import_from_taxonomy($vid, $limit, $case_sensitive, &$context) {
  if (empty($context['sandbox'])) {
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['max'] = word_link_exchange_get_count_taxonomy_terms($vid);
  }
  if (empty($context['results'])) {
    $context['results']['processed'] = 0;
    $context['results']['created'] = 0;
  }
  $tree = word_link_exchange_get_taxonomy_terms($vid, $context['sandbox']['progress'], $limit);
  foreach ($tree as $term) {
    $exist = word_link_exists($term->name);
    if (!$exist) {
      $value = array(
        'text' => $term->name,
        'case_sensitive' => $case_sensitive !== 'default' ? $case_sensitive : 1,
        'url' => 'taxonomy/term/' . $term->tid,
        'url_title' => $term->name,
        'visibility' => 0,
        'except_list' => NULL,
      );
      word_link_save($value);
      $context['results']['created']++;
    }
    $context['results']['processed']++;
    $context['sandbox']['progress']++;
    $context['message'] = t('Created @created items. Processed @processed items.', array(
      '@created' => $context['results']['created'],
      '@processed' => $context['results']['processed'],
    ));
  }
  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
}