Пример #1
0
    $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $systemcontext);
    foreach ($roles as $role) {
        if (!isset($canviewroles[$role->id])) {
            // Avoid this role (eg course creator)
            continue;
        }
        if (isset($doanythingroles[$role->id])) {
            // Avoid this role (ie admin)
            continue;
        }
        $rolenames[$role->id] = strip_tags(role_get_name($role, $context));
        // Used in menus etc later on
    }
}
/// Create the form
$editform = new autogroup_form(null, array('roles' => $rolenames));
$editform->set_data(array('courseid' => $courseid, 'seed' => time()));
/// Handle form submission
if ($editform->is_cancelled()) {
    redirect($returnurl);
} elseif ($data = $editform->get_data(false)) {
    /// Allocate members from the selected role to groups
    switch ($data->allocateby) {
        case 'no':
        case 'random':
        case 'lastname':
            $orderby = 'lastname, firstname';
            break;
        case 'firstname':
            $orderby = 'firstname, lastname';
            break;