Unable to manual enrol: enrol_manual_enrol_users

Re: Unable to manual enrol: enrol_manual_enrol_users

by Tim Titchmarsh -
Number of replies: 0

Hi Elias


Its been a while - I think this is what you mean.

It seems an omission in the web services, in the end I  ended up doing the following and passing in the $status to put a user on hold


    private function add_user_courses($moodle_user_id,$courses,$default_role,$status)

    {

        write_log(sprintf("%s moodle_user_id=%s courses=%s",__FUNCTION__,$moodle_user_id,implode(",",$courses)));

        // now enrol the user in the course

        $moodlecourses = array();

        foreach( $courses as $course)

        {

            write_log("add user to course " .  $moodle_user_id . " " .  $course);

            $moodlcourse = new stdClass();

            $moodlcourse->roleid = $default_role;

            $moodlcourse->userid = $moodle_user_id;

            $moodlcourse->courseid = $course;

            $moodlcourse->suspend = $status;

            array_push($moodlecourses,$moodlcourse);

            $params = array("enrolments" => $moodlecourses);

            //write_log(var_dump_ret($params));

            $this->MoodleIt("enrol_manual_enrol_users", $params);

        }


    }


Regards

Tim