Commit 3c7ca373 authored by Richard Mansfield's avatar Richard Mansfield

Add forum option to close new topics by default

Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent be498131
......@@ -63,23 +63,25 @@ else { // edit topic
}
$forum = get_record_sql(
'SELECT f.group AS groupid, f.title, g.name AS groupname, g.grouptype, ic.value AS newtopicusers
'SELECT f.group AS groupid, f.title, g.name AS groupname, g.grouptype
FROM {interaction_instance} f
INNER JOIN {group} g ON (g.id = f.group AND g.deleted = 0)
LEFT OUTER JOIN {interaction_forum_instance_config} ic ON (f.id = ic.forum AND ic.field = \'createtopicusers\')
WHERE f.id = ?
AND f.deleted != 1',
array($forumid)
);
if (!$forum) {
throw new NotFoundException(get_string('cantfindforum', 'interaction.forum', $forumid));
}
$forumconfig = get_records_assoc('interaction_forum_instance_config', 'forum', $forumid, '', 'field,value');
define('GROUP', $forum->groupid);
$membership = user_can_access_forum((int)$forumid);
$moderator = (bool)($membership & INTERACTION_FORUM_MOD);
if (!$membership || ($forum->newtopicusers == 'moderators' && !$moderator)) {
if (!$membership || ($forumconfig['createtopicusers']->value == 'moderators' && !$moderator)) {
throw new AccessDeniedException(get_string('cantaddtopic', 'interaction.forum'));
}
......@@ -134,7 +136,7 @@ $editform = array(
'type' => 'checkbox',
'title' => get_string('Closed', 'interaction.forum'),
'description' => get_string('closeddescription', 'interaction.forum'),
'defaultvalue' => isset($topic) && $topic->closed == 1 ? 'checked' : null
'defaultvalue' => isset($topic) ? $topic->closed : !empty($forumconfig['closetopics']->value),
),
'submit' => array(
'type' => 'submitcancel',
......
......@@ -173,4 +173,7 @@ $string['indentflatindent'] = 'No indents';
$string['indentmodedescription'] = 'Specify how topics in this forum should be indented.';
$string['maxindent'] = 'Maximum Indent Level';
$string['maxindentdescription'] = 'Set the maximum indention level for a topic. This only applies if Indent mode has been set to Expand to max';
?>
$string['closetopics'] = 'Close new topics';
$string['closetopicsdescription'] = 'If checked, all new topics in this forum will be closed by default. Only moderators and group administrators can reply to closed topics.';
......@@ -35,6 +35,7 @@ class PluginInteractionForum extends PluginInteraction {
$autosubscribe = isset($instanceconfig['autosubscribe']) ? $instanceconfig['autosubscribe']->value : false;
$weight = isset($instanceconfig['weight']) ? $instanceconfig['weight']->value : null;
$createtopicusers = isset($instanceconfig['createtopicusers']) ? $instanceconfig['createtopicusers']->value : null;
$closetopics = !empty($instanceconfig['closetopics']);
$indentmode = isset($instanceconfig['indentmode']) ? $instanceconfig['indentmode']->value : null;
$maxindent = isset($instanceconfig['maxindent']) ? $instanceconfig['maxindent']->value : null;
......@@ -147,6 +148,12 @@ class PluginInteractionForum extends PluginInteraction {
'required' => true,
),
),
'closetopics' => array(
'type' => 'checkbox',
'title' => get_string('closetopics', 'interaction.forum'),
'description' => get_string('closetopicsdescription', 'interaction.forum'),
'defaultvalue' => !empty($closetopics),
),
)
)
);
......@@ -274,6 +281,20 @@ EOF;
'value' => $values['createtopicusers'] == 'moderators' ? 'moderators' : 'members',
));
// Close topics
delete_records_sql(
"DELETE FROM {interaction_forum_instance_config}
WHERE field = 'closetopics' AND forum = ?",
array($instance->get('id'))
);
if (!empty($values['closetopics'])) {
insert_record('interaction_forum_instance_config', (object)array(
'forum' => $instance->get('id'),
'field' => 'closetopics',
'value' => 1,
));
}
//Indent mode
delete_records_sql(
"DELETE FROM {interaction_forum_instance_config}
......
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