function userpoints_get_vid in User Points 7
Same name and namespace in other branches
- 5.3 userpoints.module \userpoints_get_vid()
- 6 userpoints.module \userpoints_get_vid()
- 7.2 userpoints.module \userpoints_get_vid()
Returns the Vocabulary ID (vid) used by userpoints for categorization.
If no vocab exists it will create one.
2 calls to userpoints_get_vid()
- UserpointsAPITestCase::testGetDefaultTid in tests/
userpoints_api.test - Test the default term id.
- userpoints_get_categories in ./
userpoints.module - Returns an array of possible categories, suitable for inclusion in FAPI.
File
- ./
userpoints.module, line 1606
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_vocabulary_load($vid)) {
$sql = "SELECT vid FROM {taxonomy_vocabulary} WHERE module='userpoints'";
$vid = db_query($sql)
->fetchField();
if (!$vid) {
drupal_set_message(t("Created Userpoints vocabulary"));
// No vocabulary exists, we'll create one.
$vocab = (object) array(
'name' => USERPOINTS_CATEGORY_NAME,
'description' => t('Automatically created by the userpoints module'),
'machine_name' => 'userpoints',
'multiple' => '0',
'required' => '0',
'hierarchy' => '1',
'relations' => '0',
'module' => 'userpoints',
);
taxonomy_vocabulary_save($vocab);
$vid = $vocab->vid;
}
variable_set(USERPOINTS_CATEGORY_DEFAULT_VID, $vid);
}
if (!is_numeric($vid)) {
watchdog('userpoints', 'userpoints module was unable to select or create a vocabulary. !Points will be uncategorized', array(), WATCHDOG_ERROR);
}
return $vid;
}