Added discussion thread subscription support.
This commit is contained in:
parent
1f305caee0
commit
2df4defd5e
4 changed files with 157 additions and 77 deletions
|
|
@ -61,6 +61,14 @@ sub _duplicateReplyTree {
|
|||
$sth->finish;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _isSubscribed {
|
||||
my ($subscribed) = WebGUI::SQL->quickArray("select count(*) from discussionSubscription
|
||||
where threadId=$_[1] and userId=$_[0]");
|
||||
return $subscribed;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _lockReplyTree {
|
||||
my ($sth, %data, $messageId);
|
||||
|
|
@ -314,6 +322,13 @@ sub postSave {
|
|||
WebGUI::SQL->write("insert into discussion (messageId, wobjectId, subId, rid, pid, userId, username, status) values
|
||||
($session{form}{mid},$session{form}{wid},$session{form}{sid},$rid,$pid,$session{user}{userId},"
|
||||
.quote($username).", '$status')");
|
||||
my $sth = WebGUI::SQL->read("select userId from discussionSubscription where threadId=$rid");
|
||||
while (my ($userId) = $sth->array) {
|
||||
WebGUI::MessageLog::addInternationalizedEntry($userId,"",
|
||||
WebGUI::URL::page('func=showMessage&wid='.$session{form}{wid}
|
||||
.'&sid='.$session{form}{sid}.'&mid='.$session{form}{mid}),875);
|
||||
}
|
||||
$sth->finish;
|
||||
} elsif ($session{setting}{addEditStampToPosts}) {
|
||||
$session{form}{message} = "\n --- (Edited at ".epochToHuman(time())." by $session{user}{username}) --- \n\n"
|
||||
.$session{form}{message};
|
||||
|
|
@ -412,6 +427,17 @@ sub showMessage {
|
|||
$html .= '<a href="'.WebGUI::URL::page('func=showMessage&mid='.$data[0].'&sid='.$session{form}{sid}.'&wid='.
|
||||
$session{form}{wid}).'">'.WebGUI::International::get(512).' »</a><br>';
|
||||
}
|
||||
if ($session{user}{userId} != 1) {
|
||||
if (_isSubscribed($session{user}{userId},$message{rid})) {
|
||||
$html .= '<a href="'.WebGUI::URL::page('func=unsubscribeFromThread&mid='.$session{form}{mid}.
|
||||
'&wid='.$session{form}{wid}.'&sid='.$session{form}{sid}.'&threadId='.$message{rid}).'">'
|
||||
.WebGUI::International::get(874).'</a><br>';
|
||||
} else {
|
||||
$html .= '<a href="'.WebGUI::URL::page('func=subscribeToThread&mid='.$session{form}{mid}.
|
||||
'&wid='.$session{form}{wid}.'&sid='.$session{form}{sid}.'&threadId='.$message{rid}).'">'
|
||||
.WebGUI::International::get(873).'</a><br>';
|
||||
}
|
||||
}
|
||||
if (canEditMessage($_[1],$session{form}{mid})) {
|
||||
$html .= '<a href="'.WebGUI::URL::page('func=post&mid='.$session{form}{mid}.
|
||||
'&wid='.$session{form}{wid}.'&sid='.$session{form}{sid}).'">'
|
||||
|
|
@ -573,6 +599,16 @@ sub status {
|
|||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub subscribeToThread {
|
||||
unless (_isSubscribed($session{user}{userId},$session{form}{threadId})) {
|
||||
WebGUI::SQL->write("insert into discussionSubscription (threadId,userId) values (
|
||||
$session{form}{threadId}, $session{user}{userId})");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub traverseReplyTree {
|
||||
my ($sth, @data, $html, $depth, $i);
|
||||
|
|
@ -608,6 +644,15 @@ sub unlockThread {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub unsubscribeFromThread {
|
||||
if (_isSubscribed($session{user}{userId},$session{form}{threadId})) {
|
||||
WebGUI::SQL->write("delete from discussionSubscription where
|
||||
threadId=$session{form}{threadId} and userId=$session{user}{userId}");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ use WebGUI::Utility;
|
|||
use WebGUI::Authentication;
|
||||
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(&www_viewMessageLogMessage &www_viewMessageLog &www_viewProfile &www_editProfile &www_editProfileSave &www_createAccount &www_deactivateAccount &www_deactivateAccountConfirm &www_displayAccount &www_displayLogin &www_login &www_logout &www_recoverPassword &www_recoverPasswordFinish &www_createAccountSave &www_updateAccount);
|
||||
our @EXPORT = qw(&www_viewMessageLogMessage &www_viewThreadSubscriptions &www_viewMessageLog &www_viewProfile &www_editProfile &www_editProfileSave &www_createAccount &www_deactivateAccount &www_deactivateAccountConfirm &www_displayAccount &www_displayLogin &www_login &www_logout &www_recoverPassword &www_recoverPasswordFinish &www_createAccountSave &www_updateAccount);
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _accountOptions {
|
||||
|
|
@ -53,6 +53,8 @@ sub _accountOptions {
|
|||
unless ($session{form}{op} eq "viewProfile");
|
||||
$output .= '<li><a href="'.WebGUI::URL::page('op=viewMessageLog').'">'.WebGUI::International::get(354).'</a>'
|
||||
unless ($session{form}{op} eq "viewMessageLog");
|
||||
$output .= '<li><a href="'.WebGUI::URL::page('op=viewThreadSubscriptions').'">'.WebGUI::International::get(876).'</a>'
|
||||
unless ($session{form}{op} eq "viewThreadSubscriptions");
|
||||
$output .= '<li><a href="'.WebGUI::URL::page('op=logout').'">'.WebGUI::International::get(64).'</a>';
|
||||
|
||||
$output .= '<li><a href="'.WebGUI::URL::page('op=deactivateAccount').'">'.
|
||||
|
|
@ -558,7 +560,7 @@ sub www_viewProfile {
|
|||
return WebGUI::Privilege::notMember();
|
||||
} elsif ($u->profileField("publicProfile") < 1) {
|
||||
return $header.WebGUI::International::get(862);
|
||||
} elsif ($session{user}{userId} != 1) {
|
||||
} elsif (WebGUI::Privilege::isInGroup(2)) {
|
||||
$output = $header;
|
||||
$output .= '<table>';
|
||||
$a = WebGUI::SQL->read("select * from userProfileField,userProfileCategory
|
||||
|
|
@ -594,5 +596,32 @@ sub www_viewProfile {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_viewThreadSubscriptions {
|
||||
WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::isInGroup(2));
|
||||
my ($data, $output, $list);
|
||||
$output = '<h1>'.WebGUI::International::get(877).'</h1>';
|
||||
my $sth = WebGUI::SQL->read("select b.subject,b.messageId,b.wobjectId,b.subId,d.urlizedTitle
|
||||
from discussionSubscription a left join discussion b on (a.threadId=b.rid and b.pid=0)
|
||||
left join wobject c on (b.wobjectId=c.wobjectId) left join page d on (c.pageId=d.pageId)
|
||||
where a.userId=$session{user}{userId}");
|
||||
while ($data = $sth->hashRef) {
|
||||
$list .= '<li><a href="'
|
||||
.WebGUI::URL::gateway($data->{urlizedTitle},'func=showMessage&wid='
|
||||
.$data->{wobjectId}.'&mid='.$data->{messageId}.'&sid='.$data->{subId})
|
||||
.'">'.$data->{subject}.'</a>';
|
||||
}
|
||||
$sth->finish;
|
||||
if ($list eq "") {
|
||||
$output .= WebGUI::International::get(878);
|
||||
} else {
|
||||
$output .= '<ul>'.$list.'</ul><hr>';
|
||||
}
|
||||
$output .= _accountOptions();
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
|
|
@ -1292,6 +1292,20 @@ sub www_showMessage {
|
|||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_subscribeToThread ( )
|
||||
|
||||
Subscribes the current user to a specified discussion thread.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_subscribeToThread {
|
||||
WebGUI::Discussion::subscribeToThread();
|
||||
return $_[0]->www_showMessage();
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_unlockThread ( )
|
||||
|
|
@ -1311,6 +1325,19 @@ sub www_unlockThread {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_subscribeToThread ( )
|
||||
|
||||
Unsubscribes the current user from a specified discussion thread.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_unsubscribeFromThread {
|
||||
WebGUI::Discussion::unsubscribeFromThread();
|
||||
return $_[0]->www_showMessage();
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_view ( )
|
||||
|
||||
The default display mechanism for any wobject. This web method MUST be overridden.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue