Commit afef965e authored by Sam Hemelryk's avatar Sam Hemelryk
Browse files

mod-forum MDL-22114 Enhanced navigation options for forum in regards to subscription.

parent 105666bb
......@@ -38,7 +38,6 @@ $string['aggregatetype'] = 'Aggregate type';
$string['ajaxrating'] = 'Enable AJAX rating';
$string['allforums'] = 'All forums';
$string['allowdiscussions'] = 'Can a {$a} post to this forum?';
$string['allowchoice'] = 'Allow everyone to choose';
$string['allowratings'] = 'Allow posts to be rated?';
$string['allowsallsubscribe'] = 'This forum allows everyone to choose whether to subscribe or not';
$string['allowsdiscussions'] = 'This forum allows each person to start one discussion topic.';
......@@ -193,6 +192,7 @@ $string['introsocial'] = 'An open forum for chatting about anything you want to'
$string['introteacher'] = 'A forum for teacher-only notes and discussion';
$string['invalidaccess'] = 'This page was not accessed correctly';
$string['invaliddiscussionid'] = 'Discussion ID was incorrect or no longer exists';
$string['invalidforcesubscribe'] = 'Invalid force subscription mode';
$string['invalidforumid'] = 'Forum ID was incorrect';
$string['invalidparentpostid'] = 'Parent post ID was incorrect';
$string['invalidpostid'] = 'Invalid Post ID - {$a}';
......@@ -239,6 +239,7 @@ $string['noguestsubscribe'] = 'Sorry, guests are not allowed to subscribe to rec
$string['noguesttracking'] = 'Sorry, guests are not allowed to set tracking options.';
$string['nomorepostscontaining'] = 'No more posts containing \'{$a}\' were found';
$string['nonews'] = 'No news has been posted yet';
$string['noonecansubscribenow'] = 'Subscriptions are now disallowed';
$string['nopermissiontosubscribe'] = 'You do not have the permission to view forum subscribers';
$string['nopermissiontoview'] = 'You do not have permissions to view this post';
$string['nopostforum'] = 'Sorry, you are not allowed to post to this forum';
......@@ -353,6 +354,11 @@ $string['subscribersto'] = 'Subscribers to \'{$a}\'';
$string['subscribestart'] = 'Send me email copies of posts to this forum';
$string['subscribestop'] = 'I don\'t want email copies of posts to this forum';
$string['subscription'] = 'Subscription';
$string['subscriptionmode'] = 'Subscription mode';
$string['subscriptionoptional'] = 'Optional subscription';
$string['subscriptionforced'] = 'Forced subscription';
$string['subscriptionauto'] = 'Auto subscription';
$string['subscriptiondisabled'] = 'Subscription disabled';
$string['subscriptions'] = 'Subscriptions';
$string['thisforumisthrottled'] = 'This forum has a limit to the number of forum postings you can make in a given time period - this is currently set at {$a->blockafter} posting(s) in {$a->blockperiod}';
$string['timedposts'] = 'Timed posts';
......@@ -377,8 +383,6 @@ $string['unsubscribeshort'] = 'Unsubscribe';
$string['usermarksread'] = 'Manual message read marking';
$string['viewalldiscussions'] = 'View all discussions';
$string['warnafter'] = 'Post threshold for warning';
$string['yesforever'] = 'Yes, forever';
$string['yesinitially'] = 'Yes, initially';
$string['youratedthis'] = 'You rated this';
$string['yournewquestion'] = 'Your new question';
$string['yournewtopic'] = 'Your new discussion topic';
......
......@@ -34,6 +34,7 @@ define('FORUM_MODE_FLATNEWEST', -1);
define('FORUM_MODE_THREADED', 2);
define('FORUM_MODE_NESTED', 3);
define('FORUM_CHOOSESUBSCRIBE', 0);
define('FORUM_FORCESUBSCRIBE', 1);
define('FORUM_INITIALSUBSCRIBE', 2);
define('FORUM_DISALLOWSUBSCRIBE',3);
......@@ -4824,6 +4825,15 @@ function forum_is_forcesubscribed($forum) {
}
}
function forum_get_forcesubscribed($forum) {
global $DB;
if (isset($forum->forcesubscribe)) { // then we use that
return $forum->forcesubscribe;
} else { // Check the database
return $DB->get_field('forum', 'forcesubscribe', array('id' => $forum));
}
}
/**
* @global object
* @param int $userid
......@@ -8029,47 +8039,69 @@ function forum_extend_settings_navigation(settings_navigation $settingsnav, navi
if (is_enrolled($PAGE->cm->context)) { // means enrolled users only
$notenode = false;
$helpbutton = false;
if (forum_is_forcesubscribed($forumobject)) {
$notenode = $forumnode->add(get_string("forcessubscribe", 'forum'));
$string = get_string('allowchoice', 'forum');
$helpbutton = $OUTPUT->old_help_icon("subscription", $string, "forum");
if (has_capability('mod/forum:managesubscriptions', $PAGE->cm->context)) {
$url = new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'force'=>'no'));
$forumnode->add($string, $url, navigation_node::TYPE_SETTING);
} else {
$forumnode->add(get_string('everyoneisnowsubscribed', 'forum'), null, navigation_node::TYPE_SETTING);
$canmanage = has_capability('mod/forum:managesubscriptions', $PAGE->cm->context);
$subscriptionmode = forum_get_forcesubscribed($forumobject);
$cansubscribe = ($subscriptionmode != FORUM_FORCESUBSCRIBE && ($subscriptionmode != FORUM_DISALLOWSUBSCRIBE || $canmanage));
if ($canmanage) {
$mode = $forumnode->add(get_string('subscriptionmode', 'forum'), null, navigation_node::TYPE_CONTAINER);
$allowchoice = $mode->add(get_string('subscriptionoptional', 'forum'), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>'0')), navigation_node::TYPE_SETTING);
$forceforever = $mode->add(get_string("subscriptionforced", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>'1')), navigation_node::TYPE_SETTING);
$forceinitially = $mode->add(get_string("subscriptionauto", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>'2')), navigation_node::TYPE_SETTING);
$disallowchoice = $mode->add(get_string('subscriptiondisabled', 'forum'), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>'3')), navigation_node::TYPE_SETTING);
switch ($subscriptionmode) {
case FORUM_CHOOSESUBSCRIBE : // 0
$allowchoice->action = null;
$allowchoice->add_class('activesetting');
break;
case FORUM_FORCESUBSCRIBE : // 1
$forceforever->action = null;
$forceforever->add_class('activesetting');
break;
case FORUM_INITIALSUBSCRIBE : // 2
$forceinitially->action = null;
$forceinitially->add_class('activesetting');
break;
case FORUM_DISALLOWSUBSCRIBE : // 3
$disallowchoice->action = null;
$disallowchoice->add_class('activesetting');
break;
}
} else if ($forumobject->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
$string = get_string('disallowsubscribe', 'forum');
$notenode = $forumnode->add($string);
$helpbutton = $OUTPUT->old_help_icon("subscription", $string, "forum");
} else {
$string = get_string("forcesubscribe", "forum");
$notenode = $forumnode->add(get_string("allowsallsubscribe", 'forum'));
$helpbutton = $OUTPUT->old_help_icon("subscription", $string, "forum");
if (has_capability('mod/forum:managesubscriptions', $PAGE->cm->context)) {
$url = new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'force'=>'yes'));
$forumnode->add($string, $url, navigation_node::TYPE_SETTING);
} else {
$forumnode->add(get_string('everyonecannowchoose', 'forum'), null, navigation_node::TYPE_SETTING);
}
if(has_capability('mod/forum:viewsubscribers', $PAGE->cm->context)){
$url = new moodle_url('/mod/forum/subscribers.php', array('id'=>$forumobject->id));
$forumnode->add(get_string('showsubscribers', 'forum'), $url, navigation_node::TYPE_SETTING);
switch ($subscriptionmode) {
case FORUM_CHOOSESUBSCRIBE : // 0
$notenode = $forumnode->add(get_string('subscriptionoptional', 'forum'));
break;
case FORUM_FORCESUBSCRIBE : // 1
$notenode = $forumnode->add(get_string('subscriptionforced', 'forum'));
break;
case FORUM_INITIALSUBSCRIBE : // 2
$notenode = $forumnode->add(get_string('subscriptionauto', 'forum'));
break;
case FORUM_DISALLOWSUBSCRIBE : // 3
$notenode = $forumnode->add(get_string('subscriptiondisabled', 'forum'));
break;
}
}
if (forum_is_forcesubscribed($forumobject) || ($forumobject->forcesubscribe == FORUM_DISALLOWSUBSCRIBE && !has_capability('mod/forum:managesubscriptions', $PAGE->cm->context))) {
// Do nothing
if ($cansubscribe) {
if (forum_is_subscribed($USER->id, $forumobject)) {
$linktext = get_string('unsubscribe', 'forum');
} else {
if (forum_is_subscribed($USER->id, $forumobject)) {
$linktext = get_string('unsubscribe', 'forum');
} else {
$linktext = get_string('subscribe', 'forum');
}
$url = new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id));
$forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
$linktext = get_string('subscribe', 'forum');
}
$url = new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id));
$forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
}
if (has_capability('mod/forum:viewsubscribers', $PAGE->cm->context)){
$url = new moodle_url('/mod/forum/subscribers.php', array('id'=>$forumobject->id));
$forumnode->add(get_string('showsubscribers', 'forum'), $url, navigation_node::TYPE_SETTING);
}
if (forum_tp_can_track_forums($forumobject)) {
......@@ -8081,12 +8113,6 @@ function forum_extend_settings_navigation(settings_navigation $settingsnav, navi
$url = new moodle_url('/mod/forum/settracking.php', array('id'=>$forumobject->id));
$forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
}
if ($notenode!==false) {
$notenode->add_class('note');
if ($helpbutton!==false) {
$notenode->helpbutton = $helpbutton;
}
}
}
if (!empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds) && $forumobject->rsstype && $forumobject->rssarticles) {
......
......@@ -52,11 +52,11 @@ class mod_forum_mod_form extends moodleform_mod {
$this->add_intro_editor(true, get_string('forumintro', 'forum'));
$options = array();
$options[0] = get_string('no');
$options[1] = get_string('yesforever', 'forum');
$options[FORUM_INITIALSUBSCRIBE] = get_string('yesinitially', 'forum');
$options[FORUM_DISALLOWSUBSCRIBE] = get_string('disallowsubscribe','forum');
$mform->addElement('select', 'forcesubscribe', get_string('forcesubscribeq', 'forum'), $options);
$options[FORUM_CHOOSESUBSCRIBE] = get_string('subscriptionoptional', 'forum');
$options[FORUM_FORCESUBSCRIBE] = get_string('subscriptionforced', 'forum');
$options[FORUM_INITIALSUBSCRIBE] = get_string('subscriptionauto', 'forum');
$options[FORUM_DISALLOWSUBSCRIBE] = get_string('subscriptiondisabled','forum');
$mform->addElement('select', 'forcesubscribe', get_string('subscriptionmode', 'forum'), $options);
$mform->setHelpButton('forcesubscribe', array('subscription2', get_string('forcesubscribeq', 'forum'), 'forum'));
$options = array();
......
......@@ -27,12 +27,12 @@ require_once("../../config.php");
require_once("lib.php");
$id = required_param('id',PARAM_INT); // The forum to subscribe or unsubscribe to
$force = optional_param('force','',PARAM_ALPHA); // Force everyone to be subscribed to this forum?
$mode = optional_param('mode',false,PARAM_INT); // Force everyone to be subscribed to this forum?
$user = optional_param('user',0,PARAM_INT);
$url = new moodle_url('/mod/forum/subscribe.php', array('id'=>$id));
if ($force !== '') {
$url->param('force', $force);
if ($mode !== '') {
$url->param('force', $mode);
}
if ($user !== 0) {
$url->param('user', $user);
......@@ -88,13 +88,26 @@ $returnto = optional_param('backtoindex',0,PARAM_INT)
? "index.php?id=".$course->id
: "view.php?f=$id";
if ($force and has_capability('mod/forum:managesubscriptions', $context)) {
if (forum_is_forcesubscribed($forum)) {
forum_forcesubscribe($forum->id, 0);
redirect($returnto, get_string("everyonecannowchoose", "forum"), 1);
} else {
forum_forcesubscribe($forum->id, 1);
redirect($returnto, get_string("everyoneisnowsubscribed", "forum"), 1);
if ($mode !== false && has_capability('mod/forum:managesubscriptions', $context)) {
switch ($mode) {
case FORUM_CHOOSESUBSCRIBE : // 0
forum_forcesubscribe($forum->id, 0);
redirect($returnto, get_string("everyonecannowchoose", "forum"), 1);
break;
case FORUM_FORCESUBSCRIBE : // 1
forum_forcesubscribe($forum->id, 1);
redirect($returnto, get_string("everyoneisnowsubscribed", "forum"), 1);
break;
case FORUM_INITIALSUBSCRIBE : // 2
forum_forcesubscribe($forum->id, 2);
redirect($returnto, get_string("everyoneisnowsubscribed", "forum"), 1);
break;
case FORUM_DISALLOWSUBSCRIBE : // 3
forum_forcesubscribe($forum->id, 3);
redirect($returnto, get_string("noonecansubscribenow", "forum"), 1);
break;
default:
print_error(get_string('invalidforcesubscribe', 'forum'));
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment