Subscriber editing is group-aware.
Groups can be subscribed or unsubscribed with one click
This commit is contained in:
@@ -121,7 +121,9 @@ $string['singleforum'] = 'A single simple discussion';
|
||||
$string['startedby'] = 'Started by';
|
||||
$string['subject'] = 'Subject';
|
||||
$string['subscribe'] = 'Subscribe to this forum';
|
||||
$string['subscribeall'] = 'Subscribe everyone to this forum';
|
||||
$string['subscribed'] = 'Subscribed';
|
||||
$string['subscribenone'] = 'Unsubscribe everyone from this forum';
|
||||
$string['subscribers'] = 'Subscribers';
|
||||
$string['subscribersto'] = 'Subscribers to \'$a\'';
|
||||
$string['subscribestart'] = 'Send me email copies of posts to this forum';
|
||||
|
||||
+15
-3
@@ -913,10 +913,18 @@ function forum_get_user_discussions($courseid, $userid, $groupid=0) {
|
||||
}
|
||||
|
||||
|
||||
function forum_subscribed_users($course, $forum) {
|
||||
function forum_subscribed_users($course, $forum, $groupid=0) {
|
||||
/// Returns list of user objects that are subscribed to this forum
|
||||
global $CFG;
|
||||
|
||||
if ($groupid) {
|
||||
$grouptables = ", {$CFG->prefix}groups_members g";
|
||||
$groupselect = " AND g.groupid = '$groupid' AND u.id = g.userid";
|
||||
} else {
|
||||
$grouptables = "";
|
||||
$groupselect = "";
|
||||
}
|
||||
|
||||
if ($forum->forcesubscribe) {
|
||||
if ($course->category) {
|
||||
if ($forum->type == "teacher") {
|
||||
@@ -931,10 +939,10 @@ function forum_subscribed_users($course, $forum) {
|
||||
return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.emailstop,
|
||||
u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture, u.timezone, u.lang
|
||||
FROM {$CFG->prefix}user u,
|
||||
{$CFG->prefix}forum_subscriptions s
|
||||
{$CFG->prefix}forum_subscriptions s $grouptables
|
||||
WHERE s.forum = '$forum->id'
|
||||
AND s.userid = u.id
|
||||
AND u.deleted <> 1
|
||||
AND u.deleted <> 1 $groupselect
|
||||
ORDER BY u.email ASC");
|
||||
}
|
||||
|
||||
@@ -1924,6 +1932,10 @@ function forum_is_subscribed($userid, $forumid) {
|
||||
function forum_subscribe($userid, $forumid) {
|
||||
/// Adds user to the subscriber list
|
||||
|
||||
if (record_exists("forum_subscriptions", "userid", $userid, "forum", $forumid)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$sub->userid = $userid;
|
||||
$sub->forum = $forumid;
|
||||
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
require_variable($id); // forum
|
||||
require_variable($id); // forum
|
||||
optional_variable($subscribe, ''); // 'all' or 'none'
|
||||
optional_variable($unsubscribe, ''); // a single user id
|
||||
optional_variable($group); // change of group
|
||||
|
||||
if (! $forum = get_record("forum", "id", $id)) {
|
||||
error("Forum ID is incorrect");
|
||||
@@ -28,6 +31,8 @@
|
||||
add_to_log($course->id, "forum", "view subscribers", "subscribers.php?id=$forum->id", $forum->id, $cm->id);
|
||||
|
||||
$strunsubscribeshort = get_string("unsubscribeshort", "forum");
|
||||
$strsubscribeall = get_string("subscribeall", "forum");
|
||||
$strsubscribenone = get_string("subscribenone", "forum");
|
||||
$strsubscribers = get_string("subscribers", "forum");
|
||||
$strforums = get_string("forums", "forum");
|
||||
|
||||
@@ -42,11 +47,71 @@
|
||||
|
||||
print_header("$course->shortname: $strsubscribers", "$course->fullname", "$navigation");
|
||||
|
||||
if (! $users = forum_subscribed_users($course, $forum) ) {
|
||||
|
||||
/// Check to see if groups are being used in this forum
|
||||
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
|
||||
$currentgroup = setup_and_print_groups($course, $groupmode, "subscribers.php?id=$forum->id");
|
||||
} else {
|
||||
$currentgroup = false;
|
||||
}
|
||||
|
||||
if ($subscribe == 'all') {
|
||||
if ($currentgroup) {
|
||||
$users = get_group_users($currentgroup);
|
||||
} else {
|
||||
$users = get_course_users($course->id);
|
||||
}
|
||||
if ($users) {
|
||||
foreach ($users as $user) {
|
||||
forum_subscribe($user->id, $forum->id);
|
||||
}
|
||||
}
|
||||
} else if ($subscribe == 'none') {
|
||||
if ($currentgroup) {
|
||||
if ($users = get_group_users($currentgroup)) {
|
||||
foreach ($users as $user) {
|
||||
forum_unsubscribe($user->id, $forum->id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
delete_records("forum_subscriptions", "forum", $forum->id);
|
||||
}
|
||||
}
|
||||
|
||||
if ($unsubscribe) {
|
||||
forum_unsubscribe($unsubscribe, $forum->id);
|
||||
}
|
||||
|
||||
if (! $users = forum_subscribed_users($course, $forum, $currentgroup) ) {
|
||||
|
||||
if (!$forum->forcesubscribe) {
|
||||
echo '<center>';
|
||||
$options['id'] = $forum->id;
|
||||
$options['subscribe'] = 'all';
|
||||
print_single_button('subscribers.php', $options, $strsubscribeall);
|
||||
echo '</center>';
|
||||
}
|
||||
|
||||
print_heading(get_string("nosubscribers", "forum"));
|
||||
|
||||
} else {
|
||||
|
||||
if (!$forum->forcesubscribe) {
|
||||
echo '<table align="center"><tr>';
|
||||
echo '<td>';
|
||||
$options['id'] = $forum->id;
|
||||
$options['subscribe'] = 'all';
|
||||
print_single_button('subscribers.php', $options, $strsubscribeall);
|
||||
echo '</td>';
|
||||
echo '<td>';
|
||||
$options['subscribe'] = 'none';
|
||||
print_single_button('subscribers.php', $options, $strsubscribenone);
|
||||
echo '</td>';
|
||||
echo '</tr></table>';
|
||||
}
|
||||
|
||||
print_heading(get_string("subscribersto","forum", "'$forum->name'"));
|
||||
|
||||
echo '<table align="center" cellpadding="5" cellspacing="5">';
|
||||
foreach ($users as $user) {
|
||||
echo "<tr><td>";
|
||||
@@ -56,7 +121,7 @@
|
||||
echo "</td><td bgcolor=\"$THEME->cellcontent\">";
|
||||
echo "$user->email";
|
||||
echo "</td><td>";
|
||||
echo "<font size=1><a href=\"subscribe.php?id=$forum->id&user=$user->id\">$strunsubscribeshort</a></font>";
|
||||
echo "<font size=1><a href=\"subscribers.php?id=$forum->id&unsubscribe=$user->id\">$strunsubscribeshort</a></font>";
|
||||
echo "</td></tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
|
||||
Reference in New Issue
Block a user