1

を使用してMoodle 1.9、php経由でユーザーを登録することに成功しました

$user   = get_record("user", "id", $mqval['id']);
$course = get_record("course", "id", $cid);

if ( ! enrol_into_course($course, $user, 'manuel')) { 

} else {
  //echo 'success';
}

次に、同じ方法でユーザーの登録を解除します。を使用してみunenrol_userましたが、うまくいきませんでした。私も試しrole_unassignましたが、成功しませんでした。

4

2 に答える 2

1
//get instance that can unenrol
$enrols = enrol_get_plugins(true);
$enrolinstances = enrol_get_instances($courseid, true);
$unenrolled = false;
foreach ($enrolinstances as $instance) {
    if (!$unenrolled and $enrols[$instance->enrol]->allow_unenrol($instance)) {
        $unenrolinstance = $instance;
        $unenrolled = true;
    }
}

//unenrol the user in every course he's in
$enrolledusercourses = enrol_get_users_courses($userid);
foreach ($enrolledcourses as $course) {
    //unenrol the user
    $enrols[$unenrolinstance->enrol]->unenrol_user($unenrolinstance, $userid, $roleid);
}
于 2012-11-12T14:59:09.087 に答える
0

上記のコードとその動作を変更しました。

//unenrol the user in every course he's in
 $enrols = enrol_get_plugins(true);

$enrolledusercourses = enrol_get_users_courses($user->id);

foreach ($enrolledusercourses as $course) {
    //unenrol the user
    $courseid = $course->id;

    $enrolinstances = enrol_get_instances($courseid, true);
    $unenrolled = false;

    foreach ($enrolinstances as $instance) {
        if (!$unenrolled and $enrols[$instance->enrol]->allow_unenrol($instance)) {
            $unenrolinstance = $instance;
            $unenrolled = true;
        }
    }

    $enrols[$unenrolinstance->enrol]->unenrol_user($unenrolinstance, $user->id, $user->rollid);
}
于 2015-05-15T03:37:10.903 に答える