Example #1
0
function permission_to_move($discussion, $targetforum)
{
    if (is_a($discussion, 'mod_forumng_discussion')) {
        // Check permission for move.
        $discussion->require_view();
        $forum = $discussion->get_forum();
    } else {
        $forum = $discussion;
    }
    $aag = check_move_permissions($forum, $targetforum);
    return $aag;
}
if ($target == 0) {
    $target = required_param('target', PARAM_INT);
}
$targetforum = mod_forumng::get_from_cmid($target, mod_forumng::CLONE_DIRECT);
// Sets up chosen target group.
$chosentargetgroup = optional_param('chosengroup', 0, PARAM_INT);
if (!$targetgroup) {
    $targetgroup = $chosentargetgroup;
}
if (!$targetgroup) {
    $cm = $forum->get_course_module();
    $targetgroup = mod_forumng::get_activity_group($cm, false);
}
// Security check against user and their capabilities.
$forum->require_view($targetgroup);
check_move_permissions($forum, $targetforum);
// If it is a clone, find the original.
$targetforum = $targetforum->get_real_forum();
$targetgroupmode = $targetforum->get_group_mode();
// Get selected ids.
$selectedids = array();
foreach ($_POST as $field => $value) {
    $matches = array();
    if (!is_array($value) && (string) $value !== '0' && preg_match('~^selectd([0-9]+)$~', $field, $matches)) {
        $selectedids[] = $matches[1];
    }
}
if ($targetgroupmode != 0) {
    $targetgroups = get_target_groups($selectedids, $targetforum, mod_forumng::CLONE_DIRECT);
    if (count($targetgroups) == 1) {
        // We have one usable target group.