Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mod_data_generator Class Reference
Inheritance diagram for mod_data_generator:
testing_module_generator component_generator_base

Public Member Functions

 create_content ($instance, $record=array())
 Generates a piece of content for the module. More...
 
 create_entry ($data, array $contents, $groupid=0, $tags=[], array $options=null)
 Creates a field for a mod_data instance. More...
 
 create_field (stdClass $record=null, $data=null)
 Creates a field for a mod_data instance. More...
 
 create_instance ($record=null, array $options=null)
 Creates a mod_data instance. More...
 
 get_modulename ()
 Returns module name. More...
 
 reset ()
 To be called from data reset code only, do not use in tests. More...
 

Protected Member Functions

 post_add_instance ($id, $cmid)
 Called after *_add_instance() More...
 
 precreate_course_module ($courseid, array $options)
 Create course module and link it to course. More...
 
 prepare_moduleinfo_record ($record, $options)
 Merges together arguments $record and $options and fills default module fields that are shared by all module types. More...
 

Protected Attributes

int $databasefieldcount = 0
 keep track of how many database fields have been created.
 
int $databaserecordcount = 0
 keep track of how many database records have been created.
 
testing_data_generator $datagenerator
 
number $instancecount = 0
 of created instances
 

Member Function Documentation

◆ create_content()

testing_module_generator::create_content (   $instance,
  $record = array() 
)
inherited

Generates a piece of content for the module.

User is usually taken from global $USER variable.

Parameters
stdClass$instanceobject returned from create_instance() call
stdClass | array$record
Return values
stdClassgenerated object
Exceptions
coding_exceptionif function is not implemented by module

Reimplemented in mod_wiki_generator, mod_lesson_generator, mod_forum_generator, and mod_book_generator.

◆ create_entry()

mod_data_generator::create_entry (   $data,
array  $contents,
  $groupid = 0,
  $tags = [],
array  $options = null 
)

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')

Parameters
stdClass$datarecord from table {data}
array$contents
int$groupid
array$tags
array$options
Return values
intid of the generated record in table {data_records}

◆ create_field()

mod_data_generator::create_field ( stdClass  $record = null,
  $data = null 
)

Creates a field for a mod_data instance.

Parameters
StdClass$record
mod_data$data
Return values
data_field_{type}

◆ create_instance()

mod_data_generator::create_instance (   $record = null,
array  $options = null 
)

Creates a mod_data instance.

Parameters
array$record
array$options
Return values
StdClass

Reimplemented from testing_module_generator.

◆ get_modulename()

testing_module_generator::get_modulename ( )
inherited

Returns module name.

Return values
stringname of module that this class describes
Exceptions
coding_exceptionif class invalid

◆ post_add_instance()

testing_module_generator::post_add_instance (   $id,
  $cmid 
)
protectedinherited

Called after *_add_instance()

Since 2.6 it is recommended to use function add_moduleinfo() to create a module.

Deprecated:
since 2.6
See also
testing_module_generator::create_instance()
Parameters
int$id
int$cmid
Return values
stdClassmodule instance

◆ precreate_course_module()

testing_module_generator::precreate_course_module (   $courseid,
array  $options 
)
protectedinherited

Create course module and link it to course.

Since 2.6 it is recommended to use function add_moduleinfo() to create a module.

Deprecated:
since 2.6
See also
testing_module_generator::create_instance()
Parameters
integer$courseid
array$optionssection, visible
Return values
integer::$cminstance id

◆ prepare_moduleinfo_record()

testing_module_generator::prepare_moduleinfo_record (   $record,
  $options 
)
protectedinherited

Merges together arguments $record and $options and fills default module fields that are shared by all module types.

Parameters
object | array$recordfields (different from defaults) for this module
null | array$optionsfor backward-compatibility this may include fields from course_modules table. They are merged into $record
Exceptions
coding_exceptionif $record->course is not specified

◆ reset()

mod_data_generator::reset ( )

To be called from data reset code only, do not use in tests.

Return values
void

Reimplemented from testing_module_generator.


The documentation for this class was generated from the following file: