function faq_get_faq_list in Frequently Asked Questions 7
Same name and namespace in other branches
- 5.2 faq.module \faq_get_faq_list()
- 5 faq.module \faq_get_faq_list()
- 6 faq.module \faq_get_faq_list()
- 7.2 faq.module \faq_get_faq_list()
Format the output for the faq_site_map() function.
Return value
array Return a list of FAQ categories if categorization is enabled, otherwise return a list of faq nodes.
File
- ./
faq.module, line 1093 - 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');
$query = db_select('node', 'n');
$w_alias = $query
->leftJoin('faq_weights', 'w', "%alias.nid = n.nid");
$query
->fields('n', array(
'nid',
))
->condition('n.type', 'faq')
->condition('n.status', 1)
->condition(db_or()
->condition("{$w_alias}.tid", 0)
->isNull("{$w_alias}.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');
// @codingStandardsIgnoreStart
// @todo Doesn't work in Postgres.
//$query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight));
// @codingStandardsIgnoreEnd
$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());
}
// We only want the first column, which is nid, so that we can load all
// related nodes.
$nids = $query
->execute()
->fetchCol();
$nodes = node_load_multiple($nids);
foreach ($nodes as $node) {
if (node_access('view', $node)) {
$items[] = l($node->title, "node/{$node->nid}");
}
}
return theme('item_list', array(
'items' => $items,
));
}