You are here

function document_get_vocid in Document 6

Same name and namespace in other branches
  1. 7 document.inc \document_get_vocid()
  2. 8.x document.inc \document_get_vocid()
4 calls to document_get_vocid()
document_add_type in ./document.callback.inc
document_get_types in ./document.inc
document_get_vocab in ./document.inc
document_install in ./document.install

File

./document.inc, line 42

Code

function document_get_vocid() {
  $vocid = variable_get('document_vocabulary', '');
  if (empty($vocid)) {

    // Check to see if document vocabulary exists
    $vocid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module='document'"));
    if ($vocid) {

      // We found a vocabulary, so make sure it is associated with our content.
      $vocabulary = (array) taxonomy_vocabulary_load($vocid);
      $vocabulary['nodes'] = array(
        'document' => 1,
      );
      $status = taxonomy_save_vocabulary($vocabulary);
    }
    else {

      // Didn't find one, so create vocabulary from scratch.
      $vocabulary = array(
        'name' => 'Document types',
        'multiple' => 0,
        'required' => 1,
        'hierarchy' => 2,
        'relations' => 0,
        'module' => 'document',
        'nodes' => array(
          'document' => 1,
        ),
      );
      $status = taxonomy_save_vocabulary($vocabulary);
      $vocid = $vocabulary['vid'];
    }
    variable_set('document_vocabulary', $vocid);
  }
  return $vocid;
}