You are here

function userpoints_get_vid in User Points 5.3

Same name and namespace in other branches
  1. 6 userpoints.module \userpoints_get_vid()
  2. 7.2 userpoints.module \userpoints_get_vid()
  3. 7 userpoints.module \userpoints_get_vid()
1 call to userpoints_get_vid()
userpoints_get_categories in ./userpoints.module

File

./userpoints.module, line 1670

Code

function userpoints_get_vid() {
  if (!module_exists('taxonomy')) {
    return false;
  }

  //code lovingly inspired by the image.module w/ code by drewish
  $vid = variable_get(USERPOINTS_CATEGORY_DEFAULT_VID, '');
  if (empty($vid) || !taxonomy_get_vocabulary($vid)) {
    $sql = "SELECT vid FROM {vocabulary} WHERE module='userpoints'";
    $vid = db_result(db_query($sql));
    if (!$vid) {
      drupal_set_message(t("Created Userpoints vocabulary"));

      //No vocabulary exists, we'll create one
      $vocab = array(
        'name' => t(USERPOINTS_CATEGORY_NAME),
        'description' => t('Automatically created by the userpoints module'),
        'multiple' => '0',
        'required' => '0',
        'hierarchy' => '1',
        'relations' => '0',
        'module' => 'userpoints',
      );
      taxonomy_save_vocabulary($vocab);
      $vid = $vocab['vid'];
    }
    variable_set(USERPOINTS_CATEGORY_DEFAULT_VID, $vid);
  }
  if (!is_numeric($vid)) {
    watchdog('userpoints', t('userpoints module was unable to select or create a vocabulary. Points will be uncategorized'), WATCHDOG_ERROR);
  }
  return $vid;
}