function _get_indented_faq_terms in Frequently Asked Questions 7.2
Same name and namespace in other branches
- 5.2 faq.module \_get_indented_faq_terms()
- 5 faq.module \_get_indented_faq_terms()
- 6 faq.module \_get_indented_faq_terms()
- 7 faq.module \_get_indented_faq_terms()
Return a HTML formatted list of terms indented according to the term depth.
Parameters
$vid int: Vocabulary id.
$tid int: Term id.
Return value
string Return a HTML formatted list of terms indented according to the term depth.
2 calls to _get_indented_faq_terms()
- faq_get_terms in ./
faq.module - Get a list of terms associated with the FAQ nodes.
- new_faq_page in ./
faq.module - Function to display the faq page.
File
- ./
faq.module, line 865 - The FAQ module allows users to create a FAQ page, with questions and answers displayed in different styles, according to the settings.
Code
function _get_indented_faq_terms($vid, $tid) {
if (module_exists('pathauto')) {
module_load_include('inc', 'pathauto');
}
$display_faq_count = variable_get('faq_count', FALSE);
$hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
$items = array();
$tree = taxonomy_get_tree($vid, $tid, 1, TRUE);
foreach ($tree as $term) {
$tree_count = faq_taxonomy_term_count_nodes($term->tid);
if ($tree_count) {
// Get taxonomy image.
$term_image = '';
if (module_exists('taxonomy_image')) {
$term_image = taxonomy_image_display($term->tid, array(
'class' => 'faq-tax-image',
));
}
// Get term description.
$desc = '';
if (!empty($term->description)) {
$desc = '<div class="faq-qa-description">';
$desc .= check_markup(faq_tt("taxonomy:term:{$term->tid}:description", $term->description), $term->format) . "</div>";
}
// See if this term has any nodes itself, should it be a link?
$query = db_select('node', 'n');
$ti_alias = $query
->innerJoin('taxonomy_index', 'ti', '(n.nid = %alias.nid)');
$term_node_count = $query
->condition('n.status', 1)
->condition('n.type', 'faq')
->condition("{$ti_alias}.tid", $term->tid)
->addTag('node_access')
->countQuery()
->execute()
->fetchField();
if ($term_node_count > 0) {
$path = "faq-page/{$term->tid}";
if (!drupal_lookup_path('alias', arg(0) . '/' . $term->tid) && module_exists('pathauto')) {
$alias = pathauto_create_alias('faq', 'insert', arg(0) . '/' . $term->tid, array(
'term' => $term,
));
if ($alias) {
$path = $alias['alias'];
}
}
if ($display_faq_count) {
$count = $term_node_count;
if ($hide_child_terms) {
$count = $tree_count;
}
$cur_item = $term_image . l(faq_tt("taxonomy:term:{$term->tid}:name", $term->name), $path) . " ({$count}) " . $desc;
}
else {
$cur_item = $term_image . l(faq_tt("taxonomy:term:{$term->tid}:name", $term->name), $path) . $desc;
}
}
else {
$cur_item = $term_image . check_plain(faq_tt("taxonomy:term:{$term->tid}:name", $term->name)) . $desc;
}
if (!empty($term_image)) {
$cur_item .= '<div class="clear-block"></div>';
}
$term_items = array();
if (!$hide_child_terms) {
$term_items = _get_indented_faq_terms($vid, $term->tid);
}
$items[] = array(
"data" => $cur_item,
"children" => $term_items,
);
}
}
return $items;
}