Generic function for getting vocabularies by module
I post it here for the world because CMT will no longer be overriding the vocabulary module names of other module's vocabularies, so Agaric doesn't have a use for it in this form.
It could be useful for other folks though.
I liked overriding the 'module' name part of vocabulary definitions, but as it hasn't proved necessary yet in taking control of the vocabulary from taxonomy module (all the ones I've looked at are treated the same) and I'd have to find a place to store the old module names for uninstalling CMT properly... well, anyone want a barely used function? Cheap!
/**
* Return an array of all vocabulary objects associated with CMT or other specified module.
*
* It might be a good idea to see if this could be merged with taxonomy_get_vocabularies
*
* @param $module
* If set, return only those vocabularies associated with this module. Default cmt.
/
function cmt_get_vocabularies($module = 'cmt') {
$result = db_query(db_rewrite_sql("SELECT v.vid, v., n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE v.module = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $module);
// below identical to taxonomy_get_vocabularies
// couldn't it just use taxonomy_get_vocabulary in a loop?
$vocabularies = array();
$node_types = array();
while ($voc = db_fetch_object($result)) {
$node_types[$voc->vid][] = $voc->type;
unset($voc->type);
$voc->nodes = $node_types[$voc->vid];
$vocabularies[$voc->vid] = $voc;
}
return $vocabularies;
}
I post it here for the world because CMT will no longer be overriding the vocabulary module names of other module's vocabularies, so Agaric doesn't have a use for it in this form.
It could be useful for other folks though.
I liked overriding the 'module' name part of vocabulary definitions, but as it hasn't proved necessary yet in taking control of the vocabulary from taxonomy module (all the ones I've looked at are treated the same) and I'd have to find a place to store the old module names for uninstalling CMT properly... well, anyone want a barely used function? Cheap!
/**
* Return an array of all vocabulary objects associated with CMT or other specified module.
*
* It might be a good idea to see if this could be merged with taxonomy_get_vocabularies
*
* @param $module
* If set, return only those vocabularies associated with this module. Default cmt.
/
function cmt_get_vocabularies($module = 'cmt') {
$result = db_query(db_rewrite_sql("SELECT v.vid, v., n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE v.module = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $module);
// below identical to taxonomy_get_vocabularies
// couldn't it just use taxonomy_get_vocabulary in a loop?
$vocabularies = array();
$node_types = array();
while ($voc = db_fetch_object($result)) {
$node_types[$voc->vid][] = $voc->type;
unset($voc->type);
$voc->nodes = $node_types[$voc->vid];
$vocabularies[$voc->vid] = $voc;
}
return $vocabularies;
}
Comments
Post new comment