Commit 963fcbed authored by Richard Mansfield's avatar Richard Mansfield

Add forum setting so that only group admins & moderators can create new topics

parent eb1c12ac
......@@ -62,9 +62,10 @@ else { // edit topic
}
$forum = get_record_sql(
'SELECT f.group AS groupid, f.title, g.name AS groupname, g.grouptype
'SELECT f.group AS groupid, f.title, g.name AS groupname, g.grouptype, ic.value AS newtopicusers
FROM {interaction_instance} f
INNER JOIN {group} g ON (g.id = f.group AND g.deleted = ?)
LEFT OUTER JOIN {interaction_forum_instance_config} ic ON (f.id = ic.forum AND ic.field = \'createtopicusers\')
WHERE f.id = ?
AND f.deleted != ?',
array(0, $forumid, 1)
......@@ -77,7 +78,7 @@ define('GROUP', $forum->groupid);
$membership = user_can_access_forum((int)$forumid);
$moderator = (bool)($membership & INTERACTION_FORUM_MOD);
if (!$membership) {
if (!$membership || ($forum->newtopicusers == 'moderators' && !$moderator)) {
throw new AccessDeniedException(get_string('cantaddtopic', 'interaction.forum'));
}
......
......@@ -50,6 +50,7 @@ $string['Closed'] = 'Closed';
$string['Close'] = 'Close';
$string['closeddescription'] = 'Closed topics can only be replied to by moderators and the group administrators';
$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['currentmoderators'] = 'Current Moderators';
$string['deleteforum'] = 'Delete forum';
$string['deletepost'] = 'Delete post';
......@@ -87,6 +88,7 @@ $string['Key'] = 'Key';
$string['lastpost'] = 'Last post';
$string['latestforumposts'] = 'Latest Forum Posts';
$string['Moderators'] = 'Moderators';
$string['moderatorsandgroupadminsonly'] = 'Moderators and group admins only';
$string['moderatorslist'] = 'Moderators:';
$string['moderatorsdescription'] = 'Moderators can edit and delete topics and posts. They can also open, close, set and unset topics as sticky';
$string['name'] = 'Forum';
......@@ -141,6 +143,7 @@ $string['Unsubscribe'] = 'Unsubscribe';
$string['unsubscribefromforum'] = 'Unsubscribe from forum';
$string['unsubscribefromtopic'] = 'Unsubscribe from topic';
$string['updateselectedtopics'] = 'Update selected topics';
$string['whocancreatetopics'] = 'Who can create topics';
$string['youcannotunsubscribeotherusers'] = 'You cannot unsubscribe other users';
$string['youarenotsubscribedtothisforum'] = 'You are not subscribed to this forum';
$string['youarenotsubscribedtothistopic'] = 'You are not subscribed to this topic';
......
......@@ -30,8 +30,11 @@ 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'));
$instanceconfig = get_records_assoc('interaction_forum_instance_config', 'forum', $instance->get('id'), '', 'field,value');
$autosubscribe = isset($instanceconfig['autosubscribe']) ? $instanceconfig['autosubscribe']->value : false;
$weight = isset($instanceconfig['weight']) ? $instanceconfig['weight']->value : null;
$createtopicusers = isset($instanceconfig['createtopicusers']) ? $instanceconfig['createtopicusers']->value : null;
$moderators = get_column_sql(
'SELECT fm.user FROM {interaction_forum_moderator} fm
JOIN {usr} u ON (fm.user = u.id AND u.deleted = 0)
......@@ -105,7 +108,18 @@ class PluginInteractionForum extends PluginInteraction {
'filter' => false,
'lefttitle' => get_string('potentialmoderators', 'interaction.forum'),
'righttitle' => get_string('currentmoderators', 'interaction.forum')
)
),
'createtopicusers' => array(
'type' => 'select',
'title' => get_string('whocancreatetopics', 'interaction.forum'),
'options' => array('members' => get_string('allgroupmembers', 'group'),
'moderators' => get_string('moderatorsandgroupadminsonly', 'interaction.forum')),
'description' => get_string('createtopicusersdescription', 'interaction.forum'),
'defaultvalue' => (isset($createtopicusers) && $createtopicusers == 'moderators') ? 'moderators' : 'members',
'rules' => array(
'required' => true,
),
),
)
)
);
......@@ -194,6 +208,20 @@ class PluginInteractionForum extends PluginInteraction {
)
);
}
// Create topic users
delete_records_sql(
"DELETE FROM {interaction_forum_instance_config}
WHERE field = 'createtopicusers' AND forum = ?",
array($instance->get('id'))
);
insert_record('interaction_forum_instance_config', (object)array(
'forum' => $instance->get('id'),
'field' => 'createtopicusers',
'value' => $values['createtopicusers'] == 'moderators' ? 'moderators' : 'members',
));
db_commit();
}
......
......@@ -11,7 +11,7 @@
<div id="forumdescription">{$forum->description}</div>
<div id="viewforum" class="rel">
<h3>{str tag=Topics section="interaction.forum"}</h3>
{if $membership}
{if $membership && ($moderator || $forum->newtopicusers != 'moderators') }
<div class="rbuttons">
<a href="{$WWWROOT}interaction/forum/edittopic.php?forum={$forum->id|escape}" class="btn-add s">{str tag="newtopic" section="interaction.forum}</a>
</div>
......
......@@ -46,14 +46,15 @@ $topicsperpage = 25;
$offset = (int)($offset / $topicsperpage) * $topicsperpage;
$forum = get_record_sql(
'SELECT f.title, f.description, f.id, COUNT(t.id) AS topiccount, s.forum AS subscribed, g.id AS groupid, g.name AS groupname
'SELECT f.title, f.description, f.id, COUNT(t.id) AS topiccount, s.forum AS subscribed, g.id AS groupid, g.name AS groupname, ic.value AS newtopicusers
FROM {interaction_instance} f
INNER JOIN {group} g ON (g.id = f."group" AND g.deleted = ?)
LEFT JOIN {interaction_forum_topic} t ON (t.forum = f.id AND t.deleted != 1 AND t.sticky != 1)
LEFT JOIN {interaction_forum_subscription_forum} s ON (s.forum = f.id AND s."user" = ?)
LEFT JOIN {interaction_forum_instance_config} ic ON (f.id = ic.forum AND ic.field = \'createtopicusers\')
WHERE f.id = ?
AND f.deleted != 1
GROUP BY 1, 2, 3, 5, 6, 7',
GROUP BY 1, 2, 3, 5, 6, 7, 8',
array(0, $userid, $forumid)
);
......
......@@ -144,6 +144,7 @@ $string['youaregroupmember'] = 'You are a member of this group';
$string['youowngroup'] = 'You own this group';
$string['groupsnotin'] = 'Groups I\'m not in';
$string['allgroups'] = 'All groups';
$string['allgroupmembers'] = 'All group members';
$string['trysearchingforgroups'] = 'Try %ssearching for groups%s to join!';
$string['nogroupsfound'] = 'No groups found :(';
$string['group'] = 'group';
......
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