You are here

function theme_category_hide_answer in Frequently Asked Questions 5

1 theme call to theme_category_hide_answer()
_display_faq_by_category in ./faq.module

File

./faq.module, line 1112

Code

function theme_category_hide_answer($result, $display_vars, $term, $class) {
  $get_sub_terms = 0;
  if (arg(0) == 'faq' && is_numeric(arg(1))) {
    $get_sub_terms = arg(1);
  }
  drupal_add_js(drupal_get_path('module', 'faq') . '/faq.js', 'module');

  // get number of questions, and account for hidden sub-cats
  if ($display_vars['faq_count']) {
    $count = db_num_rows($result);
    if ($display_vars['hide_sub_categories']) {
      $count = taxonomy_term_count_nodes($term->tid, 'faq');
    }
  }

  // configure header
  $hdr = "h5";
  if ($term->depth > 0) {
    $hdr = "h6";
  }
  if ($display_vars['category_display'] == 'hide_qa') {
    $header = "<{$hdr} class=\"faq_header\">";
    $header .= l($term->name, "faq/{$term->tid}");
    if ($display_vars['faq_count']) {
      $header .= " (%d)";
    }
    $header .= "</{$hdr}>\n";
  }
  else {
    $header = "<{$hdr} class=\"faq_header\">";
    $header .= check_plain($term->name);
    if ($display_vars['faq_count']) {
      $header .= " (%d)";
    }
    $header .= "</{$hdr}>\n";
  }
  $desc = '';
  if (!empty($term->description)) {
    $desc = '<div class="faq_qa_description"><p>';
    $desc .= $term->description . "</p></div>\n";
  }

  // get list of sub-categories if necessary
  $sub_cats = '';
  if (($display_vars['show_cat_sub_cats'] || $display_vars['hide_sub_categories']) && $display_vars['category_display'] == 'new_page') {
    $list = taxonomy_get_children($term->tid);
    $scats = array();
    foreach ($list as $tid => $sub_term) {
      $sub_count = taxonomy_term_count_nodes($sub_term->tid, 'faq');
      if ($sub_count) {
        $sub_cat_desc = '';
        if (!empty($sub_term->description)) {
          $sub_cat_desc = '<div class="faq_qa_description"><p>';
          $sub_cat_desc .= $sub_term->description . "</p></div>";
        }
        if ($display_vars['faq_count']) {
          $scats[] = l($sub_term->name, "faq/{$sub_term->tid}") . " ({$sub_count}) {$sub_cat_desc}";
        }
        else {
          $scats[] = l($sub_term->name, "faq/{$sub_term->tid}") . $sub_cat_desc;
        }
      }
    }
    $list_style = variable_get('faq_category_listing', 'ul');
    $sub_cats .= theme('item_list', $scats, NULL, $list_style, array(
      "class" => "faq_category_list",
    ));
  }
  $output = '<div class="faq_category_group">' . "\n";
  if ($display_vars['display_header'] == 1) {
    $output .= '<div class="faq_qa_header">' . $header . $desc . "</div>\n";
  }
  else {
    $output .= '<div class="faq_qa_header">' . $desc . "</div>\n";
  }
  $output .= $sub_cats;
  $sub_cats = '';
  if ($get_sub_terms == $term->tid) {
    $output .= '<div class="faq_qa">' . "\n";
  }
  else {
    $output .= '<div class="' . $class . '">' . "\n";
  }
  if ($get_sub_terms && $display_vars['category_display'] == 'categories_inline' || ($display_vars['show_cat_sub_cats'] || $display_vars['hide_sub_categories']) && $display_vars['category_display'] == 'hide_qa') {
    $list = taxonomy_get_children($term->tid);
    foreach ($list as $tid => $sub_term) {
      if (taxonomy_term_count_nodes($sub_term->tid, 'faq')) {
        $sub_result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.body, r.teaser, r.format, if((w.weight IS NULL), 0, w.weight) as weight FROM {node} n LEFT JOIN {node_revisions} r ON n.nid = r.nid AND r.vid = n.vid 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"), $sub_term->tid);
        $display_vars['display_header'] = 1;
        $sub_cats .= '<div class="faq_category_indent">';
        $sub_cats .= theme('category_hide_answer', $sub_result, $display_vars, $sub_term, $class);
        $sub_cats .= '</div>';
      }
    }
    $output .= $sub_cats;
  }
  if (db_num_rows($result)) {
    $output .= '<div class="faq_dl_hide_answer">' . "\n";
    while ($node = db_fetch_object($result)) {
      $node = node_load($node->nid);
      if (node_access("view", $node)) {
        $output .= '<div class="faq_question faq_dt_hide_answer">';
        $output .= l($node->title, "node/{$node->nid}") . "</div>\n";

        // should we display teaser or full text
        if ($display_vars['use_teaser']) {
          $more_link = '';
          if (!empty($display_vars['more_link']) && strlen($node->teaser) < strlen($node->body)) {
            $more_link = '<p class="faq_more_link">';
            $more_link .= l(t($display_vars['more_link']), "node/{$node->nid}") . '</p>';
          }
          $output .= '<div class="faq_answer faq_dd_hide_answer">';
          $output .= check_markup($node->teaser, $node->format, FALSE);
          $output .= $more_link . "</div>\n";
        }
        else {
          $output .= '<div class="faq_answer faq_dd_hide_answer">';
          $output .= check_markup($node->body, $node->format, FALSE) . "</div>\n";
        }
      }
      else {
        $count--;
      }
    }
    $output .= "</div>\n";
  }
  $output .= "</div>\n</div>\n";
  if ($display_vars['faq_count']) {
    $output = sprintf($output, $count);
  }
  return $output;
}