You are here

function devel_generate_terms in Devel 6

Same name and namespace in other branches
  1. 5 devel_generate.inc \devel_generate_terms()
  2. 7 devel_generate/devel_generate.inc \devel_generate_terms()
1 call to devel_generate_terms()
devel_generate_taxonomy_data in ./devel_generate.inc

File

./devel_generate.inc, line 129

Code

function devel_generate_terms($records, $vocs, $maxlength = 12) {
  $terms = array();

  // Insert new data:
  for ($i = 1; $i <= $records; $i++) {
    switch ($i % 2) {
      case 1:
        $term['vid'] = $vocs[array_rand($vocs)];

        // dont set a parent. handled by taxonomy_save_term()
        // $term->parent = 0;
        break;
      case 2:
      default:
        $parent = db_fetch_object(db_query_range("SELECT t.tid, v.vid FROM {term_data} t INNER JOIN {vocabulary} v ON t.vid = v.vid ORDER BY RAND()", 0, 1));
        $term['parent'] = array(
          $parent->tid,
        );
        $term['vid'] = $parent->vid;
        break;
    }
    $term['name'] = devel_generate_word(mt_rand(2, $maxlength));
    $term['description'] = "description of " . $term['name'];
    $term['weight'] = mt_rand(0, 10);
    $status = taxonomy_save_term($term);
    $output = NULL;
    if ($status) {
      $terms[] = $term['name'];
    }
    unset($term);
  }
  return $terms;
}