Search moodle.org's
Developer Documentation

See Release Notes

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

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

Data generator class for mod_data.

Copyright: 2012 Petr Skoda {@link http://skodak.org}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 424 lines (15 kb)
Included or required:0 times
Referenced: 2 times
Includes or requires: 0 files

Defines 1 class

mod_data_generator:: (5 methods):
  reset()
  create_instance()
  create_field()
  create_entry()
  create_preset()


Class: mod_data_generator  - X-Ref

Data generator class for mod_data.

reset()   X-Ref
To be called from data reset code only,
do not use in tests.

return: void

create_instance($record = null, array $options = null)   X-Ref
Creates a mod_data instance

param: array $record
param: array $options
return: StdClass

create_field(stdClass $record = null, $data = null)   X-Ref
Creates a field for a mod_data instance.

param: StdClass $record
param: mod_data $data
return: data_field_{type}

create_entry($data, array $contents, $groupid = 0, $tags = [], array $options = null, int $userid = 0)   X-Ref
Creates a field for a mod_data instance.
Keep in mind the default data field params created in create_field() function!
...if you haven't provided your own custom data field parameters there.
The developers using the generator must adhere to the following format :

Syntax : $contents[ fieldid ] = fieldvalue
$contents['checkbox'] = array('val1', 'val2', 'val3' .....)
$contents['data'] = 'dd-mm-yyyy'
$contents['menu'] = 'value';
$contents['multimenu'] =  array('val1', 'val2', 'val3' .....)
$contents['number'] = 'numeric value'
$contents['radiobuton'] = 'value'
$contents['text'] = 'text'
$contents['textarea'] = 'text'
$contents['url'] = 'example.url' or array('example.url', 'urlname')
$contents['latlong'] = array('value for lattitude', 'value for longitude')
$contents['file'] = 'filename or draftitemid'
$contents['picture'] = array('filename or draftitemid', 'alternative text')

param: stdClass $data record from table {data}
param: array $contents
param: int $groupid
param: array $tags
param: array $options
param: int $userid if defined, it will be the author of the entry
return: int id of the generated record in table {data_records}

create_preset(stdClass $instance, stdClass $record = null)   X-Ref
Creates a preset from a mod_data instance.

param: stdClass $instance The mod_data instance.
param: stdClass|null $record The preset information, like 'name'.
return: preset The preset that has been created.