public static function cancel_data_request($requestid) {
        global $USER;

        $warnings = [];
        $params = external_api::validate_parameters(self::cancel_data_request_parameters(), [
            'requestid' => $requestid
        ]);
        $requestid = $params['requestid'];

        // Validate context and access to manage the registry.
        $context = context_user::instance($USER->id);
        self::validate_context($context);

        // Ensure the request exists.
        $select = 'id = :id AND (userid = :userid OR requestedby = :requestedby)';
        $params = ['id' => $requestid, 'userid' => $USER->id, 'requestedby' => $USER->id];
        $requests = data_request::get_records_select($select, $params);
        $requestexists = count($requests) === 1;

        $result = false;
        if ($requestexists) {
            $request = reset($requests);
            $datasubject = $request->get('userid');

            if ($datasubject !== $USER->id) {
                // The user is not the subject. Check that they can cancel this request.
                if (!api::can_create_data_request_for_user($datasubject)) {
                    $forusercontext = \context_user::instance($datasubject);
                    throw new required_capability_exception($forusercontext,
                            'tool/dataprivacy:makedatarequestsforchildren', 'nopermissions', '');
                }
            }

            // TODO: Do we want a request to be non-cancellable past a certain point? E.g. When it's already approved/processing.
            $result = api::update_request_status($requestid, api::DATAREQUEST_STATUS_CANCELLED);
        } else {
            $warnings[] = [
                'item' => $requestid,
                'warningcode' => 'errorrequestnotfound',
                'message' => get_string('errorrequestnotfound', 'tool_dataprivacy')
            ];
        }

        return [
            'result' => $result,
            'warnings' => $warnings
        ];
    }
public static function cancel_data_request($requestid) {
        global $USER;

        $warnings = [];
        $params = external_api::validate_parameters(self::cancel_data_request_parameters(), [
            'requestid' => $requestid
        ]);
        $requestid = $params['requestid'];

        // Validate context and access to manage the registry.
        $context = context_user::instance($USER->id);
        self::validate_context($context);

        // Ensure the request exists.
        $select = 'id = :id AND (userid = :userid OR requestedby = :requestedby)';
        $params = ['id' => $requestid, 'userid' => $USER->id, 'requestedby' => $USER->id];
        $requests = data_request::get_records_select($select, $params);
        $requestexists = count($requests) === 1;

        $result = false;
        if ($requestexists) {
            $request = reset($requests);
            $datasubject = $request->get('userid');

            if ($datasubject !== $USER->id) {
                // The user is not the subject. Check that they can cancel this request.
                if (!api::can_create_data_request_for_user($datasubject)) {
                    $forusercontext = \context_user::instance($datasubject);
                    throw new required_capability_exception($forusercontext,
                            'tool/dataprivacy:makedatarequestsforchildren', 'nopermissions', '');
                }
            }

            // TODO: Do we want a request to be non-cancellable past a certain point? E.g. When it's already approved/processing.
            $result = api::update_request_status($requestid, api::DATAREQUEST_STATUS_CANCELLED);
        } else {
            $warnings[] = [
                'item' => $requestid,
                'warningcode' => 'errorrequestnotfound',
                'message' => get_string('errorrequestnotfound', 'tool_dataprivacy')
            ];
        }

        return [
            'result' => $result,
            'warnings' => $warnings
        ];
    }
public static function cancel_data_request ( $ requestid ) { global $ USER ; $ warnings = [ ] ; $ params = external_api :: validate_parameters ( self :: cancel_data_request_parameters ( ) , [ 'requestid' => $ requestid ] ) ; $ requestid = $ params [ 'requestid' ] ; // Validate context and access to manage the registry. $ context = context_user :: instance ( $ USER -> id ) ; self :: validate_context ( $ context ) ; // Ensure the request exists. $ select = 'id = :id AND (userid = :userid OR requestedby = :requestedby)' ; $ params = [ 'id' => $ requestid , 'userid' => $ USER -> id , 'requestedby' => $ USER -> id ] ; $ requests = data_request :: get_records_select ( $ select , $ params ) ; $ requestexists = count ( $ requests ) === 1 ; $ result = false ; if ( $ requestexists ) { $ request = reset ( $ requests ) ; $ datasubject = $ request -> get ( 'userid' ) ; if ( $ datasubject !== $ USER -> id ) { // The user is not the subject. Check that they can cancel this request. if ( ! api :: can_create_data_request_for_user ( $ datasubject ) ) { $ forusercontext = \ context_user :: instance ( $ datasubject ) ; throw new required_capability_exception ( $ forusercontext , 'tool/dataprivacy:makedatarequestsforchildren' , 'nopermissions' , '' ) ; } } // TODO: Do we want a request to be non-cancellable past a certain point? E.g. When it's already approved/processing. $ result = api :: update_request_status ( $ requestid , api :: DATAREQUEST_STATUS_CANCELLED ) ; } else { $ warnings [ ] = [ 'item' => $ requestid , 'warningcode' => 'errorrequestnotfound' , 'message' => get_string ( 'errorrequestnotfound' , 'tool_dataprivacy' ) ] ; } return [ 'result' => $ result , 'warnings' => $ warnings ] ; }
Cancel a data request.

@since Moodle 3.5
@param int $requestid The request ID.
@return array
@throws invalid_persistent_exception
@throws coding_exception
@throws invalid_parameter_exception
@throws restricted_context_exception
Cancel a data request .