Commit 93d40247 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Create a default forum when creating a group

parent 4bed8a15
...@@ -87,6 +87,11 @@ function xmldb_interaction_forum_upgrade($oldversion=0) { ...@@ -87,6 +87,11 @@ function xmldb_interaction_forum_upgrade($oldversion=0) {
} }
} }
if ($oldversion < 2009081800) {
$subscription = (object) array('plugin' => 'forum', 'event' => 'creategroup', 'callfunction' => 'create_default_forum');
ensure_record_exists('interaction_event_subscription', $subscription, $subscription);
}
return true; return true;
} }
......
...@@ -52,6 +52,8 @@ $string['closeddescription'] = 'Closed topics can only be replied to by moderato ...@@ -52,6 +52,8 @@ $string['closeddescription'] = 'Closed topics can only be replied to by moderato
$string['Count'] = 'Count'; $string['Count'] = 'Count';
$string['createtopicusersdescription'] = 'If set to "All group members", anyone can create new topics and reply to existing topics. If set to "Moderators and group admins", only moderators and group administrators can start new topics, but once topics exist, all users can post replies to them.'; $string['createtopicusersdescription'] = 'If set to "All group members", anyone can create new topics and reply to existing topics. If set to "Moderators and group admins", only moderators and group administrators can start new topics, but once topics exist, all users can post replies to them.';
$string['currentmoderators'] = 'Current Moderators'; $string['currentmoderators'] = 'Current Moderators';
$string['defaultforumtitle'] = 'General Discussion';
$string['defaultforumdescription'] = '%s general discussion forum';
$string['deleteforum'] = 'Delete forum'; $string['deleteforum'] = 'Delete forum';
$string['deletepost'] = 'Delete post'; $string['deletepost'] = 'Delete post';
$string['deletepostsuccess'] = 'Post deleted successfully'; $string['deletepostsuccess'] = 'Post deleted successfully';
......
...@@ -161,14 +161,16 @@ class PluginInteractionForum extends PluginInteraction { ...@@ -161,14 +161,16 @@ class PluginInteractionForum extends PluginInteraction {
'interaction_forum_moderator', 'interaction_forum_moderator',
'forum', $instance->get('id') 'forum', $instance->get('id')
); );
foreach ($values['moderator'] as $user) { if (isset($values['moderator']) && is_array($values['moderator'])) {
insert_record( foreach ($values['moderator'] as $user) {
'interaction_forum_moderator', insert_record(
(object)array( 'interaction_forum_moderator',
'user' => $user, (object)array(
'forum' => $instance->get('id') 'user' => $user,
) 'forum' => $instance->get('id')
); )
);
}
} }
// Re-order the forums according to their new ordering // Re-order the forums according to their new ordering
...@@ -256,6 +258,11 @@ class PluginInteractionForum extends PluginInteraction { ...@@ -256,6 +258,11 @@ class PluginInteractionForum extends PluginInteraction {
'event' => 'userjoinsgroup', 'event' => 'userjoinsgroup',
'callfunction' => 'user_joined_group', 'callfunction' => 'user_joined_group',
), ),
(object)array(
'plugin' => 'forum',
'event' => 'creategroup',
'callfunction' => 'create_default_forum',
),
); );
} }
...@@ -288,6 +295,41 @@ class PluginInteractionForum extends PluginInteraction { ...@@ -288,6 +295,41 @@ class PluginInteractionForum extends PluginInteraction {
} }
} }
/**
* When a group is created, create one forum automatically.
*
* @param array $eventdata
*/
public static function create_default_forum($event, $eventdata) {
global $USER;
$creator = 0;
if (isset($eventdata['members'][$USER->get('id')])) {
$creator = $USER->get('id');
}
else {
foreach($eventdata['members'] as $userid => $role) {
if ($role == 'admin') {
$creator = $userid;
break;
}
}
}
db_begin();
$forum = new InteractionForumInstance(0, (object) array(
'group' => $eventdata['id'],
'creator' => $creator,
'title' => get_string('defaultforumtitle', 'interaction.forum'),
'description' => get_string('defaultforumdescription', 'interaction.forum', $eventdata['name']),
));
$forum->commit();
self::instance_config_save($forum, array(
'createtopicusers' => 'members',
'autosubscribe' => 1,
'justcreated' => 1,
));
db_commit();
}
/** /**
* Optional method. Takes a list of forums and sorts them according to * Optional method. Takes a list of forums and sorts them according to
* their weights for the sideblock * their weights for the sideblock
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
* *
*/ */
$config->version = 2009081700; $config->version = 2009081800;
$config->release = '1.2.0'; $config->release = '1.2.0';
?> ?>
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