if ($cloneid) { $pageparams['clone'] = $cloneid; } if (!$target) { print_error('move_notselected', 'forumng'); } $discussion = mod_forumng_discussion::get_from_id($d, $cloneid); // Get target forum. $targetforum = mod_forumng::get_from_cmid($target, mod_forumng::CLONE_DIRECT); // If it is a clone, find the original. $targetforum = $targetforum->get_real_forum(); $targetcmid = $targetforum->get_course_module_id(); // Check permission for move. $aag = permission_to_move($discussion, $targetforum); // Work out target group for move. $targetgroup = get_target_group($discussion, $targetforum, $aag); $groupmode = $targetforum->get_group_mode(); $options = array(); if ($groupmode && !$targetgroup) { $options = get_allowed_groups($targetforum, $aag); // If there's only one then we'll use it. if (count($options) == 1) { reset($options); $targetgroup = key($options); } else { if (count($options) == 0) { print_error('move_nogroups', 'forumng'); } } } if (!$targetgroup && $groupmode > 0) {
$discussion = mod_forumng_discussion::get_from_id($d, $clone); if (!$discussion->is_deleted()) { // Check permission for move. $aag = permission_to_move($discussion, $targetforum); // Check to see whether we have the discussion. // Work out target group for move. $discussiongroupid = $discussion->get_group_id(); if (!$chosentargetgroup) { $targetgroup = 0; if (in_array($discussiongroupid, $options, true)) { $targetgroup = $discussiongroupid; } else { if ($targetgroupmode > 0) { // We have no target group so try to work one out if need be. // Work out target group for move. $targetgroup = get_target_group($discussion, $targetforum, true); } } if ($targetgroupmode == 0) { $targetgroup = 0; } if ($targetgroup == null) { // Target group not found. $targetgroupfound = false; } if ($targetgroup < 1) { // Target forum has no groups so set target group to null. $targetgroup = null; } } // Perform move.
function get_forum_discussions_groups($selectedids, $forum, $cloneid) { $groups = array(); foreach ($selectedids as $d) { // We have the discussions and forum cmid, check to see whether it has groups. $discussion = mod_forumng_discussion::get_from_id($d, $cloneid); // Work out target group. $group = get_target_group($discussion, $forum, true); $groups[] = $group; } $groups = array_unique($groups); return $groups; }