summaryrefslogtreecommitdiff
path: root/lib/VNDB/DB/Discussions.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VNDB/DB/Discussions.pm')
-rw-r--r--lib/VNDB/DB/Discussions.pm11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/VNDB/DB/Discussions.pm b/lib/VNDB/DB/Discussions.pm
index deeb7480..1c27c22e 100644
--- a/lib/VNDB/DB/Discussions.pm
+++ b/lib/VNDB/DB/Discussions.pm
@@ -158,7 +158,7 @@ sub dbThreadCount {
}
-# Options: tid, num, what, uid, mindate, hide, page, results
+# Options: tid, num, what, uid, mindate, hide, page, results, sort, reverse
# what: user thread
sub dbPostGet {
my($self, %o) = @_;
@@ -191,13 +191,18 @@ sub dbPostGet {
$o{what} =~ /thread/ ? 'JOIN threads t ON t.id = tp.tid' : (),
);
+ my $order = sprintf {
+ num => 'tp.num %s',
+ date => 'tp.date %s',
+ }->{ $o{sort}||'num' }, $o{reverse} ? 'DESC' : 'ASC';
+
my($r, $np) = $self->dbPage(\%o, q|
SELECT !s
FROM threads_posts tp
!s
!W
- ORDER BY tp.num ASC|,
- join(', ', @select), join(' ', @join), \%where
+ ORDER BY !s|,
+ join(', ', @select), join(' ', @join), \%where, $order
);
return wantarray ? ($r, $np) : $r;