You are here

function faq_get_faq_list in Frequently Asked Questions 5.2

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

Format the output for the faq_site_map() function.

Return value

Return a list of FAQ categories if categorization is enabled, otherwise return a list of faq nodes.

File

./faq.module, line 1366
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_faq_list() {

  // Return list of vocab terms if categories are configured.
  $use_categories = variable_get('faq_use_categories', FALSE);
  if ($use_categories) {
    return faq_get_terms();
  }

  // Otherwise return list of weighted FAQ nodes.
  $items = array();
  $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 LEFT JOIN {faq_weights} w ON w.nid = n.nid WHERE n.type='faq' AND n.status = 1 AND (w.tid = 0 OR w.tid IS NULL) ORDER BY weight, n.sticky DESC, n.created ASC", "n", "nid"), $default_weight);
  }
  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 LEFT JOIN {faq_weights} w ON w.nid = n.nid WHERE n.type='faq' AND n.status = 1 AND (w.tid = 0 OR w.tid IS NULL) ORDER BY weight, n.sticky DESC, n.created DESC", "n", "nid"), $default_weight);
  }
  while ($row = db_fetch_object($result)) {
    $node = node_load($row->nid);
    if (node_access("view", $node)) {
      $items[] = l($node->question, "node/{$node->nid}");
    }
  }
  return theme('item_list', $items);
}