Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
core_h5p_generator Class Reference
Inheritance diagram for core_h5p_generator:
component_generator_base

Public Member Functions

 create_content_file (string $file, string $filearea, int $contentid=0)
 Add a record on files table for a file that belongs to. More...
 
 create_content_types (array $typestonotinstall, core $core)
 Create H5P content type records in the h5p_libraries database table. More...
 
 create_contents_libraries_record (string $h5pid, int $libid, string $dependencytype='preloaded')
 Create a record in the h5p_contents_libraries database table. More...
 
 create_export_file (string $filename, int $contextid, string $component, string $filearea, int $typeurl=self::WSPLUGINFILE)
 Create a fake export H5P deployed file. More...
 
 create_file (string $file, string $content='')
 Convenience function to create a file. More...
 
 create_h5p_record (int $mainlibid, string $jsoncontent=null, string $filtered=null)
 Create a record in the h5p database table. More...
 
 create_library (string $uploaddirectory, int $libraryid, string $machinename, int $majorversion, int $minorversion, ?array $langs=[])
 Create the necessary files and return an array structure for a library. More...
 
 create_library_dependency_record (int $libid, int $requiredlibid, string $dependencytype='preloaded')
 Create a record in the h5p_library_dependencies database table. More...
 
 create_library_record (string $machinename, string $title, int $majorversion=1, int $minorversion=0, int $patchversion=1, string $semantics='', string $addto=null)
 Create a record in the h5p_libraries database table. More...
 
 generate_h5p_data (bool $createlibraryfiles=false)
 Populate H5P database tables with relevant data to simulate the process of adding H5P content. More...
 
 reset ()
 To be called from data reset code only, do not use in tests. More...
 

Public Attributes

const PLUGINFILE = 2
 Url pointing to plugin file.
 
const TOKENPLUGINFILE = 1
 Url pointing to token plugin file.
 
const WSPLUGINFILE = 0
 Url pointing to webservice plugin file.
 

Protected Member Functions

 add_libfile_to_array (string $type, string $path, string $version, &$files)
 Creates the file record. More...
 
 set_user (?stdClass $user=null)
 Set the current user during data generation. More...
 

Protected Attributes

testing_data_generator $datagenerator
 

Member Function Documentation

◆ add_libfile_to_array()

core_h5p_generator::add_libfile_to_array ( string  $type,
string  $path,
string  $version,
$files 
)
protected

Creates the file record.

Currently used for the cache tests.

Parameters
string$typeEither 'scripts' or 'styles'.
string$pathPath to the file in the file system.
string$versionNot really needed at the moment.

◆ create_content_file()

core_h5p_generator::create_content_file ( string  $file,
string  $filearea,
int  $contentid = 0 
)

Add a record on files table for a file that belongs to.

Parameters
string$fileFile name and path inside the filearea.
string$fileareaThe filearea in which the file is ("editor" or "content").
int$contentidId of the H5P content to which the file belongs. null if the file is in the editor.
Return values
stored_file;
Exceptions
coding_exception

◆ create_content_types()

core_h5p_generator::create_content_types ( array  $typestonotinstall,
core  $core 
)

Create H5P content type records in the h5p_libraries database table.

Parameters
array$typestonotinstallH5P content types that should not be installed
core$coreh5p_test_core instance required to use the exttests URL
Return values
arrayData of the content types not installed.

◆ create_contents_libraries_record()

core_h5p_generator::create_contents_libraries_record ( string  $h5pid,
int  $libid,
string  $dependencytype = 'preloaded' 
)

Create a record in the h5p_contents_libraries database table.

Parameters
string$h5pidThe ID of the H5P content
int$libidThe ID of the library
string$dependencytypeThe dependency type
Return values
intThe ID of the added record

◆ create_export_file()

core_h5p_generator::create_export_file ( string  $filename,
int  $contextid,
string  $component,
string  $filearea,
int  $typeurl = self::WSPLUGINFILE 
)

Create a fake export H5P deployed file.

Parameters
string$filenameName of the H5P file to deploy.
int$contextidContext id of the H5P activity.
string$componentcomponent.
string$fileareafile area.
int$typeurlType of url to create the export url plugin file.
Return values
arrayreturn deployed file information.

◆ create_file()

core_h5p_generator::create_file ( string  $file,
string  $content = '' 
)

Convenience function to create a file.

Parameters
string$filepath to a file.
string$contentfile content.

◆ create_h5p_record()

core_h5p_generator::create_h5p_record ( int  $mainlibid,
string  $jsoncontent = null,
string  $filtered = null 
)

Create a record in the h5p database table.

Parameters
int$mainlibidThe ID of the content's main library
string$jsoncontentThe content in json format
string$filteredThe filtered content parameters
Return values
intThe ID of the added record

◆ create_library()

core_h5p_generator::create_library ( string  $uploaddirectory,
int  $libraryid,
string  $machinename,
int  $majorversion,
int  $minorversion,
?array  $langs = [] 
)

Create the necessary files and return an array structure for a library.

Parameters
string$uploaddirectoryBase directory for the library.
int$libraryidLibrary id.
string$machinenameName for this library.
int$majorversionMajor version (any number will do).
int$minorversionMinor version (any number will do).
array$langsLanguages to be included into the library.
Return values
arrayA list of library data and files that the core API will understand.

◆ create_library_dependency_record()

core_h5p_generator::create_library_dependency_record ( int  $libid,
int  $requiredlibid,
string  $dependencytype = 'preloaded' 
)

Create a record in the h5p_library_dependencies database table.

Parameters
int$libidThe ID of the library
int$requiredlibidThe ID of the required library
string$dependencytypeThe dependency type
Return values
intThe ID of the added record

◆ create_library_record()

core_h5p_generator::create_library_record ( string  $machinename,
string  $title,
int  $majorversion = 1,
int  $minorversion = 0,
int  $patchversion = 1,
string  $semantics = '',
string  $addto = null 
)

Create a record in the h5p_libraries database table.

Parameters
string$machinenameThe library machine name
string$titleThe library's name
int$majorversionThe library's major version
int$minorversionThe library's minor version
int$patchversionThe library's patch version
string$semanticsJson describing the content structure for the library
string$addtoThe plugin configuration data
Return values
stdClassAn object representing the added library record

◆ generate_h5p_data()

core_h5p_generator::generate_h5p_data ( bool  $createlibraryfiles = false)

Populate H5P database tables with relevant data to simulate the process of adding H5P content.

Parameters
bool$createlibraryfilesWhether to create and store library files on the filesystem
Return values
stdClassAn object representing the added H5P records

◆ reset()

component_generator_base::reset ( )
inherited

◆ 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: