public static function create(int $id, \stdClass $record = null, field_controller $field = null) : data_controller {
        global $DB;
        if ($id && $record) {
            // This warning really should be in persistent as well.
            debugging('Too many parameters, either id need to be specified or a record, but not both.',
                DEBUG_DEVELOPER);
        }
        if ($id) {
            $record = $DB->get_record(data::TABLE, array('id' => $id), '*', MUST_EXIST);
        } else if (!$record) {
            $record = new \stdClass();
        }

        if (!$field && empty($record->fieldid)) {
            throw new \coding_exception('Not enough parameters to initialise data_controller - unknown field');
        }
        if (!$field) {
            $field = field_controller::create($record->fieldid);
        }
        if (empty($record->fieldid)) {
            $record->fieldid = $field->get('id');
        }
        if ($field->get('id') != $record->fieldid) {
            throw new \coding_exception('Field id from the record does not match field from the parameter');
        }
        $type = $field->get('type');
        $customfieldtype = "\\customfield_{$type}\\data_controller";
        if (!class_exists($customfieldtype) || !is_subclass_of($customfieldtype, self::class)) {
            throw new \moodle_exception('errorfieldtypenotfound', 'core_customfield', '', s($type));
        }
        $datacontroller = new $customfieldtype(0, $record);
        $datacontroller->field = $field;
        return $datacontroller;
    }
public static function create(int $id, \stdClass $record = null, field_controller $field = null) : data_controller {
        global $DB;
        if ($id && $record) {
            // This warning really should be in persistent as well.
            debugging('Too many parameters, either id need to be specified or a record, but not both.',
                DEBUG_DEVELOPER);
        }
        if ($id) {
            $record = $DB->get_record(data::TABLE, array('id' => $id), '*', MUST_EXIST);
        } else if (!$record) {
            $record = new \stdClass();
        }

        if (!$field && empty($record->fieldid)) {
            throw new \coding_exception('Not enough parameters to initialise data_controller - unknown field');
        }
        if (!$field) {
            $field = field_controller::create($record->fieldid);
        }
        if (empty($record->fieldid)) {
            $record->fieldid = $field->get('id');
        }
        if ($field->get('id') != $record->fieldid) {
            throw new \coding_exception('Field id from the record does not match field from the parameter');
        }
        $type = $field->get('type');
        $customfieldtype = "\\customfield_{$type}\\data_controller";
        if (!class_exists($customfieldtype) || !is_subclass_of($customfieldtype, self::class)) {
            throw new \moodle_exception('errorfieldtypenotfound', 'core_customfield', '', s($type));
        }
        $datacontroller = new $customfieldtype(0, $record);
        $datacontroller->field = $field;
        return $datacontroller;
    }
public static function create ( int $ id , \ stdClass $ record = null , field_controller $ field = null ) : data_controller { global $ DB ; if ( $ id && $ record ) { // This warning really should be in persistent as well. debugging ( 'Too many parameters, either id need to be specified or a record, but not both.' , DEBUG_DEVELOPER ) ; } if ( $ id ) { $ record = $ DB -> get_record ( data :: TABLE , array ( 'id' => $ id ) , '*' , MUST_EXIST ) ; } else if ( ! $ record ) { $ record = new \ stdClass ( ) ; } if ( ! $ field && empty ( $ record -> fieldid ) ) { throw new \ coding_exception ( 'Not enough parameters to initialise data_controller - unknown field' ) ; } if ( ! $ field ) { $ field = field_controller :: create ( $ record -> fieldid ) ; } if ( empty ( $ record -> fieldid ) ) { $ record -> fieldid = $ field -> get ( 'id' ) ; } if ( $ field -> get ( 'id' ) != $ record -> fieldid ) { throw new \ coding_exception ( 'Field id from the record does not match field from the parameter' ) ; } $ type = $ field -> get ( 'type' ) ; $ customfieldtype = "\\customfield_{$type}\\data_controller" ; if ( ! class_exists ( $ customfieldtype ) || ! is_subclass_of ( $ customfieldtype , self :: class ) ) { throw new \ moodle_exception ( 'errorfieldtypenotfound' , 'core_customfield' , '' , s ( $ type ) ) ; } $ datacontroller = new $ customfieldtype ( 0 , $ record ) ; $ datacontroller -> field = $ field ; return $ datacontroller ; }
Creates an instance of data_controller

Parameters $id, $record and $field can complement each other but not conflict.
If $id is not specified, fieldid must be present either in $record or in $field.
If $id is not specified, instanceid must be present in $record

No DB queries are performed if both $record and $field are specified.

@param int $id
@param \stdClass|null $record
@param field_controller|null $field
@return data_controller
@throws \coding_exception
@throws \moodle_exception
Creates an instance of data_controller