mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 12:45:04 +01:00
fixed When unassigning a role, forum_role_unassign unsubscribes the user even if you have other roles there MDL-7120; merged from MOODLE_17_STABLE
This commit is contained in:
parent
5fd4e46dbd
commit
00e12c7332
@ -1093,7 +1093,7 @@ function get_coursemodule_from_instance($modulename, $instance, $courseid=0) {
|
||||
* @param array $courses This depends on an accurate $course->modinfo
|
||||
* @return array of instances
|
||||
*/
|
||||
function get_all_instances_in_courses($modulename,$courses) {
|
||||
function get_all_instances_in_courses($modulename, $courses, $userid=NULL, $includeinvisible=false) {
|
||||
global $CFG;
|
||||
if (empty($courses) || !is_array($courses) || count($courses) == 0) {
|
||||
return array();
|
||||
@ -1114,8 +1114,10 @@ function get_all_instances_in_courses($modulename,$courses) {
|
||||
$outputarray = array();
|
||||
|
||||
foreach ($courses as $course) {
|
||||
// Hide non-visible instances from students
|
||||
if (has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||
if ($includeinvisible) {
|
||||
$invisible = -1;
|
||||
} else if (has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id), $userid)) {
|
||||
// Usually hide non-visible instances from students
|
||||
$invisible = -1;
|
||||
} else {
|
||||
$invisible = 0;
|
||||
@ -1151,7 +1153,7 @@ function get_all_instances_in_courses($modulename,$courses) {
|
||||
* @param string $modulename The name of the module to get instances for
|
||||
* @param object(course) $course This depends on an accurate $course->modinfo
|
||||
*/
|
||||
function get_all_instances_in_course($modulename, $course) {
|
||||
function get_all_instances_in_course($modulename, $course, $userid=NULL, $includeinvisible=false) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
@ -1176,8 +1178,10 @@ function get_all_instances_in_course($modulename, $course) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Hide non-visible instances from students
|
||||
if (has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||
if ($includeinvisible) {
|
||||
$invisible = -1;
|
||||
} else if (has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id), $userid)) {
|
||||
// Usually hide non-visible instances from students
|
||||
$invisible = -1;
|
||||
} else {
|
||||
$invisible = 0;
|
||||
|
@ -3690,7 +3690,7 @@ function forum_add_user_default_subscriptions($userid, $context) {
|
||||
foreach ($courses as $course) {
|
||||
if ($course->id == SITEID) {
|
||||
// temporary workaround for bug MDL-7114
|
||||
if ($forums = get_all_instances_in_course('forum', $course)) {
|
||||
if ($forums = get_all_instances_in_course('forum', $course, $userid, false)) {
|
||||
foreach ($forums as $forum) {
|
||||
if ($forum->forcesubscribe != FORUM_INITIALSUBSCRIBE) {
|
||||
continue;
|
||||
@ -3731,7 +3731,7 @@ function forum_add_user_default_subscriptions($userid, $context) {
|
||||
|
||||
case CONTEXT_COURSE: // For a whole course
|
||||
if ($course = get_record('course', 'id', $context->instanceid)) {
|
||||
if ($forums = get_all_instances_in_course('forum', $course)) {
|
||||
if ($forums = get_all_instances_in_course('forum', $course, $userid, false)) {
|
||||
foreach ($forums as $forum) {
|
||||
if ($forum->forcesubscribe != FORUM_INITIALSUBSCRIBE) {
|
||||
continue;
|
||||
@ -3778,9 +3778,13 @@ function forum_remove_user_subscriptions($userid, $context) {
|
||||
foreach ($courses as $course) {
|
||||
if ($course->id == SITEID) {
|
||||
if ($course = get_records('course', 'id', $context->instanceid)) {
|
||||
if ($forums = get_all_instances_in_course('forum', $course)) {
|
||||
if ($forums = get_all_instances_in_course('forum', $course, $userid, true)) {
|
||||
foreach ($forums as $forum) {
|
||||
forum_unsubscribe($userid, $forum->id);
|
||||
if ($modcontext = get_context_instance(CONTEXT_MODULE, $forum->coursemodule)) {
|
||||
if (!has_capability('mod/forum:viewdiscussion', $modcontext, $userid)) {
|
||||
forum_unsubscribe($userid, $forum->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3808,10 +3812,14 @@ function forum_remove_user_subscriptions($userid, $context) {
|
||||
break;
|
||||
|
||||
case CONTEXT_COURSE: // For a whole course
|
||||
if ($course = get_records('course', 'id', $context->instanceid)) {
|
||||
if ($forums = get_all_instances_in_course('forum', $course)) {
|
||||
if ($course = get_record('course', 'id', $context->instanceid)) {
|
||||
if ($forums = get_all_instances_in_course('forum', $course, $userid, true)) {
|
||||
foreach ($forums as $forum) {
|
||||
forum_unsubscribe($userid, $forum->id);
|
||||
if ($modcontext = get_context_instance(CONTEXT_MODULE, $forum->coursemodule)) {
|
||||
if (!has_capability('mod/forum:viewdiscussion', $modcontext, $userid)) {
|
||||
forum_unsubscribe($userid, $forum->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3820,7 +3828,9 @@ function forum_remove_user_subscriptions($userid, $context) {
|
||||
case CONTEXT_MODULE: // Just one forum
|
||||
if ($cm = get_coursemodule_from_id('forum', $context->instanceid)) {
|
||||
if ($forum = get_record('forum', 'id', $cm->instance)) {
|
||||
forum_unsubscribe($userid, $forum->id);
|
||||
if (!has_capability('mod/forum:viewdiscussion', $context, $userid)) {
|
||||
forum_unsubscribe($userid, $forum->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user