function glossary_get_related in Glossary 7
Same name and namespace in other branches
- 5.2 glossary.module \glossary_get_related()
- 6 glossary.module \glossary_get_related()
Find all term objects related to a given term ID Adapted frm taxonomy.module.
Parameters
int $tid: the term id to look up.
bool $one_way: whether to do one-way or two-way relations.
Return value
array an array related-tid => related-name
1 call to glossary_get_related()
- theme_glossary_block_term in ./
glossary.module - @todo Please document this function.
File
- ./
glossary.module, line 1215 - Glossary terms will be automatically marked with links to their descriptions.
Code
function glossary_get_related($tid, $key = 'tid', $one_way = FALSE) {
// D7 doesn't really support relationships.
return array();
if ($tid) {
$related = array();
$qargs = array_fill(0, 3, $tid);
if ($one_way) {
$result = db_query('SELECT r.tid2 FROM {taxonomy_term_relation} r WHERE r.tid1 = :r.tid1 ORDER BY r.tid2', array(
':r.tid1' => $qargs,
));
foreach ($result as $term) {
// Hope that taxonomy has this cached to save a query.
$rel = taxonomy_term_load($term->tid2);
$related[$rel->{$key}] = $rel;
}
}
else {
// Two-way (normal taxonomy function).
// $result = db_query('SELECT t.*, tid1, tid2 FROM {taxonomy_term_relation
// }, {taxonomy_term_data} t WHERE (t.tid = :(t.tid OR t.tid = :t.tid AND
// (tid1 = :(tid1 OR tid2 = :tid2)AND t.tid != :t.tid ORDER BY weight,
// name', array(':(t.tid' => 'tid1', ':t.tid' => 'tid2', ':(tid1' =>
// $qargs));
// foreach ($result as $term) {
// $related[$term->$key] = $term;
// }
}
return $related;
}
else {
return array();
}
}