You are here

function faq_get_child_categories_faqs in Frequently Asked Questions 5.2

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

Helper function for retrieving the sub-categories faqs.

Parameters

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

$theme_function: Theme function to use to format the Q/A layout for sub-categories.

$default_weight: Is 0 for $default_sorting = DESC; is 1000000 for $default_sorting = ASC.

$default_sorting: If 'DESC', nodes are sorted by creation date descending; if 'ASC', nodes are sorted by creation date ascending.

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

$class: CSS class which the HTML div will be using. A special class name is required in order to hide and questions / answers.

4 calls to faq_get_child_categories_faqs()
theme_faq_category_hide_answer in includes/faq.hide_answer.inc
Create the code of the FAQ page if set to show/hide the category-sorted answers when the question is clicked.
theme_faq_category_new_page in includes/faq.new_page.inc
Create the code of the FAQ page if set to show the answer in a new page when the category-sorted question is clicked.
theme_faq_category_questions_inline in includes/faq.questions_inline.inc
Create the code of the FAQ page if set to show/hide the category-sorted questions inline.
theme_faq_category_questions_top in includes/faq.questions_top.inc
Create the layout of the FAQ page if set to show the questions on top, all sorted by categories.

File

./faq.module, line 1712
The FAQ module allows users to create a FAQ page, with questions and answers displayed in different styles, according to the settings.

Code

function faq_get_child_categories_faqs($term, $theme_function, $default_weight, $default_sorting, $category_display, $class) {
  $output = '';
  $hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
  $list = taxonomy_get_children($term->tid);
  foreach ($list as $tid => $child_term) {
    if (taxonomy_term_count_nodes($child_term->tid, 'faq')) {
      $nodes = array();
      if ($default_sorting == 'DESC') {
        $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, $child_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 ASC", "n", "nid"), $default_weight, $child_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($child_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;
        }
      }

      // Get the taxonomy image.
      $term_image = '';
      if (module_exists('taxonomy_image')) {
        $term_image = taxonomy_image_display($child_term->tid, array(
          'class' => 'faq-tax-image',
        ));
      }

      // Format the sub-category listing.
      $output .= '<div class="faq-category-indent">';
      $output .= theme($theme_function, $nodes, $node_count, 1, $category_display, $child_term, $class, $term_image);
      $output .= '</div>';
    }
  }
  return $output;
}