Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'wip-mdl-33166' of git://github.com/rajeshtaneja/moodle

  • Loading branch information...
commit a9c31deea86530bc803a23dd7a0702b05ee8bb32 2 parents 1f8ee5c + 1659b1d
@stronk7 stronk7 authored
View
10 mod/forum/db/access.php
@@ -334,5 +334,15 @@
'manager' => CAP_ALLOW
)
),
+ 'mod/forum:allowforcesubscribe' => array(
+
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'archetypes' => array(
+ 'student' => CAP_ALLOW,
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW
+ )
+ ),
);
View
4 mod/forum/db/events.php
@@ -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,
),
View
1  mod/forum/lang/en/forum.php
@@ -156,6 +156,7 @@
$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.';
View
39 mod/forum/lib.php
@@ -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
*/
@@ -6156,6 +6159,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
*
* @param stdClass $cp
View
2  mod/forum/version.php
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.