Permalink
Browse files

Can now force subscribe INITIALLY, implementing suggestion by Howard …

…in bug 1084
  • Loading branch information...
1 parent b06d217 commit 709f0ec8d502addea68360c0b9b3176234419c04 gustav_delius committed Aug 29, 2004
Showing with 37 additions and 8 deletions.
  1. +12 −0 lib/moodlelib.php
  2. +25 −8 mod/forum/lib.php
View
@@ -831,11 +831,16 @@ function authenticate_user_login($username, $password) {
function enrol_student($userid, $courseid, $timestart=0, $timeend=0) {
/// Enrols a student in a given course
+ global $CFG;
$course = get_record("course", "id", $courseid);
if (!record_exists("user_students", "userid", $userid, "course", $courseid)) {
if (record_exists("user", "id", $userid)) {
+
+ require_once('../mod/forum/lib.php');
+ forum_add_user($userid, $courseid);
+
$student->userid = $userid;
$student->course = $courseid;
$student->timestart = $timestart;
@@ -911,6 +916,13 @@ function add_teacher($userid, $courseid, $editall=1, $role="", $timestart=0, $ti
$teacher->authority = 1;
}
delete_records("user_students", "userid", $userid, "course", $courseid); // Unenrol as student
+
+ /// Add forum subscriptions for new users
+ if ($forums = get_records('forum', 'course', $courseid, 'forcesubscribe', 2)) {
+ foreach ($forums as $forum) {
+ forum_subscribe($userid, $forum->id);
+ }
+ }
return insert_record("user_teachers", $teacher);
View
@@ -9,6 +9,9 @@
define("FORUM_MODE_THREADED", 2);
define("FORUM_MODE_NESTED", 3);
+define("FORUM_FORCESUBSCRIBE", 1);
+define("FORUM_INITIALSUBSCRIBE", 2);
+
$FORUM_LAYOUT_MODES = array ( FORUM_MODE_FLATOLDEST => get_string("modeflatoldestfirst", "forum"),
FORUM_MODE_FLATNEWEST => get_string("modeflatnewestfirst", "forum"),
FORUM_MODE_THREADED => get_string("modethreaded", "forum"),
@@ -90,6 +93,13 @@ function forum_add_instance($forum) {
error("Could not add the discussion for this forum");
}
}
+
+ if ($forum->forcesubscribe == FORUM_INITIALSUBSCRIBE) { // all users should be subscribed initially
+ $users = get_course_users($forum->course);
+ foreach ($users as $user) {
+ forum_subscribe($user->id, $forum->id);
+ }
+ }
return $forum->id;
}
@@ -1203,7 +1213,7 @@ function forum_subscribed_users($course, $forum, $groupid=0) {
$groupselect = "";
}
- if ($forum->forcesubscribe) {
+ if (forum_is_forcesubscribed($forum->id)) {
if ($course->category) {
if ($forum->type == "teacher") {
return get_course_teachers($course->id); // Only teachers can be subscribed to teacher forums
@@ -1251,12 +1261,10 @@ function forum_get_course_forum($courseid, $type) {
$forum->forcesubscribe = 1;
$forum->open = 1; // 0 - no, 1 - posts only, 2 - discuss and post
$forum->assessed = 0;
- if ($site = get_site()) {
- if ($courseid == $site->id) {
- $forum->name = get_string("sitenews");
- $forum->forcesubscribe = 0;
- }
- }
+ if ($courseid == SITEID) {
+ $forum->name = get_string("sitenews");
+ $forum->forcesubscribe = 0;
+ }
break;
case "social":
$forum->name = addslashes(get_string("namesocial", "forum"));
@@ -2234,7 +2242,7 @@ function forum_forcesubscribe($forumid, $value=1) {
}
function forum_is_forcesubscribed($forumid) {
- return get_field("forum", "forcesubscribe", "id", $forumid);
+ return (get_field("forum", "forcesubscribe", "id", $forumid) == 1);
}
function forum_is_subscribed($userid, $forumid) {
@@ -2834,4 +2842,13 @@ function forum_update_subscriptions_button($courseid, $forumid) {
}
}
+function forum_add_user($userid, $courseid) {
+/// Add subscriptions for new users
+ if ($forums = get_records_select('forum', "course = '$courseid' AND forcesubscribe = '2'")) {
+ foreach ($forums as $forum) {
+ forum_subscribe($userid, $forum->id);
+ }
+ }
+}
+
?>

0 comments on commit 709f0ec

Please sign in to comment.