Ejemplo n.º 1
0
function get_target_group($discussion, $targetforum, $aag = true)
{
    // Work out target group for move.
    $targetgroup = $discussion->get_group_id();
    if ($targetforum->get_group_mode() == 0) {
        // Target forum doesn't have groups.
        $targetgroup = null;
    } else {
        if (!$targetgroup && $aag && $discussion->get_forum()->get_group_mode() != 0) {
            $targetgroup = null;
        } else {
            if ($targetgroup && $targetforum->get_grouping() != $discussion->get_forum()->get_grouping()) {
                // Target forum has groups :( Need to decide a group.
                // Had source group, but grouping has changed.
                // See if old group belongs to new grouping.
                $allowedgroups = groups_get_all_groups($targetforum->get_course_id(), 0, $targetforum->get_grouping(), 'g.id');
                if (count($allowedgroups) == 1) {
                    $targetgroup = key($allowedgroups);
                } else {
                    if (!array_key_exists($targetgroup, $allowedgroups)) {
                        // Old group not in new grouping, so don't know where to put it.
                        $targetgroup = null;
                    }
                }
            } else {
                // Check to see whether a single or multigroup forum.
                $groupids = get_allowed_groupids($targetforum, $aag);
                if (count($groupids) == 1) {
                    $targetgroup = key($groupids);
                } else {
                    if (!array_key_exists($targetgroup, $groupids)) {
                        $targetgroup = null;
                    }
                }
            }
        }
    }
    return $targetgroup;
}
        } else {
            $targetgroups[0] = 0;
        }
    } else {
        if (count($targetgroups) == 0) {
            $targetgroups[0] = 0;
        } else {
            $multigroups = 1;
        }
    }
}
$targetgroupdiff = 1;
$groupsfound = true;
$options = array();
if ($targetgroupmode) {
    $options = get_allowed_groupids($targetforum, false);
    // Need to find the difference between original groups and options.
    // See http://www.php.net/manual/en/function.array-diff.php .
    $result = array_diff($targetgroups, $options);
    $targetgroupdiff = count($result);
    $optionsnum = count($options);
    // Check to see whether we have some matching groups.
    $optionsdiff = count(array_diff($options, $targetgroups));
    if ($optionsnum === $optionsdiff) {
        // No groups found.
        $groupsfound = false;
    }
}
if (!$chosentargetgroup && $targetgroup > 0 && !$groupsfound) {
    // Target group set from source forum, but not in target - ensure choice given.
    $targetgroup = 0;