Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
mod_forum_generator Class Reference

Forum module data generator class. More...

Inheritance diagram for mod_forum_generator:
testing_module_generator component_generator_base

Public Member Functions

 create_content ($instance, $record=array())
 Generates a piece of content for the module.
 
 create_discussion ($record=null)
 Function to create a dummy discussion.
 
 create_instance ($record=null, array $options=null)
 Creates an instance of the module for testing purposes.
 
 create_post ($record=null)
 Function to create a dummy post.
 
 create_subscription ($record=null)
 Function to create a dummy subscription.
 
 get_author_subheading_html (stdClass $exportedauthor, int $timecreated)
 Extracted from exporter/post.php.
 
 get_modulename ()
 Returns module name.
 
 reset ()
 To be called from data reset code only, do not use in tests.
 

Protected Member Functions

 insert_files (stdClass $instance, stdClass $record, string $table, context $context, string $component, string $filearea, int $targetitemid)
 Update the instance record, inserting any files that are referenced.
 
 post_add_instance ($id, $cmid)
 Called after *_add_instance()
 
 precreate_course_module ($courseid, array $options)
 Create course module and link it to course.
 
 prepare_moduleinfo_record ($record, $options)
 Merges together arguments $record and $options and fills default module fields that are shared by all module types.
 
 set_user (?stdClass $user=null)
 Set the current user during data generation.
 

Protected Attributes

testing_data_generator $datagenerator
 
int $forumdiscussioncount = 0
 keep track of how many forum discussions have been created.
 
int $forumpostcount = 0
 keep track of how many forum posts have been created.
 
int $forumsubscriptionscount = 0
 keep track of how many forum subscriptions have been created.
 
int $instancecount = 0
 number of created instances
 

Detailed Description

Forum module data generator class.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ create_content()

mod_forum_generator::create_content ( $instance,
$record = array() )

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 from testing_module_generator.

◆ create_discussion()

mod_forum_generator::create_discussion ( $record = null)

Function to create a dummy discussion.

Parameters
array | stdClass$record
Return values
stdClassthe discussion object

◆ create_instance()

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

Creates an instance of the module for testing purposes.

Module type will be taken from the class name. Each module type may overwrite this function to add other default values used by it.

Parameters
array | stdClass$recorddata for module being generated. Requires 'course' key (an id or the full object). Also can have any fields from add module form.
null | array$optionsgeneral options for course module. Since 2.6 it is possible to omit this argument by merging options into $record
Return values
stdClassrecord from module-defined table with additional field cmid (corresponding id in course_modules table)

Reimplemented from testing_module_generator.

◆ create_post()

mod_forum_generator::create_post ( $record = null)

Function to create a dummy post.

Parameters
array | stdClass$record
Return values
stdClassthe post object

◆ create_subscription()

mod_forum_generator::create_subscription ( $record = null)

Function to create a dummy subscription.

Parameters
array | stdClass$record
Return values
stdClassthe subscription object

◆ get_author_subheading_html()

mod_forum_generator::get_author_subheading_html ( stdClass $exportedauthor,
int $timecreated )

Extracted from exporter/post.php.

Get the HTML to display as a subheading in a post.

Parameters
stdClass$exportedauthorThe exported author object
int$timecreatedThe post time created timestamp if it's to be displayed
Return values
string

◆ 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

◆ insert_files()

component_generator_base::insert_files ( stdClass $instance,
stdClass $record,
string $table,
context $context,
string $component,
string $filearea,
int $targetitemid )
protectedinherited

Update the instance record, inserting any files that are referenced.

Parameters
stdClass$instanceThe instance record of the already-created record
stdClass$recordThe data passed in to create the instance
string$tableThe table that the data exists in
context$contextThe context of the instance
string$componentThe component of the owning plugin
string$fileareaThe name of the file area
int$targetitemidThe itemid to use when saving the files
Return values
stdClassThe updated instance record

◆ 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_forum_generator::reset ( )

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

Return values
void

Reimplemented from testing_module_generator.

◆ set_user()

component_generator_base::set_user ( ?stdClass $user = null)
protectedinherited

Set the current user during data generation.

This should be avoided wherever possible, but in some situations underlying code will insert data as the current user.

Parameters
stdClass$user

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