working on new discussion system
This commit is contained in:
parent
cb55619457
commit
b84c79ab96
6 changed files with 357 additions and 3 deletions
|
|
@ -14,7 +14,7 @@ create table forum (
|
|||
moderatePosts int not null default 0,
|
||||
groupToModerate int not null default 0,
|
||||
attachmentsPerPost int not null default 0,
|
||||
allowHTML int not null default 1,
|
||||
allowRichEdit int not null default 1,
|
||||
allowReplacements int not null default 1
|
||||
);
|
||||
|
||||
|
|
@ -34,7 +34,6 @@ create table forumPost (
|
|||
message text,
|
||||
dateOfPost int,
|
||||
views int,
|
||||
locked int,
|
||||
status varchar(30) not null default 'approved',
|
||||
contentType varchar(30) not null default 'some html'
|
||||
);
|
||||
|
|
@ -52,7 +51,8 @@ create table forumThread (
|
|||
views int not null,
|
||||
replies int not null,
|
||||
lastPostId int not null,
|
||||
locked int not null,
|
||||
lastPostDate int not null,
|
||||
isLocked int not null,
|
||||
isSticky int not null
|
||||
);
|
||||
|
||||
|
|
|
|||
43
lib/WebGUI/Forum.pm
Normal file
43
lib/WebGUI/Forum.pm
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package WebGUI::Forum;
|
||||
|
||||
use WebGUI::Forum::Thread;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
|
||||
sub create {
|
||||
my ($self, $data) = @_;
|
||||
$data->{forumId} = "new";
|
||||
my $forumId = WebGUI::SQL->setRow("forum","forumId",$data);
|
||||
return WebGUI::Forum->new($forumId);
|
||||
}
|
||||
|
||||
sub get {
|
||||
my ($self, $key) = @_;
|
||||
if ($key eq "") {
|
||||
return $self->{_properties};
|
||||
}
|
||||
return $self->{_properties}->{$key};
|
||||
}
|
||||
|
||||
sub getThread {
|
||||
my ($self, $threadId) = @_;
|
||||
unless (exists $self->{_thread}{$threadId}) {
|
||||
$self->{_thread}{$threadId} = WebGUI::Forum::Thread->new($threadId);
|
||||
}
|
||||
return $self->{_thread}{$threadId};
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($self, $forumId) = @_;
|
||||
my $properties = WebGUI::SQL->getRow("forum","forumId",$forumId);
|
||||
bless {_properties=>$properties}, $self;
|
||||
}
|
||||
|
||||
sub set {
|
||||
my ($self, $data) = @_;
|
||||
WebGUI::SQL->setRow("forum","forumId",$data);
|
||||
$self->{_properties} = $data;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
76
lib/WebGUI/Forum/Post.pm
Normal file
76
lib/WebGUI/Forum/Post.pm
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
package WebGUI::Forum::Post;
|
||||
|
||||
use WebGUI::Discuss::Thread;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
|
||||
sub addView {
|
||||
my ($self) = @_;
|
||||
WebGUI::SQL->write("update forumPost set views=views+1 where forumPostId=".$self->get("forumPostId"));
|
||||
$self->getThread->addView;
|
||||
}
|
||||
|
||||
sub create {
|
||||
my ($self, $data) = @_;
|
||||
$data->{forumPostId} = "new";
|
||||
$data->{dateOfPost} = WebGUI::DateTime::time();
|
||||
my $forumPostId = WebGUI::SQL->setRow("forumPost","forumPostId",$data);
|
||||
$self = WebGUI::Forum::Post->new($forumPostId);
|
||||
if ($data->{parentId} > 0) {
|
||||
$self->getThread->addReply($forumPostId,$self->get("dateOfPost"));
|
||||
}
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub get {
|
||||
my ($self, $key) = @_;
|
||||
if ($key eq "") {
|
||||
return $self->{_properties};
|
||||
}
|
||||
return $self->{_properties}->{$key};
|
||||
}
|
||||
|
||||
sub getTemplateVars {
|
||||
my ($self) = @_;
|
||||
my $properties = $self->get;
|
||||
my %var = %{$properties};
|
||||
$var->{subject} = WebGUI::HTML::filter($var->{subject},"none");
|
||||
$var->{message} = WebGUI::HTML::filter($var->{subject},$self->getThread->getForum->get("filterPosts"));
|
||||
if ($self->getThread->getForum->get("allowReplacements")) {
|
||||
# do the replacement thing
|
||||
}
|
||||
$var->{dateOfPost} = WebGUI::DateTime::epochToHuman($var->{dateOfPost});
|
||||
}
|
||||
|
||||
sub getThread {
|
||||
my ($self) = @_;
|
||||
unless (exists $self->{_thread}) {
|
||||
$self->{_thread} = WebGUI::Forum::Thread->new($self->get("forumThreadId"));
|
||||
}
|
||||
return $self->{_thread};
|
||||
}
|
||||
|
||||
sub markRead {
|
||||
my ($self, $userId) = @_;
|
||||
$userId = $session{user}{userId} unless ($userId);
|
||||
my ($alreadyMarked) = WebGUI::SQL->quickArray("select count(*) from forumRead userId,forumPostId");
|
||||
unless ($alreadyMarked) {
|
||||
WebGUI::SQL->write("insert into forumRead (userId, forumPostId, lastRead) values ($userId,
|
||||
".$self->get("forumPostId").", ".WebGUI::DateTime::time().")");
|
||||
}
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($self, $forumPostId) = @_;
|
||||
my $properties = WebGUI::SQL->getRow("forumPost","forumPostId",$forumPostId);
|
||||
bless {_properties=>$properties}, $self;
|
||||
}
|
||||
|
||||
sub set {
|
||||
my ($self, $data) = @_;
|
||||
WebGUI::SQL->setRow("forumPost","forumPostId",$data);
|
||||
$self->{_properties} = $data;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
128
lib/WebGUI/Forum/Thread.pm
Normal file
128
lib/WebGUI/Forum/Thread.pm
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
package WebGUI::Forum::Thread;
|
||||
|
||||
use WebGUI::Forum;
|
||||
use WebGUI::Forum::Post;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
|
||||
sub addReply {
|
||||
my ($self, $dateOfReply) = @_;
|
||||
WebGUI::SQL->write("update forumThread set replies=replies+1, lastR where forumThreadId=".$self->get("forumThreadId"));
|
||||
#add method to notify users for subscriptions
|
||||
}
|
||||
|
||||
sub addView {
|
||||
my ($self) = @_;
|
||||
WebGUI::SQL->write("update forumThread set views=views+1 where forumThreadId=".$self->get("forumThreadId"));
|
||||
}
|
||||
|
||||
sub create {
|
||||
my ($self, $data, $postData) = @_;
|
||||
$data->{forumThreadId} = "new";
|
||||
my $forumThreadId = WebGUI::SQL->setRow("forumThread","forumThreadId",$data);
|
||||
$self = WebGUI::Forum::Thread->new($forumThreadId);
|
||||
$postData{forumThreadId} = $forumThreadId;
|
||||
$postData{parentId} = 0;
|
||||
my $post = WebGUI::Discuss::Post->create($postData);
|
||||
$self->set({
|
||||
rootPostId=>$post->get("forumPostId"),
|
||||
lastPostId=>$post->get("forumPostId"),
|
||||
lastPostDate=>$post->get("dateOfPost")
|
||||
});
|
||||
$self->{_post}{$post->{forumPostId}} = $post;
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub get {
|
||||
my ($self, $key) = @_;
|
||||
if ($key eq "") {
|
||||
return $self->{_properties};
|
||||
}
|
||||
return $self->{_properties}->{$key};
|
||||
}
|
||||
|
||||
sub getForum {
|
||||
my ($self) = @_;
|
||||
unless (exists $self->{_forum}) {
|
||||
$self->{_forum} = WebGUI::Forum->new($self->get("forumId"));
|
||||
}
|
||||
return $self->{_forum};
|
||||
}
|
||||
|
||||
sub getPost {
|
||||
my ($self, $postId) = @_;
|
||||
unless (exists $self->{_post}{$postId}) {
|
||||
$self->{_post}{$postId} = WebGUI::Forum::Post->new($postId);
|
||||
}
|
||||
return $self->{_post}{$postId};
|
||||
}
|
||||
|
||||
sub isLocked {
|
||||
my ($self) = @_;
|
||||
return $self->get("isLocked");
|
||||
}
|
||||
|
||||
sub isSticky {
|
||||
my ($self) = @_;
|
||||
return $self->get("isSticky");
|
||||
}
|
||||
|
||||
sub isSubscribed {
|
||||
my ($self, $userId) = @_;
|
||||
$userId = $session{user}{userId} unless ($userId);
|
||||
my ($isSubscribed) = WebGUI::SQL->quickArray("select count(*) from forumThreadSubscription where forumThreadId=".$self->get("forumThreadId")
|
||||
." and userId=$userId");
|
||||
return $isSubscribed;
|
||||
}
|
||||
|
||||
sub lock {
|
||||
my ($self) = @_;
|
||||
$self->set({isLocked=>1});
|
||||
}
|
||||
|
||||
sub stick {
|
||||
my ($self) = @_;
|
||||
$self->set({isSticky=>1});
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($self, $forumThreadId) = @_;
|
||||
my $properties = WebGUI::SQL->getRow("forumThread","forumThreadId",$forumThreadId);
|
||||
bless {_properties=>$properties}, $self;
|
||||
}
|
||||
|
||||
sub set {
|
||||
my ($self, $data) = @_;
|
||||
WebGUI::SQL->setRow("forumThread","forumThreadId",$data);
|
||||
$self->{_properties} = $data;
|
||||
}
|
||||
|
||||
sub subscribe {
|
||||
my ($self, $userId) = @_;
|
||||
$userId = $session{user}{userId} unless ($userId);
|
||||
unless ($self->isSubscribed($userId)) {
|
||||
WebGUI::SQL->write("insert into forumThreadSubscription (forumThreadId, userId) values (".$self->get("forumThreadId").",$userId)");
|
||||
}
|
||||
}
|
||||
|
||||
sub unlock {
|
||||
my ($self) = @_;
|
||||
$self->set({isLocked=>0});
|
||||
}
|
||||
|
||||
sub unstick {
|
||||
my ($self) = @_;
|
||||
$self->set({isSticky=>0});
|
||||
}
|
||||
|
||||
sub unsubscribe {
|
||||
my ($self, $userId) = @_;
|
||||
$userId = $session{user}{userId} unless ($userId);
|
||||
if ($self->isSubscribed($userId)) {
|
||||
WebGUI::SQL->write("delete from forumThreadSubscription where forumThreadId=".$self->get("forumThreadId")." and userId=$userId");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
29
lib/WebGUI/Forum/Web.pm
Normal file
29
lib/WebGUI/Forum/Web.pm
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package WebGUI::Discuss::Web;
|
||||
|
||||
use WebGUI::Discuss;
|
||||
use WebGUI::Discuss::Post;
|
||||
use WebGUI::Discuss::Thread;
|
||||
use WebGUI::Session;
|
||||
|
||||
|
||||
sub post {
|
||||
|
||||
}
|
||||
|
||||
sub postSave {
|
||||
my $forumId = $session{form}{forumId};
|
||||
my $threadId = $session{form}{forumThreadId};
|
||||
if ($session{form}{parentId} > 0) {
|
||||
my $parentPost = WebGUI::Discuss::Post->new($session{form}{parentId});
|
||||
$forumId = $parentPost->getThread->get("forumId");
|
||||
$threadId = $parentPost->get("forumThreadId");
|
||||
}
|
||||
if ($threadId < 1) {
|
||||
$threadId = WebGUI::Discuss::Thread->create({
|
||||
forumId=>$forumId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -277,6 +277,39 @@ sub getNextId {
|
|||
return $id;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getRow ( table, key, keyValue [, dbh ] )
|
||||
|
||||
Returns a row of data as a hash reference from the specified table.
|
||||
|
||||
=over
|
||||
|
||||
=item table
|
||||
|
||||
The name of the table to retrieve the row of data from.
|
||||
|
||||
=item key
|
||||
|
||||
The name of the column to use as the retrieve key. Should be a primary or unique key in the table.
|
||||
|
||||
=item keyValue
|
||||
|
||||
The value to search for in the key column.
|
||||
|
||||
=item dbh
|
||||
|
||||
A database handler to use. Defaults to the WebGUI database handler.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub getRow {
|
||||
my ($self, $table, $key, $keyValue, $dbh) = @_;
|
||||
my $row = WebGUI::SQL->quickHashRef("select * from $table where ".$key."=".quote($keyValue), $dbh);
|
||||
return $row;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -572,6 +605,51 @@ sub rows {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 setRow ( table, key, data [, dbh ] )
|
||||
|
||||
Inserts/updates a row of data into the database. Returns the value of the key.
|
||||
|
||||
=over
|
||||
|
||||
=item table
|
||||
|
||||
The name of the table to use.
|
||||
|
||||
=item key
|
||||
|
||||
The name of the primary key of the table.
|
||||
|
||||
=item data
|
||||
|
||||
A hash reference containing column names and values to be set.
|
||||
|
||||
=item dbh
|
||||
|
||||
A database handler to use. Defaults to the WebGUI database handler.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub setRow {
|
||||
my ($self, $table, $keyColumn, $data, $dbh) = @_;
|
||||
if ($data->{$keyColumn} eq "new") {
|
||||
$data->{$keyColumn} = WebGUI::SQL->getNextId($keyColumn);
|
||||
WebGUI::SQL->write("insert into $table ($keyColumn) values ($data->{$keyColumn})", $dbh);
|
||||
}
|
||||
my (@pairs);
|
||||
foreach my $key (keys %{$data}) {
|
||||
unless ($key eq $keyColumn) {
|
||||
push(@pairs, $key.'='.quote($data->{$key}));
|
||||
}
|
||||
}
|
||||
WebGUI::SQL->write("update $table set ".join(", ", @pairs), $dbh);
|
||||
return $data->{$keyColumn};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 unconditionalRead ( sql [, dbh ] )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue