summaryrefslogtreecommitdiff
path: root/lib/VNDB/DB/Discussions.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-11-16 11:40:35 +0100
committerYorhel <git@yorhel.nl>2008-11-16 11:40:35 +0100
commitb4786aa2ef2c3e06e30be93a8d12d6e18c1e8bbf (patch)
tree507025c379f32a6ff729d5f73a30e9f023abb5f4 /lib/VNDB/DB/Discussions.pm
parent2027a382b5bbf78a28725a425abe78f3f04dcc0e (diff)
Added reply/post edit/new thread functionality
Most of the code, or at least the design, was stolen from 1.X, as those functions were fine. Links to these forms is still pending...
Diffstat (limited to 'lib/VNDB/DB/Discussions.pm')
-rw-r--r--lib/VNDB/DB/Discussions.pm92
1 files changed, 91 insertions, 1 deletions
diff --git a/lib/VNDB/DB/Discussions.pm b/lib/VNDB/DB/Discussions.pm
index 2ab083f0..d645fb74 100644
--- a/lib/VNDB/DB/Discussions.pm
+++ b/lib/VNDB/DB/Discussions.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Exporter 'import';
-our @EXPORT = qw|dbThreadGet dbPostGet|;
+our @EXPORT = qw|dbThreadGet dbThreadEdit dbThreadAdd dbPostGet dbPostEdit dbPostAdd|;
# Options: id, type, iid, results, page, what
@@ -89,6 +89,54 @@ sub dbThreadGet {
}
+# id, %options->( title locked hidden tags }
+sub dbThreadEdit {
+ my($self, $id, %o) = @_;
+
+ my %set = (
+ 'title = ?' => $o{title},
+ 'locked = ?' => $o{locked}?1:0,
+ 'hidden = ?' => $o{hidden}?1:0,
+ );
+
+ $self->dbExec(q|
+ UPDATE threads
+ !H
+ WHERE id = ?|,
+ \%set, $id);
+
+ if($o{tags}) {
+ $self->dbExec('DELETE FROM threads_tags WHERE tid = ?', $id);
+ $self->dbExec(q|
+ INSERT INTO threads_tags (tid, type, iid)
+ VALUES (?, ?, ?)|,
+ $id, $_->[0], $_->[1]||0
+ ) for (@{$o{tags}});
+ }
+}
+
+
+# %options->{ title hidden locked tags }
+sub dbThreadAdd {
+ my($self, %o) = @_;
+
+ my $id = $self->dbRow(q|
+ INSERT INTO threads (title, hidden, locked)
+ VALUES (?, ?, ?)
+ RETURNING id|,
+ $o{title}, $o{hidden}?1:0, $o{locked}?1:0
+ )->{id};
+
+ $self->dbExec(q|
+ INSERT INTO threads_tags (tid, type, iid)
+ VALUES (?, ?, ?)|,
+ $id, $_->[0], $_->[1]||0
+ ) for (@{$o{tags}});
+
+ return $id;
+}
+
+
# Options: tid, num, what, page, results
sub dbPostGet {
my($self, %o) = @_;
@@ -114,5 +162,47 @@ sub dbPostGet {
}
+# tid, num, %options->{ num msg hidden lastmod }
+sub dbPostEdit {
+ my($self, $tid, $num, %o) = @_;
+
+ my %set = (
+ 'msg = ?' => $o{msg},
+ 'edited = ?' => $o{lastmod},
+ 'hidden = ?' => $o{hidden}?1:0,
+ );
+
+ $self->dbExec(q|
+ UPDATE threads_posts
+ !H
+ WHERE tid = ?
+ AND num = ?|,
+ \%set, $tid, $num
+ );
+}
+
+
+# tid, %options->{ uid msg }
+sub dbPostAdd {
+ my($self, $tid, %o) = @_;
+
+ my $num ||= $self->dbRow('SELECT num FROM threads_posts WHERE tid = ? ORDER BY num DESC LIMIT 1', $tid)->{num}+1;
+ $o{uid} ||= $self->authInfo->{id};
+
+ $self->dbExec(q|
+ INSERT INTO threads_posts (tid, num, uid, msg)
+ VALUES(?, ?, ?, ?)|,
+ $tid, $num, @o{qw| uid msg |}
+ );
+ $self->dbExec(q|
+ UPDATE threads
+ SET count = count+1
+ WHERE id = ?|,
+ $tid);
+
+ return $num;
+}
+
+
1;