Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

File containing the helper class.

Copyright: 2013 Frédéric Massart
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 593 lines (21 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: tool_uploadcourse_helper  - X-Ref

Class containing a set of helpers.

generate_shortname($data, $templateshortname)   X-Ref
Generate a shortname based on a template.

param: array|object $data course data.
param: string $templateshortname template of shortname.
return: null|string shortname based on the template, or null when an error occured.

generate_shortname_callback($fullname, $idnumber, $block)   X-Ref
Callback used when generating a shortname based on a template.

param: string $fullname full name.
param: string $idnumber ID number.
param: array $block result from preg_replace_callback.
return: string

get_course_formats()   X-Ref
Return the available course formats.

return: array

get_enrolment_data($data)   X-Ref
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
)
)

param: array $data data to extract the enrolment data from.
return: array

get_enrolment_plugins()   X-Ref
Return the enrolment plugins.

The result is cached for faster execution.

return: enrol_plugin[]

get_restore_content_dir($backupfile = null, $shortname = null, &$errors = array()   X-Ref
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.

param: string $backupfile path to a backup file.
param: string $shortname shortname of a course.
param: array $errors will be populated with errors found.
return: string|false false when the backup couldn't retrieved.

get_role_ids()   X-Ref
Return the role IDs.

The result is cached for faster execution.

return: array

get_coursesection_count($shortname)   X-Ref
Helper to detect how many sections a course with a given shortname has.

param: string $shortname shortname of a course to count sections from.
return: integer count of sections.

get_role_names($data, &$errors = array()   X-Ref
Get the role renaming data from the passed data.

param: array $data data to extract the names from.
param: array $errors will be populated with errors found.
return: array where the key is the role_<id>, the value is the new name.

get_custom_course_fields()   X-Ref
Return array of all custom course fields indexed by their shortname

return: \core_customfield\field_controller[]

get_custom_course_field_names()   X-Ref
Return array of custom field element names

return: string[]

get_custom_course_field_data(array $data, array $defaults, context $context,array &$errors = [])   X-Ref
Return any elements from passed $data whose key matches one of the custom course fields defined for the site

param: array $data
param: array $defaults
param: context $context
param: array $errors Will be populated with any errors
return: array

increment_idnumber($idnumber)   X-Ref
Helper to increment an ID number.

This first checks if the ID number is in use.

param: string $idnumber ID number to increment.
return: string new ID number.

increment_shortname($shortname)   X-Ref
Helper to increment a shortname.

This considers that the shortname passed has to be incremented.

param: string $shortname shortname to increment.
return: string new shortname.

resolve_category($data, &$errors = array()   X-Ref
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.

param: array $data to resolve the category from.
param: array $errors will be populated with errors found.
return: int category ID.

resolve_category_by_idnumber($idnumber)   X-Ref
Resolve a category by ID number.

param: string $idnumber category ID number.
return: int category ID.

resolve_category_by_path(array $path)   X-Ref
Resolve a category by path.

param: array $path category names indexed from parent to children.
return: int category ID.