summaryrefslogtreecommitdiff
path: root/modules/forum/forum.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/forum/forum.module')
-rw-r--r--modules/forum/forum.module41
1 files changed, 29 insertions, 12 deletions
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index fffd0c76d..c58b5c905 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -1,5 +1,4 @@
<?php
-// $Id$
/**
* @file
@@ -170,12 +169,9 @@ function forum_menu_local_tasks_alter(&$data, $router_item, $root_path) {
$tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0]->tid : 0);
$forum_term = forum_forum_load($tid);
if ($forum_term) {
- $vid = variable_get('forum_nav_vocabulary', 0);
- $vocabulary = taxonomy_vocabulary_load($vid);
-
$links = array();
// Loop through all bundles for forum taxonomy vocabulary field.
- $field = field_info_field('taxonomy_' . $vocabulary->machine_name);
+ $field = field_info_field('taxonomy_forums');
foreach ($field['bundles']['node'] as $type) {
if (node_access('create', $type)) {
$links[$type] = array(
@@ -611,7 +607,7 @@ function forum_form_alter(&$form, $form_state, $form_id) {
// ID from the URL (e.g., if we are on a page like node/add/forum/2, we
// expect "2" to be the ID of the forum that was requested).
$requested_forum_id = arg(3);
- $form['taxonomy_forums'][$langcode]['#default_value'] = is_numeric($requested_forum_id) ? $requested_forum_id : NULL;
+ $form['taxonomy_forums'][$langcode]['#default_value'] = is_numeric($requested_forum_id) ? $requested_forum_id : '';
}
}
}
@@ -880,7 +876,6 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
->addTag('node_access')
->orderBy('f.sticky', 'DESC')
->orderByHeader($forum_topic_list_header)
- ->orderBy('f.last_comment_timestamp', 'DESC')
->limit($forum_per_page);
$count_query = db_select('forum_index', 'f');
@@ -895,7 +890,29 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
$nids[] = $record->nid;
}
if ($nids) {
- $result = db_query("SELECT n.title, n.nid, n.type, n.sticky, n.created, n.uid, n.comment AS comment_mode, ncs.*, f.tid AS forum_tid, u.name, CASE ncs.last_comment_uid WHEN 0 THEN ncs.last_comment_name ELSE u2.name END AS last_comment_name FROM {node} n INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid INNER JOIN {forum} f ON n.vid = f.vid INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {users} u2 ON ncs.last_comment_uid = u2.uid WHERE n.nid IN (:nids)", array(':nids' => $nids));
+ $query = db_select('node', 'n')->extend('TableSort');
+ $query->fields('n', array('title', 'nid', 'type', 'sticky', 'created', 'uid'));
+ $query->addField('n', 'comment', 'comment_mode');
+
+ $query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid');
+ $query->fields('ncs', array('cid', 'last_comment_uid', 'last_comment_timestamp', 'comment_count'));
+
+ $query->join('forum_index', 'f', 'f.nid = ncs.nid');
+ $query->addField('f', 'tid', 'forum_tid');
+
+ $query->join('users', 'u', 'n.uid = u.uid');
+ $query->addField('u', 'name');
+
+ $query->join('users', 'u2', 'ncs.last_comment_uid = u2.uid');
+
+ $query->addExpression('CASE ncs.last_comment_uid WHEN 0 THEN ncs.last_comment_name ELSE u2.name END', 'last_comment_name');
+
+ $query
+ ->orderBy('f.sticky', 'DESC')
+ ->orderByHeader($forum_topic_list_header)
+ ->condition('n.nid', $nids);
+
+ $result = $query->execute();
}
else {
$result = array();
@@ -1194,16 +1211,16 @@ function _forum_user_last_visit($nid) {
function _forum_get_topic_order($sortby) {
switch ($sortby) {
case 1:
- return array('field' => 'ncs.last_comment_timestamp', 'sort' => 'desc');
+ return array('field' => 'f.last_comment_timestamp', 'sort' => 'desc');
break;
case 2:
- return array('field' => 'ncs.last_comment_timestamp', 'sort' => 'asc');
+ return array('field' => 'f.last_comment_timestamp', 'sort' => 'asc');
break;
case 3:
- return array('field' => 'ncs.comment_count', 'sort' => 'desc');
+ return array('field' => 'f.comment_count', 'sort' => 'desc');
break;
case 4:
- return array('field' => 'ncs.comment_count', 'sort' => 'asc');
+ return array('field' => 'f.comment_count', 'sort' => 'asc');
break;
}
}