Commit ddee4f55 authored by Nigel McNie's avatar Nigel McNie

[UPSTREAM] Add form option for forums to say whether they should be auto subscribed to.

If the option is set to yes and the forum has just been created, we subscribe all users in the group immediately.

An event handler (for new event type 'userjoinsgroup') will handle this options.
parent e4be3b17
<h3>Automatically Subscribing Users</h3>
<p>If you want users to automatically be subscribed to posts in this forum when they join, set this option to 'yes'.</p>
<p>When subscribed, users will receive notifications when new posts and replies are made in the forum.</p>
<p>Users will have the option to unsubscribe, if they do not want to be notified.</p>
......@@ -28,6 +28,8 @@ $string['addpostsuccess'] = 'Added post successfully';
$string['addtitle'] = 'Add forum';
$string['addtopic'] = 'Add topic';
$string['addtopicsuccess'] = 'Added topic successfully';
$string['autosubscribeusers'] = 'Automatically subscribe users?';
$string['autosubscribeusersdescription'] = 'Choose whether group users will automatically be subscribed to this forum';
$string['Body'] = 'Body';
$string['cantaddposttoforum'] = 'You are not allowed to post in this forum';
$string['cantaddposttotopic'] = 'You are not allowed to post in this topic';
......
......@@ -30,6 +30,7 @@ class PluginInteractionForum extends PluginInteraction {
public static function instance_config_form($group, $instance=null) {
if (isset($instance)) {
$autosubscribe = get_field('interaction_forum_instance_config', 'value', 'field', 'autosubscribe', 'forum', $instance->get('id'));
$weight = get_field('interaction_forum_instance_config', 'value', 'field', 'weight', 'forum', $instance->get('id'));
$moderators = get_column_sql(
'SELECT fm.user FROM {interaction_forum_moderator} fm
......@@ -71,6 +72,18 @@ class PluginInteractionForum extends PluginInteraction {
'collapsed' => true,
'legend' => get_string('settings'),
'elements' => array(
'autosubscribe' => array(
'type' => 'select',
'title' => get_string('autosubscribeusers', 'interaction.forum'),
'options' => array(true => get_string('yes'),
false => get_string('no')),
'description' => get_string('autosubscribeusersdescription', 'interaction.forum'),
'defaultvalue' => isset($autosubscribe) ? $autosubscribe : false,
'rules' => array(
'required' => true,
),
'help' => true,
),
'weight' => array(
'type' => 'weight',
'title' => get_string('Order', 'interaction.forum'),
......@@ -100,6 +113,35 @@ class PluginInteractionForum extends PluginInteraction {
public static function instance_config_save($instance, $values){
db_begin();
// Autosubscribe
delete_records_sql(
"DELETE FROM {interaction_forum_instance_config}
WHERE field = 'autosubscribe' AND forum = ?",
array($instance->get('id'))
);
insert_record('interaction_forum_instance_config', (object)array(
'forum' => $instance->get('id'),
'field' => 'autosubscribe',
'value' => (bool)$values['autosubscribe'],
));
if ($values['justcreated']) {
// Subscribe all existing users in the group to the forums
if ($userids = get_column('group_member', 'member', 'group', $instance->get('group'))) {
foreach ($userids as $userid) {
insert_record(
'interaction_forum_subscription_forum',
(object)array(
'forum' => $instance->get('id'),
'user' => $userid,
)
);
}
}
}
// Moderators
delete_records(
'interaction_forum_moderator',
'forum', $instance->get('id')
......
Markdown is supported
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