Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
mod_feedback_generator Class Reference

mod_feedback data generator class. More...

Inheritance diagram for mod_feedback_generator:
testing_module_generator component_generator_base

Public Member Functions

 create_content ($instance, $record=array())
 Generates a piece of content for the module.
 
 create_instance ($record=null, array $options=null)
 Creates an instance of the module for testing purposes.
 
 create_item_info ($feedback, $record=array())
 Create info question item.
 
 create_item_label ($feedback, $record=array())
 Create label question item.
 
 create_item_multichoice ($feedback, $record=array())
 Create multichoice question item.
 
 create_item_multichoicerated ($feedback, $record=array())
 Create multichoicerated question item.
 
 create_item_numeric ($feedback, $record=array())
 Create numeric question item.
 
 create_item_pagebreak ($feedback)
 Create pagebreak.
 
 create_item_textarea ($feedback, $record=array())
 Create textarea question item.
 
 create_item_textfield ($feedback, $record=array())
 Create textfield question item.
 
 create_question (array $data)
 Create question.
 
 create_response (array $data)
 Create response.
 
 get_modulename ()
 Returns module name.
 
 reset ()
 To be called from data reset code only, do not use in tests.
 

Protected Member Functions

 format_item_values (string $questiontype, string $values)
 Format feedback item values.
 
 get_choice_item_response_value (feedback_item_base $item, $record, string $response, int $offset=1)
 Given a response to a feedback choice item, return its corresponding value.
 
 get_item_response_value ($record, string $response)
 Given a response to a feedback item, return its corresponding value.
 
 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 $instancecount = 0
 number of created instances
 

Detailed Description

mod_feedback data generator class.

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

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_book_generator, mod_forum_generator, mod_h5pactivity_generator, mod_lesson_generator, and mod_wiki_generator.

◆ create_instance()

mod_feedback_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_item_info()

mod_feedback_generator::create_item_info ( $feedback,
$record = array() )

Create info question item.

Parameters
object$feedbackfeedback record
array$record(optional) to override default values
Return values
stdClass

◆ create_item_label()

mod_feedback_generator::create_item_label ( $feedback,
$record = array() )

Create label question item.

Parameters
object$feedbackfeedback record
array$record(optional) to override default values
Return values
stdClass

◆ create_item_multichoice()

mod_feedback_generator::create_item_multichoice ( $feedback,
$record = array() )

Create multichoice question item.

Parameters
object$feedbackfeedback record
array$record(optional) to override default values
Return values
stdClass

◆ create_item_multichoicerated()

mod_feedback_generator::create_item_multichoicerated ( $feedback,
$record = array() )

Create multichoicerated question item.

Parameters
object$feedbackfeedback record
array$record(optional) to override default values
Return values
stdClass

◆ create_item_numeric()

mod_feedback_generator::create_item_numeric ( $feedback,
$record = array() )

Create numeric question item.

Parameters
object$feedbackfeedback record
array$record(optional) to override default values
Return values
stdClass

◆ create_item_pagebreak()

mod_feedback_generator::create_item_pagebreak ( $feedback)

Create pagebreak.

Parameters
object$feedbackfeedback record
Return values
int|falsefalse if there already is a pagebreak on last position or the id of the pagebreak-item

◆ create_item_textarea()

mod_feedback_generator::create_item_textarea ( $feedback,
$record = array() )

Create textarea question item.

Parameters
object$feedbackfeedback record
array$record(optional) to override default values
Return values
stdClass

◆ create_item_textfield()

mod_feedback_generator::create_item_textfield ( $feedback,
$record = array() )

Create textfield question item.

Parameters
object$feedbackfeedback record
array$record(optional) to override default values
Return values
stdClass

◆ create_question()

mod_feedback_generator::create_question ( array $data)

Create question.

Parameters
array$dataQuestion data
Return values
mixedQuestion instance

◆ create_response()

mod_feedback_generator::create_response ( array $data)

Create response.

Parameters
array$dataResponse data.
Return values
stdClassfeedback_completed response instance.

◆ format_item_values()

mod_feedback_generator::format_item_values ( string $questiontype,
string $values )
protected

Format feedback item values.

This method will replace newline characters with the proper line separator for each question type.

Parameters
string$questiontypeQuestion types
string$valuesValues
Return values
stringFormatted values

◆ get_choice_item_response_value()

mod_feedback_generator::get_choice_item_response_value ( feedback_item_base $item,
$record,
string $response,
int $offset = 1 )
protected

Given a response to a feedback choice item, return its corresponding value.

Parameters
feedback_item_base$itemFeedback item
mixed$recordItem record
string$responseResponse
int$offsetChoice to start looking from
Return values
intResponse choice index

◆ get_item_response_value()

mod_feedback_generator::get_item_response_value ( $record,
string $response )
protected

Given a response to a feedback item, return its corresponding value.

Parameters
mixed$recordItem record
string$responseResponse name
Return values
int|stringResponse value

◆ 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()

testing_module_generator::reset ( )
inherited

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

Return values
void

Reimplemented from component_generator_base.

Reimplemented in mod_book_generator, mod_chat_generator, mod_data_generator, mod_forum_generator, mod_glossary_generator, mod_lesson_generator, mod_survey_generator, and mod_wiki_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: