Users can now subscribe/unsubscribe to all forums in a course from the forum list

This commit is contained in:
patrickslee 2005-11-28 03:11:05 +00:00
parent 9a3d715ffd
commit 03877b049e
2 changed files with 39 additions and 0 deletions

View File

@ -11,6 +11,8 @@ $string['allowchoice'] = 'Allow everyone to choose';
$string['allowdiscussions'] = 'Can a $a post to this forum?';
$string['allowratings'] = 'Allow posts to be rated?';
$string['allowsdiscussions'] = 'This forum allows each person to start one discussion topic.';
$string['allsubscribe'] = 'Subscribe to all forums';
$string['allunsubscribe'] = 'Unsubscribe from all forums';
$string['anyfile'] = 'Any file';
$string['attachment'] = 'Attachment';
$string['bynameondate'] = 'by $a->name - $a->date';
@ -109,6 +111,8 @@ $string['notingroup'] = 'Sorry, but you need to be part of a group to see this f
$string['notrackforum'] = 'Don\'t track unread messages';
$string['nownotsubscribed'] = '$a->name will NOT receive copies of \'$a->forum\' by email.';
$string['nownottracking'] = '$a->name is no longer tracking \'$a->forum\'.';
$string['nowallsubscribed'] = 'All forums in $a are subscribed.';
$string['nowallunsubscribed'] = 'All forums in $a are not subscribed.';
$string['nowsubscribed'] = '$a->name will receive copies of \'$a->forum\' by email.';
$string['nowtracking'] = '$a->name is now tracking \'$a->forum\'.';
$string['numposts'] = '$a posts';

View File

@ -5,6 +5,7 @@
require_once("$CFG->libdir/rsslib.php");
$id = optional_param('id',0,PARAM_INT); // course
$subscribe = optional_param('subscribe',null,PARAM_INT); // Subscribe/Unsubscribe all forums
if ($id) {
if (! $course = get_record("course", "id", $id)) {
@ -123,6 +124,31 @@
}
}
/// Do course wide subscribe/unsubscribe
if (!is_null($subscribe) && !isguest()) {
$allforums = array_merge($generalforums, $learningforums);
if ($allforums) {
foreach ($allforums as $forum) {
if (!forum_is_forcesubscribed($forum->id)) {
$subscribed = forum_is_subscribed($USER->id, $forum->id);
if ($subscribe && !$subscribed) {
forum_subscribe($USER->id, $forum->id);
} elseif (!$subscribe && $subscribed) {
forum_unsubscribe($USER->id, $forum->id);
}
}
}
}
$returnto = forum_go_back_to("index.php?id=$course->id");
if ($subscribe) {
add_to_log($course->id, "forum", "subscribeall", "index.php?id=$course->id", $course->id);
redirect($returnto, get_string("nowallsubscribed", "forum", $course->shortname), 1);
} else {
add_to_log($course->id, "forum", "unsubscribeall", "index.php?id=$course->id", $course->id);
redirect($returnto, get_string("nowallunsubscribed", "forum", $course->shortname), 1);
}
}
/// First, let's process the general forums and build up a display
if ($generalforums) {
@ -405,6 +431,15 @@
"", "", true, $searchform, navmenu($course));
}
if (!isguest()) {
echo '<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr valign="top"><td align="right" class="subscription">';
echo '<span class="helplink">';
echo '<a href="index.php?id='.$course->id.'&amp;subscribe=1">'.get_string('allsubscribe', 'forum').'</a>';
echo '<br />';
echo '<a href="index.php?id='.$course->id.'&amp;subscribe=0">'.get_string('allunsubscribe', 'forum').'</a>';
echo '</span></td></tr></table>';
}
if ($generalforums) {
print_heading(get_string("generalforums", "forum"));
print_table($generaltable);