function _display_faq_by_category in Frequently Asked Questions 7.2
Same name and namespace in other branches
- 5.2 faq.module \_display_faq_by_category()
- 5 faq.module \_display_faq_by_category()
- 6 faq.module \_display_faq_by_category()
- 7 faq.module \_display_faq_by_category()
Display FAQ questions and answers filtered by category.
Parameters
$faq_display string: Define the way the FAQ is being shown; can have the values: 'questions top',hide answers','questions inline','new page'.
$category_display string: The layout of categories which should be used.
$term object: The category / term to display FAQs for.
$display_header int: Set if the header will be shown or not.
&$output string: Reference which holds the content of the page, HTML formatted.
&$output_answers string: Reference which holds the answers from the FAQ, when showing questions on top.
1 call to _display_faq_by_category()
- new_faq_page in ./
faq.module - Function to display the faq page.
File
- ./
faq.module, line 641 - The FAQ module allows users to create a FAQ page, with questions and answers displayed in different styles, according to the settings.
Code
function _display_faq_by_category($faq_display, $category_display, $term, $display_header, &$output, &$output_answers) {
$default_sorting = variable_get('faq_default_sorting', 'DESC');
$query = db_select('node', 'n');
$ti_alias = $query
->innerJoin('taxonomy_index', 'ti', '(n.nid = %alias.nid)');
$td_alias = $query
->innerJoin('taxonomy_term_data', 'td', "({$ti_alias}.tid = %alias.tid)");
$w_alias = $query
->leftJoin('faq_weights', 'w', "%alias.tid = {$ti_alias}.tid AND n.nid = %alias.nid");
$query
->fields('n', array(
'nid',
))
->condition('n.type', 'faq')
->condition('n.status', 1)
->condition("{$ti_alias}.tid", $term->tid)
->addTag('node_access');
$default_weight = 0;
if ($default_sorting == 'ASC') {
$default_weight = 1000000;
}
// Works, but involves variable concatenation - safe though, since
// $default_weight is an integer.
$query
->addExpression("COALESCE(w.weight, {$default_weight})", 'effective_weight');
// Doesn't work in Postgres.
//$query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight));
$query
->orderBy('effective_weight', 'ASC')
->orderBy('n.sticky', 'DESC');
if ($default_sorting == 'ASC') {
$query
->orderBy('n.created', 'ASC');
}
else {
$query
->orderBy('n.created', 'DESC');
}
if (module_exists('i18n_select')) {
$query
->condition('n.language', i18n_select_langcodes());
$query
->condition("{$td_alias}.language", i18n_select_langcodes());
}
// We only want the first column, which is nid, so that we can load all
// related nodes.
$nids = $query
->execute()
->fetchCol();
$data = node_load_multiple($nids);
// Handle indenting of categories.
$depth = 0;
if (!isset($term->depth)) {
$term->depth = 0;
}
while ($depth < $term->depth) {
$display_header = 1;
$indent = '<div class="faq-category-indent">';
$output .= $indent;
$depth++;
}
// Set up the class name for hiding the q/a for a category if required.
$faq_class = "faq-qa";
if ($category_display == "hide_qa") {
$faq_class = "faq-qa-hide";
}
$faq_path = drupal_get_path('module', 'faq') . '/includes';
switch ($faq_display) {
case 'questions_top':
include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.questions_top.inc';
// @todo fix workaround: have to share result.
$output .= theme('faq_category_questions_top', array(
'data' => $data,
'display_header' => $display_header,
'category_display' => $category_display,
'term' => $term,
'class' => $faq_class,
'parent_term' => $term,
));
$output_answers .= theme('faq_category_questions_top_answers', array(
'data' => $data,
'display_header' => $display_header,
'category_display' => $category_display,
'term' => $term,
'class' => $faq_class,
'parent_term' => $term,
));
break;
case 'hide_answer':
include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.hide_answer.inc';
$output .= theme('faq_category_hide_answer', array(
'data' => $data,
'display_header' => $display_header,
'category_display' => $category_display,
'term' => $term,
'class' => $faq_class,
'parent_term' => $term,
));
break;
case 'questions_inline':
include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.questions_inline.inc';
$output .= theme('faq_category_questions_inline', array(
'data' => $data,
'display_header' => $display_header,
'category_display' => $category_display,
'term' => $term,
'class' => $faq_class,
'parent_term' => $term,
));
break;
case 'new_page':
include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.new_page.inc';
$output .= theme('faq_category_new_page', array(
'data' => $data,
'display_header' => $display_header,
'category_display' => $category_display,
'term' => $term,
'class' => $faq_class,
'parent_term' => $term,
));
break;
}
// Handle indenting of categories.
while ($depth > 0) {
$output .= '</div>';
$depth--;
}
}