public static function edit_user_enrolment($courseid, $ueid, $status, $timestart = 0, $timeend = 0) {
        global $CFG, $DB, $PAGE;

        $params = self::validate_parameters(self::edit_user_enrolment_parameters(), [
            'courseid' => $courseid,
            'ueid' => $ueid,
            'status' => $status,
            'timestart' => $timestart,
            'timeend' => $timeend,
        ]);

        $course = get_course($courseid);
        $context = context_course::instance($course->id);
        self::validate_context($context);

        $userenrolment = $DB->get_record('user_enrolments', ['id' => $params['ueid']], '*', MUST_EXIST);
        $userenroldata = [
            'status' => $params['status'],
            'timestart' => $params['timestart'],
            'timeend' => $params['timeend'],
        ];

        $result = false;
        $errors = [];

        // Validate data against the edit user enrolment form.
        $instance = $DB->get_record('enrol', ['id' => $userenrolment->enrolid], '*', MUST_EXIST);
        $plugin = enrol_get_plugin($instance->enrol);
        require_once("$CFG->dirroot/enrol/editenrolment_form.php");
        $customformdata = [
            'ue' => $userenrolment,
            'modal' => true,
            'enrolinstancename' => $plugin->get_instance_name($instance)
        ];
        $mform = new \enrol_user_enrolment_form(null, $customformdata, 'post', '', null, true, $userenroldata);
        $mform->set_data($userenroldata);
        $validationerrors = $mform->validation($userenroldata, null);
        if (empty($validationerrors)) {
            require_once($CFG->dirroot . '/enrol/locallib.php');
            $manager = new course_enrolment_manager($PAGE, $course);
            $result = $manager->edit_enrolment($userenrolment, (object)$userenroldata);
        } else {
            foreach ($validationerrors as $key => $errormessage) {
                $errors[] = (object)[
                    'key' => $key,
                    'message' => $errormessage
                ];
            }
        }

        return [
            'result' => $result,
            'errors' => $errors,
        ];
    }
public static function edit_user_enrolment($courseid, $ueid, $status, $timestart = 0, $timeend = 0) {
        global $CFG, $DB, $PAGE;

        $params = self::validate_parameters(self::edit_user_enrolment_parameters(), [
            'courseid' => $courseid,
            'ueid' => $ueid,
            'status' => $status,
            'timestart' => $timestart,
            'timeend' => $timeend,
        ]);

        $course = get_course($courseid);
        $context = context_course::instance($course->id);
        self::validate_context($context);

        $userenrolment = $DB->get_record('user_enrolments', ['id' => $params['ueid']], '*', MUST_EXIST);
        $userenroldata = [
            'status' => $params['status'],
            'timestart' => $params['timestart'],
            'timeend' => $params['timeend'],
        ];

        $result = false;
        $errors = [];

        // Validate data against the edit user enrolment form.
        $instance = $DB->get_record('enrol', ['id' => $userenrolment->enrolid], '*', MUST_EXIST);
        $plugin = enrol_get_plugin($instance->enrol);
        require_once("$CFG->dirroot/enrol/editenrolment_form.php");
        $customformdata = [
            'ue' => $userenrolment,
            'modal' => true,
            'enrolinstancename' => $plugin->get_instance_name($instance)
        ];
        $mform = new \enrol_user_enrolment_form(null, $customformdata, 'post', '', null, true, $userenroldata);
        $mform->set_data($userenroldata);
        $validationerrors = $mform->validation($userenroldata, null);
        if (empty($validationerrors)) {
            require_once($CFG->dirroot . '/enrol/locallib.php');
            $manager = new course_enrolment_manager($PAGE, $course);
            $result = $manager->edit_enrolment($userenrolment, (object)$userenroldata);
        } else {
            foreach ($validationerrors as $key => $errormessage) {
                $errors[] = (object)[
                    'key' => $key,
                    'message' => $errormessage
                ];
            }
        }

        return [
            'result' => $result,
            'errors' => $errors,
        ];
    }
public static function edit_user_enrolment ( $ courseid , $ ueid , $ status , $ timestart = 0 , $ timeend = 0 ) { global $ CFG , $ DB , $ PAGE ; $ params = self :: validate_parameters ( self :: edit_user_enrolment_parameters ( ) , [ 'courseid' => $ courseid , 'ueid' => $ ueid , 'status' => $ status , 'timestart' => $ timestart , 'timeend' => $ timeend , ] ) ; $ course = get_course ( $ courseid ) ; $ context = context_course :: instance ( $ course -> id ) ; self :: validate_context ( $ context ) ; $ userenrolment = $ DB -> get_record ( 'user_enrolments' , [ 'id' => $ params [ 'ueid' ] ] , '*' , MUST_EXIST ) ; $ userenroldata = [ 'status' => $ params [ 'status' ] , 'timestart' => $ params [ 'timestart' ] , 'timeend' => $ params [ 'timeend' ] , ] ; $ result = false ; $ errors = [ ] ; // Validate data against the edit user enrolment form. $ instance = $ DB -> get_record ( 'enrol' , [ 'id' => $ userenrolment -> enrolid ] , '*' , MUST_EXIST ) ; $ plugin = enrol_get_plugin ( $ instance -> enrol ) ; require_once ( "$CFG->dirroot/enrol/editenrolment_form.php" ) ; $ customformdata = [ 'ue' => $ userenrolment , 'modal' => true , 'enrolinstancename' => $ plugin -> get_instance_name ( $ instance ) ] ; $ mform = new \ enrol_user_enrolment_form ( null , $ customformdata , 'post' , '' , null , true , $ userenroldata ) ; $ mform -> set_data ( $ userenroldata ) ; $ validationerrors = $ mform -> validation ( $ userenroldata , null ) ; if ( empty ( $ validationerrors ) ) { require_once ( $ CFG -> dirroot . '/enrol/locallib.php' ) ; $ manager = new course_enrolment_manager ( $ PAGE , $ course ) ; $ result = $ manager -> edit_enrolment ( $ userenrolment , ( object ) $ userenroldata ) ; } else { foreach ( $ validationerrors as $ key => $ errormessage ) { $ errors [ ] = ( object ) [ 'key' => $ key , 'message' => $ errormessage ] ; } } return [ 'result' => $ result , 'errors' => $ errors , ] ; }
External function that updates a given user enrolment.

@param int $courseid The course ID.
@param int $ueid The user enrolment ID.
@param int $status The enrolment status.
@param int $timestart Enrolment start timestamp.
@param int $timeend Enrolment end timestamp.
@return array An array consisting of the processing result, errors and form output, if available.
External function that updates a given user enrolment .