public static function override_activity_completion_status($userid, $cmid, $newstate) {
        // Validate and normalize parameters.
        $params = self::validate_parameters(self::override_activity_completion_status_parameters(),
            array('userid' => $userid, 'cmid' => $cmid, 'newstate' => $newstate));
        $userid = $params['userid'];
        $cmid = $params['cmid'];
        $newstate = $params['newstate'];

        $context = context_module::instance($cmid);
        self::validate_context($context);

        list($course, $cm) = get_course_and_cm_from_cmid($cmid);

        // Set up completion object and check it is enabled.
        $completion = new completion_info($course);
        if (!$completion->is_enabled()) {
            throw new moodle_exception('completionnotenabled', 'completion');
        }

        // Update completion state and get the new state back.
        $completion->update_state($cm, $newstate, $userid, true);
        $completiondata = $completion->get_data($cm, false, $userid);

        // Return the current state of completion.
        return [
            'cmid' => $completiondata->coursemoduleid,
            'userid' => $completiondata->userid,
            'state' => $completiondata->completionstate,
            'timecompleted' => $completiondata->timemodified,
            'overrideby' => $completiondata->overrideby,
            'tracking' => $completion->is_enabled($cm)
        ];
    }
public static function override_activity_completion_status($userid, $cmid, $newstate) {
        // Validate and normalize parameters.
        $params = self::validate_parameters(self::override_activity_completion_status_parameters(),
            array('userid' => $userid, 'cmid' => $cmid, 'newstate' => $newstate));
        $userid = $params['userid'];
        $cmid = $params['cmid'];
        $newstate = $params['newstate'];

        $context = context_module::instance($cmid);
        self::validate_context($context);

        list($course, $cm) = get_course_and_cm_from_cmid($cmid);

        // Set up completion object and check it is enabled.
        $completion = new completion_info($course);
        if (!$completion->is_enabled()) {
            throw new moodle_exception('completionnotenabled', 'completion');
        }

        // Update completion state and get the new state back.
        $completion->update_state($cm, $newstate, $userid, true);
        $completiondata = $completion->get_data($cm, false, $userid);

        // Return the current state of completion.
        return [
            'cmid' => $completiondata->coursemoduleid,
            'userid' => $completiondata->userid,
            'state' => $completiondata->completionstate,
            'timecompleted' => $completiondata->timemodified,
            'overrideby' => $completiondata->overrideby,
            'tracking' => $completion->is_enabled($cm)
        ];
    }
public static function override_activity_completion_status ( $ userid , $ cmid , $ newstate ) { // Validate and normalize parameters. $ params = self :: validate_parameters ( self :: override_activity_completion_status_parameters ( ) , array ( 'userid' => $ userid , 'cmid' => $ cmid , 'newstate' => $ newstate ) ) ; $ userid = $ params [ 'userid' ] ; $ cmid = $ params [ 'cmid' ] ; $ newstate = $ params [ 'newstate' ] ; $ context = context_module :: instance ( $ cmid ) ; self :: validate_context ( $ context ) ; list ( $ course , $ cm ) = get_course_and_cm_from_cmid ( $ cmid ) ; // Set up completion object and check it is enabled. $ completion = new completion_info ( $ course ) ; if ( ! $ completion -> is_enabled ( ) ) { throw new moodle_exception ( 'completionnotenabled' , 'completion' ) ; } // Update completion state and get the new state back. $ completion -> update_state ( $ cm , $ newstate , $ userid , true ) ; $ completiondata = $ completion -> get_data ( $ cm , false , $ userid ) ; // Return the current state of completion. return [ 'cmid' => $ completiondata -> coursemoduleid , 'userid' => $ completiondata -> userid , 'state' => $ completiondata -> completionstate , 'timecompleted' => $ completiondata -> timemodified , 'overrideby' => $ completiondata -> overrideby , 'tracking' => $ completion -> is_enabled ( $ cm ) ] ; }
Update completion status for a user in an activity.
@param  int $userid    User id
@param  int $cmid      Course module id
@param  int $newstate  Activity completion
@return array          Array containing the current (updated) completion status.
@since Moodle 3.4
@throws moodle_exception
Update completion status for a user in an activity .