Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

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: 364 lines (13 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

mod_data_generator:: (4 methods):
  reset()
  create_instance()
  create_field()
  create_entry()


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)   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
return: int id of the generated record in table {data_records}