Commit c5d19347 authored by Son Nguyen's avatar Son Nguyen

Move topics forums within a group (Bug 1231316)

- Add a new action 'moveto'
- Get the list of other forums in a group
- Update the interaction_forum_topic table
- Send notifications to the new forum's subscribers
- Update the help file

Change-Id: I99ada6003b340e65f11bddfebced759f5865429a
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent b6118859
......@@ -8,3 +8,4 @@
<p><strong>Unsticky</strong>: selected topics will no longer appear at the top of every page.</p>
<p><strong>Open</strong>: all group members will be able to post to selected topics.</p>
<p><strong>Close</strong>: only the group administrators and forum moderators will be able to post to selected topics.</p>
<p><strong>Move to</strong>: only the group administrators and forum moderators will be able to move selected topics to another forum.</p>
......@@ -178,7 +178,11 @@ $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';
$string['Moveto'] = 'Move to';
$string['topicmovedsuccess'] = array(
0 => 'Topic has been moved successfully.',
1 => '%d topics have been moved successfully.',
);
$string['today'] = 'Today';
$string['yesterday'] = 'Yesterday';
$string['strftimerecentrelative'] = '%%v, %%k:%%M';
......
......@@ -41,7 +41,7 @@
<div>{$pagination|safe}</div>
{/if}
{if $membership && (!$forum->subscribed || $moderator)}
<div class="forumselectwrap"><select name="type">
<div class="forumselectwrap"><select name="type" id="action">
<option value="default" selected="selected">{str tag="chooseanaction" section="interaction.forum"}</option>
{if !$forum->subscribed}
<option value="subscribe">{str tag="Subscribe" section="interaction.forum"}</option>
......@@ -53,7 +53,17 @@
<option value="closed">{str tag="Close" section="interaction.forum"}</option>
<option value="open">{str tag="Open" section="interaction.forum"}</option>
{/if}
{if $admin && $otherforums && (count($otherforums) > 0)}
<option value="moveto">{str tag="Moveto" section="interaction.forum"}</option>
{/if}
</select>
{if $admin && $otherforums && (count($otherforums) > 0)}
<select name="newforum" id="otherforums" class="hidden">
{foreach from=$otherforums item=otherforum}
<option value="{$otherforum->id}">{$otherforum->title}</option>
{/foreach}
</select>
{/if}
<input type="submit" name="updatetopics" value="{str tag="updateselectedtopics" section="interaction.forum"}" class="submit">
{if $moderator}
{contextualhelp plugintype='interaction' pluginname='forum' section='updatemod'}
......
......@@ -43,12 +43,12 @@ $forum = get_record_sql(
array(0, $userid, $forumid)
);
define('GROUP', $forum->groupid);
if (!$forum) {
throw new InteractionInstanceNotFoundException(get_string('cantfindforum', 'interaction.forum', $forumid));
}
define('GROUP', $forum->groupid);
$membership = user_can_access_forum((int)$forumid);
$admin = (bool)($membership & INTERACTION_FORUM_ADMIN);
$moderator = (bool)($membership & INTERACTION_FORUM_MOD);
......@@ -58,6 +58,17 @@ if (!$membership && !$publicgroup) {
throw new GroupAccessDeniedException(get_string('cantviewforums', 'interaction.forum'));
}
$otherforums = get_records_sql_array(
'SELECT *
FROM {interaction_instance} f
WHERE f.id <> ?
AND f.group = ?
AND f.deleted = 0
AND f.plugin = ?
ORDER BY f.title',
array($forumid, $forum->groupid, 'forum')
);
$ineditwindow = group_within_edit_window($group);
if (!$ineditwindow) {
$moderator = false;
......@@ -101,6 +112,16 @@ if ($membership && isset($_POST['checked'])) {
set_field_select('interaction_forum_topic', 'closed', 0, 'id IN (' . implode(',', $checked) . ')', array());
$SESSION->add_ok_msg(get_string('topicopenedsuccess', 'interaction.forum'));
}
else if ($moderator && $type == 'moveto') {
$newforumid = param_integer('newforum');
// Check if the new forum is in the current group
$newforum = interaction_instance_from_id($newforumid);
if ($newforum && $newforum->get('group') == $forum->groupid) {
set_field_select('interaction_forum_topic', 'forum', $newforumid, 'id IN (' . implode(',', $checked) . ')', array());
PluginInteractionForum::interaction_forum_new_post($checked);
$SESSION->add_ok_msg(get_string('topicmovedsuccess', 'interaction.forum', count($checked)));
}
}
else if ($type == 'subscribe' && !$forum->subscribed) {
db_begin();
foreach ($checked as $key => $value) {
......@@ -234,6 +255,16 @@ addLoadEvent(function() {
}
});
});
if (action = document.getElementById('action')) {
connect(action, 'onchange', function(e) {
if (this.options[this.selectedIndex].value == 'moveto') {
\$j('#otherforums').removeClass('hidden');
}
else {
\$j('#otherforums').addClass('hidden');
}
});
}
});
EOF;
......@@ -246,6 +277,7 @@ $smarty = smarty(array(), $headers, array(), array());
$smarty->assign('heading', $forum->groupname);
$smarty->assign('subheading', $forum->title);
$smarty->assign('forum', $forum);
$smarty->assign('otherforums', $otherforums);
$smarty->assign('publicgroup', $publicgroup);
$smarty->assign('ineditwindow', $ineditwindow);
$smarty->assign('feedlink', $feedlink);
......
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