You are here

function _display_faq_by_category in Frequently Asked Questions 5.2

Same name and namespace in other branches
  1. 5 faq.module \_display_faq_by_category()
  2. 6 faq.module \_display_faq_by_category()
  3. 7.2 faq.module \_display_faq_by_category()
  4. 7 faq.module \_display_faq_by_category()

Display FAQ questions and answers filtered by category.

Parameters

$faq_display: Define the way the FAQ is being shown; can have the values: 'questions top',hide answers','questions inline','new page'.

$category_display: The layout of categories which should be used.

$term: The category / term to display FAQs for.

$display_header: Set if the header will be shown or not.

&$output: Reference which holds the content of the page, HTML formatted.

&$output_answer: Reference which holds the answers from the FAQ, when showing questions on top.

1 call to _display_faq_by_category()
faq_page in ./faq.module
Function to display the faq page.

File

./faq.module, line 994
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) {
  $nodes = array();
  $hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
  $default_sorting = variable_get('faq_default_sorting', 'DESC');
  $default_weight = 0;
  if ($default_sorting != 'DESC') {
    $default_weight = 1000000;
    $result = db_query(db_rewrite_sql("SELECT n.nid, if((w.weight IS NULL), %d, w.weight) as weight, n.sticky, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid LEFT JOIN {faq_weights} w ON w.tid = tn.tid AND n.nid = w.nid WHERE n.type='faq' AND n.status = 1 AND tn.tid = '%d' ORDER BY weight, n.sticky DESC, n.created ASC", "n", "nid"), $default_weight, $term->tid);
  }
  else {
    $result = db_query(db_rewrite_sql("SELECT n.nid, if((w.weight IS NULL), %d, w.weight) as weight, n.sticky, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid LEFT JOIN {faq_weights} w ON w.tid = tn.tid AND n.nid = w.nid WHERE n.type='faq' AND n.status = 1 AND tn.tid = '%d' ORDER BY weight, n.sticky DESC, n.created DESC", "n", "nid"), $default_weight, $term->tid);
  }

  // Get number of questions, and account for hidden sub-categories.
  $node_count = db_num_rows($result);
  if ($hide_child_terms) {
    $node_count = taxonomy_term_count_nodes($term->tid, 'faq');
  }

  // Save the nodes for output.
  while ($row = db_fetch_object($result)) {
    $node = node_load($row->nid);
    if (node_access("view", $node)) {
      $nodes[] = $node;
    }
    else {
      $node_count--;
    }
  }

  // Handle indenting of categories.
  $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";
  }

  // Get the taxonomy image.
  $term_image = '';
  if (module_exists('taxonomy_image')) {
    $term_image = taxonomy_image_display($term->tid, array(
      'class' => 'faq-tax-image',
    ));
  }
  $faq_path = drupal_get_path('module', 'faq') . '/includes';
  switch ($faq_display) {
    case 'questions_top':
      include_once $faq_path . '/faq.questions_top.inc';
      $output .= theme('faq_category_questions_top', $nodes, $node_count, $display_header, $category_display, $term, $faq_class, $term_image);
      $group_questions_top = variable_get('faq_group_questions_top', FALSE);
      if ($category_display != 'hide_qa' && $group_questions_top == FALSE) {
        $output_answers .= theme('faq_category_questions_top_answers', $nodes, $node_count, $display_header, $category_display, $term, $faq_class, $term_image);
      }
      break;
    case 'hide_answer':
      include_once $faq_path . '/faq.hide_answer.inc';
      $output .= theme('faq_category_hide_answer', $nodes, $node_count, $display_header, $category_display, $term, $faq_class, $term_image);
      break;
    case 'questions_inline':
      include_once $faq_path . '/faq.questions_inline.inc';
      $output .= theme('faq_category_questions_inline', $nodes, $node_count, $display_header, $category_display, $term, $faq_class, $term_image);
      break;
    case 'new_page':
      include_once $faq_path . '/faq.new_page.inc';
      $output .= theme('faq_category_new_page', $nodes, $node_count, $display_header, $category_display, $term, $faq_class, $term_image);
      break;
  }

  // End of switch (faq_display).
  // Handle indenting of categories.
  while ($depth > 0) {
    $output .= '</div>';
    $depth--;
  }
}