Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]

This class represent one XMLDB Field

Copyright: 1999 onwards Martin Dougiamas http://dougiamas.com
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 849 lines (29 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

xmldb_field:: (25 methods):
  __construct()
  set_attributes()
  getType()
  getLength()
  getDecimals()
  getNotNull()
  getUnsigned()
  getSequence()
  getDefault()
  setType()
  setLength()
  setDecimals()
  setUnsigned()
  setNotNull()
  setSequence()
  setDefault()
  arr2xmldb_field()
  getXMLDBFieldType()
  getXMLDBTypeName()
  calculateHash()
  xmlOutput()
  setFromADOField()
  getPHP()
  readableInfo()
  validateDefinition()


Class: xmldb_field  - X-Ref

__construct($name, $type=null, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $default=null, $previous=null)   X-Ref
Creates one new xmldb_field

param: string $name of field
param: int $type XMLDB_TYPE_INTEGER, XMLDB_TYPE_NUMBER, XMLDB_TYPE_CHAR, XMLDB_TYPE_TEXT, XMLDB_TYPE_BINARY
param: string $precision length for integers and chars, two-comma separated numbers for numbers
param: bool $unsigned XMLDB_UNSIGNED or null (or false)
param: bool $notnull XMLDB_NOTNULL or null (or false)
param: bool $sequence XMLDB_SEQUENCE or null (or false)
param: mixed $default meaningful default o null (or false)
param: string $previous

set_attributes($type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $default=null, $previous=null)   X-Ref
Set all the attributes of one xmldb_field

param: int $type XMLDB_TYPE_INTEGER, XMLDB_TYPE_NUMBER, XMLDB_TYPE_CHAR, XMLDB_TYPE_TEXT, XMLDB_TYPE_BINARY
param: string $precision length for integers and chars, two-comma separated numbers for numbers
param: bool $unsigned XMLDB_UNSIGNED or null (or false)
param: bool $notnull XMLDB_NOTNULL or null (or false)
param: bool $sequence XMLDB_SEQUENCE or null (or false)
param: mixed $default meaningful default o null (or false)
param: string $previous

getType()   X-Ref
Get the type

return: int

getLength()   X-Ref
Get the length

return: int

getDecimals()   X-Ref
Get the decimals

return: string

getNotNull()   X-Ref
Get the notnull

return: bool

getUnsigned()   X-Ref
Get the unsigned

return: bool

getSequence()   X-Ref
Get the sequence

return: bool

getDefault()   X-Ref
Get the default

return: mixed

setType($type)   X-Ref
Set the field type

param: int $type

setLength($length)   X-Ref
Set the field length

param: int $length

setDecimals($decimals)   X-Ref
Set the field decimals

param: string

setUnsigned($unsigned=true)   X-Ref
Set the field unsigned

param: bool $unsigned

setNotNull($notnull=true)   X-Ref
Set the field notnull

param: bool $notnull

setSequence($sequence=true)   X-Ref
Set the field sequence

param: bool $sequence

setDefault($default)   X-Ref
Set the field default

param: mixed $default

arr2xmldb_field($xmlarr)   X-Ref
Load data from XML to the table

param: array $xmlarr
return: mixed

getXMLDBFieldType($type)   X-Ref
This function returns the correct XMLDB_TYPE_XXX value for the
string passed as argument

param: string $type
return: int

getXMLDBTypeName($type)   X-Ref
This function returns the correct name value for the
XMLDB_TYPE_XXX passed as argument

param: int $type
return: string

calculateHash($recursive = false)   X-Ref
This function calculate and set the hash of one xmldb_field

param: bool $recursive
return: void, modifies $this->hash

xmlOutput()   X-Ref
This function will output the XML text for one field

return: string

setFromADOField($adofield)   X-Ref
This function will set all the attributes of the xmldb_field object
based on information passed in one ADOField

param: database_column_info $adofield
return: void, sets $this->type

getPHP($includeprevious=true)   X-Ref
Returns the PHP code needed to define one xmldb_field

param: bool $includeprevious
return: string

readableInfo()   X-Ref
Shows info in a readable format

return: string

validateDefinition(xmldb_table $xmldb_table=null)   X-Ref
Validates the field restrictions.

The error message should not be localised because it is intended for developers,
end users and admins should never see these problems!

param: xmldb_table $xmldb_table optional when object is table
return: string null if ok, error message if problem found