Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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: 847 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: xmldb_object $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: xmldb_object $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

return: mixed
param: array $xmlarr

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

return: int
param: string $type

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

return: string
param: int $type

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

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

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

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

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

return: string
param: bool $includeprevious

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!

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