mirror of
https://github.com/moodle/moodle.git
synced 2025-03-09 18:30:03 +01:00
MDL-33166 Forum: Adding capability mod/forum:allowforcesubscribe
Conflicts: mod/forum/version.php
This commit is contained in:
parent
c8ac480979
commit
1659b1d1a8
@ -334,5 +334,15 @@ $capabilities = array(
|
||||
'manager' => CAP_ALLOW
|
||||
)
|
||||
),
|
||||
'mod/forum:allowforcesubscribe' => array(
|
||||
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_MODULE,
|
||||
'archetypes' => array(
|
||||
'student' => CAP_ALLOW,
|
||||
'teacher' => CAP_ALLOW,
|
||||
'editingteacher' => CAP_ALLOW
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -25,9 +25,9 @@
|
||||
|
||||
/* List of handlers */
|
||||
$handlers = array (
|
||||
'user_enrolled' => array (
|
||||
'role_assigned' => array (
|
||||
'handlerfile' => '/mod/forum/lib.php',
|
||||
'handlerfunction' => 'forum_user_enrolled',
|
||||
'handlerfunction' => 'forum_user_role_assigned',
|
||||
'schedule' => 'instant',
|
||||
'internal' => 1,
|
||||
),
|
||||
|
@ -156,6 +156,7 @@ $string['forum'] = 'Forum';
|
||||
$string['forum:addinstance'] = 'Add a new forum';
|
||||
$string['forum:addnews'] = 'Add news';
|
||||
$string['forum:addquestion'] = 'Add question';
|
||||
$string['forum:allowforcesubscribe'] = 'Allow force subscribe';
|
||||
$string['forumauthorhidden'] = 'Author (hidden)';
|
||||
$string['forumblockingalmosttoomanyposts'] = 'You are approaching the posting threshold. You have posted {$a->numposts} times in the last {$a->blockperiod} and the limit is {$a->blockafter} posts.';
|
||||
$string['forumbodyhidden'] = 'This post cannot be viewed by you, probably because you have not posted in the discussion or the maximum editing time hasn\'t passed yet.';
|
||||
|
@ -2861,7 +2861,7 @@ function forum_get_potential_subscribers($forumcontext, $groupid, $fields, $sort
|
||||
global $DB;
|
||||
|
||||
// only active enrolled users or everybody on the frontpage
|
||||
list($esql, $params) = get_enrolled_sql($forumcontext, '', $groupid, true);
|
||||
list($esql, $params) = get_enrolled_sql($forumcontext, 'mod/forum:allowforcesubscribe', $groupid, true);
|
||||
|
||||
$sql = "SELECT $fields
|
||||
FROM {user} u
|
||||
@ -4680,7 +4680,9 @@ function forum_is_subscribed($userid, $forum) {
|
||||
if (is_numeric($forum)) {
|
||||
$forum = $DB->get_record('forum', array('id' => $forum));
|
||||
}
|
||||
if (forum_is_forcesubscribed($forum)) {
|
||||
// If forum is force subscribed and has allowforcesubscribe, then user is subscribed.
|
||||
if (forum_is_forcesubscribed($forum) &&
|
||||
has_capability('mod/forum:allowforcesubscribe', context_module::instance($forum->id), $userid)) {
|
||||
return true;
|
||||
}
|
||||
return $DB->record_exists("forum_subscriptions", array("userid" => $userid, "forum" => $forum->id));
|
||||
@ -6133,6 +6135,7 @@ function forum_update_subscriptions_button($courseid, $forumid) {
|
||||
/**
|
||||
* This function gets run whenever user is enrolled into course
|
||||
*
|
||||
* @deprecated deprecating this function as we will be using forum_user_role_assigned
|
||||
* @param stdClass $cp
|
||||
* @return void
|
||||
*/
|
||||
@ -6155,6 +6158,38 @@ function forum_user_enrolled($cp) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function gets run whenever user is assigned role in course
|
||||
*
|
||||
* @param stdClass $cp
|
||||
* @return void
|
||||
*/
|
||||
function forum_user_role_assigned($cp) {
|
||||
global $DB;
|
||||
|
||||
$context = context::instance_by_id($cp->contextid, MUST_EXIST);
|
||||
|
||||
// If contextlevel is course then only subscribe user. Role assignment
|
||||
// at course level means user is enroled in course and can subscribe to forum.
|
||||
if ($context->contextlevel != CONTEXT_COURSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = "SELECT f.id
|
||||
FROM {forum} f
|
||||
LEFT JOIN {forum_subscriptions} fs ON (fs.forum = f.id AND fs.userid = :userid)
|
||||
WHERE f.course = :courseid AND f.forcesubscribe = :initial AND fs.id IS NULL";
|
||||
$params = array('courseid'=>$context->instanceid, 'userid'=>$cp->userid, 'initial'=>FORUM_INITIALSUBSCRIBE);
|
||||
|
||||
$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->id), $cp->userid)) {
|
||||
forum_subscribe($cp->userid, $forum->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function gets run whenever user is unenrolled from course
|
||||
*
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$module->version = 2012061700; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->version = 2012061701; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->requires = 2012061700; // Requires this Moodle version
|
||||
$module->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)
|
||||
$module->cron = 60;
|
||||
|
Loading…
x
Reference in New Issue
Block a user