summaryrefslogtreecommitdiff
path: root/lib/VNDB/DB/Discussions.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-07-07 14:54:46 +0200
committerYorhel <git@yorhel.nl>2009-07-07 15:25:26 +0200
commit5d6f09f838392f1e2c072f44f904b5f9eab95f45 (patch)
treecb95e3d444dc47b01d6c66d9501d6f7b6ac3284d /lib/VNDB/DB/Discussions.pm
parentc281835ad2b538c6e1afbd3a4bffe440c011b51c (diff)
Posts browser on user pages (/u+/posts)
Diffstat (limited to 'lib/VNDB/DB/Discussions.pm')
-rw-r--r--lib/VNDB/DB/Discussions.pm32
1 files changed, 26 insertions, 6 deletions
diff --git a/lib/VNDB/DB/Discussions.pm b/lib/VNDB/DB/Discussions.pm
index 78a462df..58cc5f61 100644
--- a/lib/VNDB/DB/Discussions.pm
+++ b/lib/VNDB/DB/Discussions.pm
@@ -153,25 +153,45 @@ sub dbThreadCount {
}
-# Options: tid, num, what, page, results
+# Options: tid, num, what, order, uid, hide, page, results
+# what: user thread
sub dbPostGet {
my($self, %o) = @_;
$o{results} ||= 50;
$o{page} ||= 1;
+ $o{what} ||= '';
+ $o{order} ||= 'tp.num ASC';
my %where = (
- 'tp.tid = ?' => $o{tid},
+ $o{tid} ? (
+ 'tp.tid = ?' => $o{tid} ) : (),
$o{num} ? (
'tp.num = ?' => $o{num} ) : (),
+ $o{uid} ? (
+ 'tp.uid = ?' => $o{uid} ) : (),
+ $o{hide} ? (
+ 'tp.hidden = FALSE' => 1 ) : (),
+ $o{hide} && $o{what} =~ /thread/ ? (
+ 't.hidden = FALSE' => 1 ) : (),
+ );
+
+ my @select = (
+ qw|tp.num tp.date tp.edited tp.msg tp.hidden|,
+ $o{what} =~ /user/ ? qw|tp.uid u.username| : (),
+ $o{what} =~ /thread/ ? (qw|tp.tid t.title|, 't.hidden AS thread_hidden') : (),
+ );
+ my @join = (
+ $o{what} =~ /user/ ? 'JOIN users u ON u.id = tp.uid' : (),
+ $o{what} =~ /thread/ ? 'JOIN threads t ON t.id = tp.tid' : (),
);
my($r, $np) = $self->dbPage(\%o, q|
- SELECT tp.num, tp.date, tp.edited, tp.msg, tp.hidden, tp.uid, u.username
+ SELECT !s
FROM threads_posts tp
- JOIN users u ON u.id = tp.uid
+ !s
!W
- ORDER BY tp.num ASC|,
- \%where,
+ ORDER BY !s|,
+ join(', ', @select), join(' ', @join), \%where, $o{order}
);
return wantarray ? ($r, $np) : $r;