You are here

function faq_get_child_categories_faqs in Frequently Asked Questions 7.2

Same name and namespace in other branches
  1. 5.2 faq.module \faq_get_child_categories_faqs()
  2. 6 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 object: The category / term to display FAQs for.

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

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

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

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

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

$parent_term string: The original, top-level, term we're displaying FAQs for.

Return value

string

5 calls to faq_get_child_categories_faqs()
template_preprocess_faq_category_hide_answer in includes/faq.hide_answer.inc
Create categorized FAQ page if set to show answer when question is clicked.
template_preprocess_faq_category_new_page in includes/faq.new_page.inc
Create categorized FAQ page if set to show answer in a new page.
template_preprocess_faq_category_questions_inline in includes/faq.questions_inline.inc
Create categorized FAQ page if set to show/hide the questions inline.
template_preprocess_faq_category_questions_top in includes/faq.questions_top.inc
Create categorized questions for FAQ page if set to show questions on top.
template_preprocess_faq_category_questions_top_answers in includes/faq.questions_top.inc
Create categorized answers for FAQ page if set to show the questions on top.

File

./faq.module, line 1215
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, $parent_term = NULL) {
  $output = array();
  $list = taxonomy_get_children($term->tid);
  if (!is_array($list)) {
    return '';
  }
  foreach ($list as $tid => $child_term) {
    $child_term->depth = $term->depth + 1;
    if (faq_taxonomy_term_count_nodes($child_term->tid)) {
      $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", $child_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);
      $output[] = theme($theme_function, array(
        'data' => $data,
        'display_header' => 1,
        'category_display' => $category_display,
        'term' => $child_term,
        'class' => $class,
        'parent_term' => $parent_term,
      ));
    }
  }
  return $output;
}