From f614337627ac7b6553cf3c6cdb50a3d9d9fe33a3 Mon Sep 17 00:00:00 2001 From: Ludovic Arnaud Date: Wed, 17 Sep 2003 22:13:23 +0000 Subject: [PATCH] Fixed: announcements being listed last Changed: moved up the announcements query a little, rows are stored in the order they're fetched, the final order of topics is in $topic_list. Will be easier if we come to prefetching topics git-svn-id: file:///svn/phpbb/trunk@4509 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/viewforum.php | 91 ++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 0100f5e94f..06849cd877 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -41,8 +41,8 @@ if (!$forum_id) // Grab appropriate forum data if ($user->data['user_id'] == ANONYMOUS) { - $sql = 'SELECT * - FROM ' . FORUMS_TABLE . ' + $sql = 'SELECT * + FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $forum_id; } else @@ -246,7 +246,7 @@ if ($forum_data['forum_type'] == FORUM_POST) $template->assign_vars(array( 'PAGINATION' => generate_pagination("viewforum.$phpEx$SID&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir", $topics_count, $config['topics_per_page'], $start), - 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start), + 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start), 'TOTAL_TOPICS' => ($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count), 'MOD_CP' => ($auth->acl_gets('m_', $forum_id)) ? sprintf($user->lang['MCP'], "session_id&f=$forum_id&mode=forum_view\">", '') : '', 'MODERATORS' => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '', @@ -287,10 +287,8 @@ if ($forum_data['forum_type'] == FORUM_POST) $icons = array(); obtain_icons($icons); - // Grab all topic data - $total_topics = 0; - $rowset = array(); + $rowset = $announcement_list = $topic_list = array(); switch (SQL_LAYER) { @@ -304,23 +302,7 @@ if ($forum_data['forum_type'] == FORUM_POST) $sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1'; $sql_select = (($config['load_db_lastread'] || $config['load_db_track']) && $user->data['user_id'] != ANONYMOUS) ? ', tt.mark_type, tt.mark_time' : ''; - // If the user is trying to reach late pages, start searching from the end - $store_reverse = FALSE; - $limit = $config['topics_per_page']; - - if ($start > $topics_count / 2) - { - $store_reverse = TRUE; - - if ($start + $config['topics_per_page'] > $topics_count) - { - $limit = min($config['topics_per_page'], max(1, $topics_count - $start)); - } - - $sql_sort_order = preg_replace('/(ASC|DESC)/e', "('\$1' == 'ASC') ? 'DESC' : 'ASC'", $sql_sort_order); - $start = max(0, $topics_count - $limit - $start); - } - + // Obtain announcements $sql = "SELECT t.* $sql_select FROM $sql_from WHERE t.forum_id IN ($forum_id, 0) @@ -328,20 +310,35 @@ if ($forum_data['forum_type'] == FORUM_POST) ORDER BY $sql_sort_order"; $result = $db->sql_query($sql); - while($row = $db->sql_fetchrow($result)) + while ($row = $db->sql_fetchrow($result)) { - if ($store_reverse) - { - array_unshift($rowset, $row); - } - else - { - $rowset[] = $row; - } - $total_topics++; + $rowset[$row['topic_id']] = $row; + $announcement_list[] = $row['topic_id']; } $db->sql_freeresult($result); + // If the user is trying to reach late pages, start searching from the end + $store_reverse = FALSE; + $sql_limit = $config['topics_per_page']; + + if ($start > $topics_count / 2) + { + $store_reverse = TRUE; + + if ($start + $config['topics_per_page'] > $topics_count) + { + $sql_limit = min($config['topics_per_page'], max(1, $topics_count - $start)); + } + + $sql_sort_order = preg_replace('/(ASC|DESC)/e', "('\$1' == 'ASC') ? 'DESC' : 'ASC'", $sql_sort_order); + $sql_start = max(0, $topics_count - $sql_limit - $start); + } + else + { + $sql_start = $start; + } + + // Obtain other topics $sql = "SELECT t.* $sql_select FROM $sql_from WHERE t.forum_id = $forum_id @@ -349,24 +346,26 @@ if ($forum_data['forum_type'] == FORUM_POST) $sql_approved $sql_limit_time ORDER BY t.topic_type DESC, $sql_sort_order"; - $result = $db->sql_query_limit($sql, $limit, $start); + $result = $db->sql_query_limit($sql, $sql_limit, $sql_start); while($row = $db->sql_fetchrow($result)) { - if ($store_reverse) - { - array_unshift($rowset, $row); - } - else - { - $rowset[] = $row; - } - $total_topics++; + $rowset[$row['topic_id']] = $row; + $topic_list[] = $row['topic_id']; } $db->sql_freeresult($result); + if ($store_reverse) + { + $topic_list = array_merge($announcement_list, array_reverse($topic_list)); + } + else + { + $topic_list = array_merge($announcement_list, $topic_list); + } + // Okay, lets dump out the page ... - if ($total_topics) + if (count($topic_list)) { if ($config['load_db_lastread']) { @@ -380,9 +379,9 @@ if ($forum_data['forum_type'] == FORUM_POST) $mark_forum_read = true; $i = $s_type_switch = 0; - foreach ($rowset as $key => $row) + foreach ($topic_list as $topic_id) { - $topic_id = $row['topic_id']; + $row =& $rowset[$topic_id]; if ($config['load_db_lastread']) {