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

Class containing a set of helpers. More...

Static Public Member Functions

static generate_shortname ($data, $templateshortname)
 Generate a shortname based on a template.
 
static generate_shortname_callback ($fullname, $idnumber, $block)
 Callback used when generating a shortname based on a template.
 
static get_course_formats ()
 Return the available course formats.
 
static get_coursesection_count ($shortname)
 Helper to detect how many sections a course with a given shortname has.
 
static get_custom_course_field_data (array $data, array $defaults, context $context, array &$errors=[])
 Return any elements from passed $data whose key matches one of the custom course fields defined for the site.
 
static get_custom_course_field_names ()
 Return array of custom field element names.
 
static get_custom_course_fields ()
 Return array of all custom course fields indexed by their shortname.
 
static get_enrolment_data ($data)
 Extract enrolment data from passed data.
 
static get_enrolment_plugins ()
 Return the enrolment plugins.
 
static get_restore_content_dir ($backupfile=null, $shortname=null, &$errors=array())
 Get the restore content tempdir.
 
static get_role_ids ()
 Return the role IDs.
 
static get_role_names ($data, &$errors=array())
 Get the role renaming data from the passed data.
 
static increment_idnumber ($idnumber)
 Helper to increment an ID number.
 
static increment_shortname ($shortname)
 Helper to increment a shortname.
 
static resolve_category ($data, &$errors=array())
 Resolve a category based on the data passed.
 
static resolve_category_by_idnumber ($idnumber)
 Resolve a category by ID number.
 
static resolve_category_by_path (array $path)
 Resolve a category by path.
 

Detailed Description

Class containing a set of helpers.

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

Member Function Documentation

◆ generate_shortname()

static tool_uploadcourse_helper::generate_shortname ( $data,
$templateshortname )
static

Generate a shortname based on a template.

Parameters
array | object$datacourse data.
string$templateshortnametemplate of shortname.
Return values
null|stringshortname based on the template, or null when an error occured.

◆ generate_shortname_callback()

static tool_uploadcourse_helper::generate_shortname_callback ( $fullname,
$idnumber,
$block )
static

Callback used when generating a shortname based on a template.

Parameters
string$fullnamefull name.
string$idnumberID number.
array$blockresult from preg_replace_callback.
Return values
string

◆ get_course_formats()

static tool_uploadcourse_helper::get_course_formats ( )
static

Return the available course formats.

Return values
array

◆ get_coursesection_count()

static tool_uploadcourse_helper::get_coursesection_count ( $shortname)
static

Helper to detect how many sections a course with a given shortname has.

Parameters
string$shortnameshortname of a course to count sections from.
Return values
integercount of sections.

◆ get_custom_course_field_data()

static tool_uploadcourse_helper::get_custom_course_field_data ( array $data,
array $defaults,
context $context,
array & $errors = [] )
static

Return any elements from passed $data whose key matches one of the custom course fields defined for the site.

Parameters
array$data
array$defaults
context$context
array$errorsWill be populated with any errors
Return values
array

◆ get_custom_course_field_names()

static tool_uploadcourse_helper::get_custom_course_field_names ( )
static

Return array of custom field element names.

Return values
string[]

◆ get_custom_course_fields()

static tool_uploadcourse_helper::get_custom_course_fields ( )
static

Return array of all custom course fields indexed by their shortname.

Return values
core_customfield\field_controller[]

◆ get_enrolment_data()

static tool_uploadcourse_helper::get_enrolment_data ( $data)
static

Extract enrolment data from passed data.

Constructs an array of methods, and their options: array( 'method1' => array( 'option1' => value, 'option2' => value ), 'method2' => array( 'option1' => value, 'option2' => value ) )

Parameters
array$datadata to extract the enrolment data from.
Return values
array

◆ get_enrolment_plugins()

static tool_uploadcourse_helper::get_enrolment_plugins ( )
static

Return the enrolment plugins.

The result is cached for faster execution.

Return values
enrol_plugin[]

◆ get_restore_content_dir()

static tool_uploadcourse_helper::get_restore_content_dir ( $backupfile = null,
$shortname = null,
& $errors = array() )
static

Get the restore content tempdir.

The tempdir is the sub directory in which the backup has been extracted.

This caches the result for better performance, but $CFG->keeptempdirectoriesonbackup needs to be enabled, otherwise the cache is ignored.

Parameters
string$backupfilepath to a backup file.
string$shortnameshortname of a course.
array$errorswill be populated with errors found.
Return values
string|falsefalse when the backup couldn't retrieved.

◆ get_role_ids()

static tool_uploadcourse_helper::get_role_ids ( )
static

Return the role IDs.

The result is cached for faster execution.

Return values
array

◆ get_role_names()

static tool_uploadcourse_helper::get_role_names ( $data,
& $errors = array() )
static

Get the role renaming data from the passed data.

Parameters
array$datadata to extract the names from.
array$errorswill be populated with errors found.
Return values
arraywhere the key is the role_<id>, the value is the new name.

◆ increment_idnumber()

static tool_uploadcourse_helper::increment_idnumber ( $idnumber)
static

Helper to increment an ID number.

This first checks if the ID number is in use.

Parameters
string$idnumberID number to increment.
Return values
stringnew ID number.

◆ increment_shortname()

static tool_uploadcourse_helper::increment_shortname ( $shortname)
static

Helper to increment a shortname.

This considers that the shortname passed has to be incremented.

Parameters
string$shortnameshortname to increment.
Return values
stringnew shortname.

◆ resolve_category()

static tool_uploadcourse_helper::resolve_category ( $data,
& $errors = array() )
static

Resolve a category based on the data passed.

Key accepted are:

  • category, which is supposed to be a category ID.
  • category_idnumber
  • category_path, array of categories from parent to child.
Parameters
array$datato resolve the category from.
array$errorswill be populated with errors found.
Return values
intcategory ID.

◆ resolve_category_by_idnumber()

static tool_uploadcourse_helper::resolve_category_by_idnumber ( $idnumber)
static

Resolve a category by ID number.

Parameters
string$idnumbercategory ID number.
Return values
intcategory ID.

◆ resolve_category_by_path()

static tool_uploadcourse_helper::resolve_category_by_path ( array $path)
static

Resolve a category by path.

Parameters
array$pathcategory names indexed from parent to children.
Return values
intcategory ID.

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