Changing the Order of Topics [message #166930] |
Sat, 31 March 2012 10:26 |
|
bbnewbie
Messages: 27 Registered: December 2011
Karma:
|
Junior Member |
|
|
My goal is to have the topics displayed by the date the topic started, not by the date the thread was updated. I found an old thread that got me most of the way there, but I'd love some help on specifically what code to change to reroder based on the topic creation date rather than the last updated message date
http://fudforum.org/forum/index.php?t=msg&goto=38695&&srch=chan ging+the+order+of+topics#msg_38695
I know the code is here if anyone can help out. Thanks!
function th_new_rebuild($forum_id, $th, $sticky)
{
if (__th_cron_emu($forum_id)) {
return;
}
if (!db_locked()) {
$ll = 1;
db_lock('{SQL_TABLE_PREFIX}tv_'. $forum_id .' WRITE');
}
list($max,$iss) = db_saq(q_limit('SELECT /* USE MASTER */ seq, iss FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' ORDER BY seq ASC', 1));
if ((!$sticky && $iss) || $iss >= { /* Sub-optimal case, non-sticky topic and thre are stickies in the forum. */
/* Find oldest sticky message. */
if ($sticky && $iss >= {
$iss = q_singleval(q_limit('SELECT /* USE MASTER */ seq FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' WHERE seq>'. ($max - 50) .' AND iss>=8 ORDER BY seq ASC', 1));
} else {
$iss = q_singleval(q_limit('SELECT /* USE MASTER */ seq FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' WHERE seq>'. ($max - 50) .' AND iss>0 ORDER BY seq ASC', 1));
}
/* Move all stickies up one. */
q('UPDATE {SQL_TABLE_PREFIX}tv_'. $forum_id .' SET seq=seq+1 WHERE seq>='. $iss);
/* We do this, since in optimal case we just do ++max. */
$max = --$iss;
}
q('INSERT INTO {SQL_TABLE_PREFIX}tv_'. $forum_id .' (thread_id,iss,seq) VALUES('. $th .','. (int)$sticky .','. (++$max) .')');
if (isset($ll)) {
db_unlock();
}
}
function th_reply_rebuild($forum_id, $th, $sticky)
{
if (!db_locked()) {
$ll = 1;
db_lock('{SQL_TABLE_PREFIX}tv_'. $forum_id .' WRITE');
}
/* Get first topic of forum (highest seq). */
list($max,$tid,$iss) = db_saq(q_limit('SELECT /* USE MASTER */ seq,thread_id,iss FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' ORDER BY seq ASC', 1));
if ($tid == $th) {
/* NOOP: quick elimination, topic is already 1st. */
} else if (!$iss || ($sticky && $iss < ) { /* Moving to the very top. */
/* Get position. */
$pos = q_singleval('SELECT /* USE MASTER */ seq FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' WHERE thread_id='. $th);
/* Move everyone ahead, 1 down. */
q('UPDATE {SQL_TABLE_PREFIX}tv_'. $forum_id .' SET seq=seq-1 WHERE seq>'. $pos);
/* Move to top of the stack. */
q('UPDATE {SQL_TABLE_PREFIX}tv_'. $forum_id .' SET seq='. $max .' WHERE thread_id='. $th);
} else {
/* Get position. */
$pos = q_singleval('SELECT /* USE MASTER */ seq FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' WHERE thread_id='. $th);
/* Find oldest sticky message. */
$iss = q_singleval(q_limit('SELECT /* USE MASTER */ seq FROM {SQL_TABLE_PREFIX}tv_'. $forum_id .' WHERE seq>'. ($max - 50) .' AND iss>'. ($sticky && $iss >= 8 ? '=8' : '0') .' ORDER BY seq ASC', 1));
/* Move everyone ahead, unless sticky, 1 down. */
q('UPDATE {SQL_TABLE_PREFIX}tv_'. $forum_id .' SET seq=seq-1 WHERE seq BETWEEN '. ($pos + 1) .' AND '. ($iss - 1));
/* Move to top of the stack. */
q('UPDATE {SQL_TABLE_PREFIX}tv_'. $forum_id .' SET seq='. ($iss - 1) .' WHERE thread_id='. $th);
}
if (isset($ll)) {
db_unlock();
}
}
[Updated on: Sat, 31 March 2012 21:33] Report message to a moderator
|
|
|