mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'wip-MDL-45466-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
c51ad7cbe2
@ -86,8 +86,9 @@ class mod_forum_observer {
|
||||
$forums = $DB->get_records_sql($sql, $params);
|
||||
foreach ($forums as $forum) {
|
||||
// If user doesn't have allowforcesubscribe capability then don't subscribe.
|
||||
if (has_capability('mod/forum:allowforcesubscribe', context_module::instance($forum->cmid), $userid)) {
|
||||
forum_subscribe($userid, $forum->id);
|
||||
$modcontext = context_module::instance($forum->cmid);
|
||||
if (has_capability('mod/forum:allowforcesubscribe', $modcontext, $userid)) {
|
||||
forum_subscribe($userid, $forum->id, $modcontext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -193,9 +193,9 @@ if (!is_null($subscribe)) {
|
||||
if (!forum_is_forcesubscribed($forum)) {
|
||||
$subscribed = forum_is_subscribed($USER->id, $forum);
|
||||
if ((has_capability('moodle/course:manageactivities', $coursecontext, $USER->id) || $forum->forcesubscribe != FORUM_DISALLOWSUBSCRIBE) && $subscribe && !$subscribed && $cansub) {
|
||||
forum_subscribe($USER->id, $forumid);
|
||||
forum_subscribe($USER->id, $forumid, $modcontext);
|
||||
} else if (!$subscribe && $subscribed) {
|
||||
forum_unsubscribe($USER->id, $forumid);
|
||||
forum_unsubscribe($USER->id, $forumid, $modcontext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ function forum_instance_created($context, $forum) {
|
||||
if ($forum->forcesubscribe == FORUM_INITIALSUBSCRIBE) {
|
||||
$users = forum_get_potential_subscribers($context, 0, 'u.id, u.email');
|
||||
foreach ($users as $user) {
|
||||
forum_subscribe($user->id, $forum->id);
|
||||
forum_subscribe($user->id, $forum->id, $context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -241,7 +241,7 @@ function forum_update_instance($forum, $mform) {
|
||||
if (($forum->forcesubscribe == FORUM_INITIALSUBSCRIBE) && ($oldforum->forcesubscribe <> $forum->forcesubscribe)) {
|
||||
$users = forum_get_potential_subscribers($modcontext, 0, 'u.id, u.email', '');
|
||||
foreach ($users as $user) {
|
||||
forum_subscribe($user->id, $forum->id);
|
||||
forum_subscribe($user->id, $forum->id, $modcontext);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4819,12 +4819,12 @@ function forum_get_optional_subscribed_forums() {
|
||||
/**
|
||||
* Adds user to the subscriber list
|
||||
*
|
||||
* @global object
|
||||
* @param int $userid
|
||||
* @param int $forumid
|
||||
* @param context_module|null $context Module context, may be omitted if not known or if called for the current module set in page.
|
||||
*/
|
||||
function forum_subscribe($userid, $forumid) {
|
||||
global $DB;
|
||||
function forum_subscribe($userid, $forumid, $context = null) {
|
||||
global $DB, $PAGE;
|
||||
|
||||
if ($DB->record_exists("forum_subscriptions", array("userid"=>$userid, "forum"=>$forumid))) {
|
||||
return true;
|
||||
@ -4836,9 +4836,18 @@ function forum_subscribe($userid, $forumid) {
|
||||
|
||||
$result = $DB->insert_record("forum_subscriptions", $sub);
|
||||
|
||||
$cm = get_coursemodule_from_instance('forum', $forumid);
|
||||
if (!$context) {
|
||||
// Find out forum context. First try to take current page context to save on DB query.
|
||||
if ($PAGE->cm && $PAGE->cm->modname === 'forum' && $PAGE->cm->instance == $forumid
|
||||
&& $PAGE->context->contextlevel == CONTEXT_MODULE && $PAGE->context->instanceid == $PAGE->cm->id) {
|
||||
$context = $PAGE->context;
|
||||
} else {
|
||||
$cm = get_coursemodule_from_instance('forum', $forumid);
|
||||
$context = context_module::instance($cm->id);
|
||||
}
|
||||
}
|
||||
$params = array(
|
||||
'context' => context_module::instance($cm->id),
|
||||
'context' => $context,
|
||||
'objectid' => $result,
|
||||
'relateduserid' => $userid,
|
||||
'other' => array('forumid' => $forumid),
|
||||
@ -4853,21 +4862,30 @@ function forum_subscribe($userid, $forumid) {
|
||||
/**
|
||||
* Removes user from the subscriber list
|
||||
*
|
||||
* @global object
|
||||
* @param int $userid
|
||||
* @param int $forumid
|
||||
* @param context_module|null $context Module context, may be omitted if not known or if called for the current module set in page.
|
||||
*/
|
||||
function forum_unsubscribe($userid, $forumid) {
|
||||
global $DB;
|
||||
function forum_unsubscribe($userid, $forumid, $context = null) {
|
||||
global $DB, $PAGE;
|
||||
|
||||
$DB->delete_records('forum_digests', array('userid' => $userid, 'forum' => $forumid));
|
||||
|
||||
if ($forumsubscription = $DB->get_record('forum_subscriptions', array('userid' => $userid, 'forum' => $forumid))) {
|
||||
$DB->delete_records('forum_subscriptions', array('id' => $forumsubscription->id));
|
||||
|
||||
$cm = get_coursemodule_from_instance('forum', $forumid);
|
||||
if (!$context) {
|
||||
// Find out forum context. First try to take current page context to save on DB query.
|
||||
if ($PAGE->cm && $PAGE->cm->modname === 'forum' && $PAGE->cm->instance == $forumid
|
||||
&& $PAGE->context->contextlevel == CONTEXT_MODULE && $PAGE->context->instanceid == $PAGE->cm->id) {
|
||||
$context = $PAGE->context;
|
||||
} else {
|
||||
$cm = get_coursemodule_from_instance('forum', $forumid);
|
||||
$context = context_module::instance($cm->id);
|
||||
}
|
||||
}
|
||||
$params = array(
|
||||
'context' => context_module::instance($cm->id),
|
||||
'context' => $context,
|
||||
'objectid' => $forumsubscription->id,
|
||||
'relateduserid' => $userid,
|
||||
'other' => array('forumid' => $forumid),
|
||||
|
@ -50,7 +50,7 @@ if (data_submitted() and $confirm and confirm_sesskey()) {
|
||||
$forums = forum_get_optional_subscribed_forums();
|
||||
|
||||
foreach($forums as $forum) {
|
||||
forum_unsubscribe($USER->id, $forum->id);
|
||||
forum_unsubscribe($USER->id, $forum->id, context_module::instance($forum->cm));
|
||||
}
|
||||
$DB->set_field('user', 'autosubscribe', 0, array('id'=>$USER->id));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user