function create_and_enrol_user($student_name, $ruserid, $courseid)
{
    if (preg_match('/^\\s*(.+?)\\s*(\\S+)\\s*$/', $student_name, $names)) {
        $fname = $names[1];
        $sname = $names[2];
    } else {
        $fname = '';
        $sname = $student_name;
    }
    $userid = get_existing_user($ruserid, $fname, $sname);
    if (!$userid) {
        $userid = create_user($ruserid, $fname, $sname);
    }
    enrol_user($userid, $courseid);
}
Exemplo n.º 2
0
function get_enrol_data($users, $courses, $type)
{
    global $DB;
    echo "get_enrol_data started for " . $type . "enrolment, this may take some time..." . PHP_EOL;
    $coursecount = count($courses);
    $usercount = count($users) - 1;
    for ($c = 0; $c < $coursecount; $c++) {
        //echo "Course/Units to enrol to:".$courses[$c][1]. PHP_EOL;
        for ($u = 0; $u < $usercount; $u++) {
            //this will need a check here!
            //if user is in this course then enrol them
            if ($courses[$c][4] == $users[$u][6]) {
                //cohort
                echo "we have a match: student:" . $users[$u][6] . ":" . $users[$u][8] . ":Course:" . $courses[$c][4] . ":" . $courses[$c][6] . PHP_EOL;
                enrol_user($users[$u][8], $courses[$c][6], 3, $type);
            }
            //stops an undefined error when enrolling in cohorts
            if ($type == 'meta') {
                if ($courses[$c][7] == $users[$u][6]) {
                    //meta
                    echo "we have a match: student:" . $users[$u][6] . ":" . $users[$u][8] . ":unit:" . $courses[$c][7] . ":" . $courses[$c][6] . PHP_EOL;
                    //$courses contain units this time
                    enrol_user($users[$u][8], $courses[$c][6], 3, $type);
                }
            }
        }
    }
    echo "get_enrol_data complete for " . $type . " enrolment" . PHP_EOL;
}