Skip to content

Commit

Permalink
MDL-1626 mod_forum: Move subscription management to a separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jun 24, 2014
1 parent 361a41d commit 59075a4
Show file tree
Hide file tree
Showing 18 changed files with 1,268 additions and 396 deletions.
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@
if (isloggedin()) {
$SESSION->fromdiscussion = $CFG->wwwroot;
$subtext = '';
if (forum_is_subscribed($USER->id, $newsforum)) {
if (!forum_is_forcesubscribed($newsforum)) {
if (\mod_forum\subscriptions::is_subscribed($USER->id, $newsforum)) {
if (!\mod_forum\subscriptions::is_forcesubscribed($newsforum)) {
$subtext = get_string('unsubscribe', 'forum');
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions mod/forum/classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static function role_assigned(\core\event\role_assigned $event) {
require_once($CFG->dirroot . '/mod/forum/lib.php');

$userid = $event->relateduserid;
$sql = "SELECT f.id, cm.id AS cmid
$sql = "SELECT f.id, cm.id AS cmid, f.forcesubscribe
FROM {forum} f
JOIN {course_modules} cm ON (cm.instance = f.id)
JOIN {modules} m ON (m.id = cm.module)
Expand All @@ -88,7 +88,7 @@ public static function role_assigned(\core\event\role_assigned $event) {
// If user doesn't have allowforcesubscribe capability then don't subscribe.
$modcontext = context_module::instance($forum->cmid);
if (has_capability('mod/forum:allowforcesubscribe', $modcontext, $userid)) {
forum_subscribe($userid, $forum->id, $modcontext);
\mod_forum\subscriptions::subscribe_user($userid, $forum, $modcontext);
}
}
}
Expand Down
29 changes: 14 additions & 15 deletions mod/forum/classes/post_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,27 @@ function definition() {
$mform->setType('message', PARAM_RAW);
$mform->addRule('message', get_string('required'), 'required', null, 'client');

if (isset($forum->id) && forum_is_forcesubscribed($forum)) {
if (isset($forum->id) && \mod_forum\subscriptions::is_forcesubscribed($forum)) {

$mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('everyoneissubscribed', 'forum'));
$mform->addElement('hidden', 'subscribe');
$mform->setType('subscribe', PARAM_INT);
$mform->addHelpButton('subscribemessage', 'subscription', 'forum');

} else if (isset($forum->forcesubscribe)&& $forum->forcesubscribe != FORUM_DISALLOWSUBSCRIBE ||
has_capability('moodle/course:manageactivities', $coursecontext)) {
} else if (\mod_forum\subscriptions::subscription_disabled($forum) ||
has_capability('moodle/course:manageactivities', $coursecontext)) {
$options = array();
$options[0] = get_string('subscribestop', 'forum');
$options[1] = get_string('subscribestart', 'forum');

$options = array();
$options[0] = get_string('subscribestop', 'forum');
$options[1] = get_string('subscribestart', 'forum');

$mform->addElement('select', 'subscribe', get_string('subscription', 'forum'), $options);
$mform->addHelpButton('subscribe', 'subscription', 'forum');
} else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
$mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('disallowsubscribe', 'forum'));
$mform->addElement('hidden', 'subscribe');
$mform->setType('subscribe', PARAM_INT);
$mform->addHelpButton('subscribemessage', 'subscription', 'forum');
}
$mform->addElement('select', 'subscribe', get_string('subscription', 'forum'), $options);
$mform->addHelpButton('subscribe', 'subscription', 'forum');
} else if (\mod_forum\subscriptions::is_forcesubscribed($forum)) {
$mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('disallowsubscribe', 'forum'));
$mform->addElement('hidden', 'subscribe');
$mform->setType('subscribe', PARAM_INT);
$mform->addHelpButton('subscribemessage', 'subscription', 'forum');
}

if (!empty($forum->maxattachments) && $forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext)) { // 1 = No attachments at all
$mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'), null, self::attachment_options($forum));
Expand Down
Loading

0 comments on commit 59075a4

Please sign in to comment.