User login

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

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.