Skip to content

Commit

Permalink
Merge branch 'wip-mdl-33166-m23' of git://github.com/rajeshtaneja/moo…
Browse files Browse the repository at this point in the history
…dle into MOODLE_23_STABLE
  • Loading branch information
stronk7 committed Sep 18, 2012
2 parents b437a68 + fd7255a commit e608468
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
10 changes: 10 additions & 0 deletions mod/forum/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
),
);

4 changes: 2 additions & 2 deletions mod/forum/db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
1 change: 1 addition & 0 deletions mod/forum/lang/en/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,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.';
Expand Down
39 changes: 37 additions & 2 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2860,7 +2860,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
Expand Down Expand Up @@ -4623,7 +4623,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));
Expand Down Expand Up @@ -6076,6 +6078,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
*/
Expand All @@ -6098,6 +6101,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
*
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit e608468

Please sign in to comment.