Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
tool_uploadcourse_course Class Reference

Course class. More...

Public Member Functions

 __construct ($mode, $updatemode, $rawdata, $defaults=array(), $importoptions=array())
 Constructor.
 
 can_create ()
 Does the mode allow for course creation?
 
 can_delete ()
 Does the mode allow for course deletion?
 
 can_only_create ()
 Does the mode only allow for course creation?
 
 can_rename ()
 Does the mode allow for course rename?
 
 can_reset ()
 Does the mode allow for course reset?
 
 can_update ()
 Does the mode allow for course update?
 
 can_use_defaults ()
 Can we use default values?
 
 get_data ()
 Return the data that will be used upon saving.
 
 get_errors ()
 Return the errors found during preparation.
 
 get_id ()
 Return the ID of the processed course.
 
 get_statuses ()
 Return the errors found during preparation.
 
 has_errors ()
 Return whether there were errors with this course.
 
 prepare ()
 Validates and prepares the data.
 
 proceed ()
 Proceed with the import of the course.
 

Public Attributes

const DO_CREATE = 1
 Outcome of the process: creating the course.
 
const DO_DELETE = 3
 Outcome of the process: deleting the course.
 
const DO_UPDATE = 2
 Outcome of the process: updating the course.
 

Protected Member Functions

 delete ()
 Delete the current course.
 
 error ($code, lang_string $message)
 Log an error.
 
 exists ($shortname=null)
 Return whether the course exists or not.
 
 get_final_create_data ($data)
 Assemble the course data based on defaults.
 
 get_final_update_data ($data, $usedefaults=false, $missingonly=false)
 Assemble the course data based on defaults.
 
 get_restore_content_dir ()
 Get the directory of the object to restore.
 
 get_valid_fields ()
 Return array of valid fields for default values.
 
 process_enrolment_data ($course)
 Add the enrolment data for the course.
 
 reset ($course)
 Reset the current course.
 
 status ($code, lang_string $message)
 Log a status.
 
 validate_enrolment_data (int $courseid, array $enrolmentdata)
 Validate passed enrolment data against an existing course.
 
 validate_role_context (int $courseid, int $roleid)
 Check if role is allowed in course context.
 
 validate_role_context_level (int $roleid)
 Check if role is allowed at this context level.
 

Protected Attributes

array $assignableroles = []
 assignable roles.
 
array $contextlevels = []
 Roles context levels.
 
array $data = array()
 final import data.
 
array $defaults = array()
 default values.
 
int $do
 constant value of self\DO_*, what to do with that course
 
array $enrolmentdata
 enrolment data.
 
array $errors = array()
 errors.
 
int $id
 the ID of the course that had been processed.
 
array $importoptions = array()
 containing options passed from the processor.
 
int $mode
 import mode.
 
array $options = array()
 course import options.
 
bool $prepared = false
 set to true once we have prepared the course
 
bool $processstarted = false
 set to true once we have started the process of the course
 
array $rawdata = array()
 course import data.
 
array $restoredata
 restore directory.
 
string $shortname
 course shortname.
 
array $statuses = array()
 errors.
 
int $updatemode
 update mode.
 

Static Protected Attributes

static array $importoptionsdefaults
 options determining what can or cannot be done at an import level.
 
static array $mandatoryfields = array('fullname', 'category')
 fields required on course creation.
 
static array $optionfields
 fields which are considered as options.
 
static array $validfields
 fields allowed as course data.
 

Detailed Description

Course class.

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

Constructor & Destructor Documentation

◆ __construct()

tool_uploadcourse_course::__construct ( $mode,
$updatemode,
$rawdata,
$defaults = array(),
$importoptions = array() )

Constructor.

Parameters
int$modeimport mode, constant matching tool_uploadcourse_processor\MODE_*
int$updatemodeupdate mode, constant matching tool_uploadcourse_processor\UPDATE_*
array$rawdataraw course data.
array$defaultsdefault course data.
array$importoptionsimport options.

Member Function Documentation

◆ can_create()

tool_uploadcourse_course::can_create ( )

Does the mode allow for course creation?

Return values
bool

◆ can_delete()

tool_uploadcourse_course::can_delete ( )

Does the mode allow for course deletion?

Return values
bool

◆ can_only_create()

tool_uploadcourse_course::can_only_create ( )

Does the mode only allow for course creation?

Return values
bool

◆ can_rename()

tool_uploadcourse_course::can_rename ( )

Does the mode allow for course rename?

Return values
bool

◆ can_reset()

tool_uploadcourse_course::can_reset ( )

Does the mode allow for course reset?

Return values
bool

◆ can_update()

tool_uploadcourse_course::can_update ( )

Does the mode allow for course update?

Return values
bool

◆ can_use_defaults()

tool_uploadcourse_course::can_use_defaults ( )

Can we use default values?

Return values
bool

◆ delete()

tool_uploadcourse_course::delete ( )
protected

Delete the current course.

Return values
bool

◆ error()

tool_uploadcourse_course::error ( $code,
lang_string $message )
protected

Log an error.

Parameters
string$codeerror code.
lang_string$messageerror message.
Return values
void

◆ exists()

tool_uploadcourse_course::exists ( $shortname = null)
protected

Return whether the course exists or not.

Parameters
string$shortnamethe shortname to use to check if the course exists. Falls back on $this->shortname if empty.
Return values
bool

◆ get_data()

tool_uploadcourse_course::get_data ( )

Return the data that will be used upon saving.

Return values
null|array

◆ get_errors()

tool_uploadcourse_course::get_errors ( )

Return the errors found during preparation.

Return values
array

◆ get_final_create_data()

tool_uploadcourse_course::get_final_create_data ( $data)
protected

Assemble the course data based on defaults.

This returns the final data to be passed to create_course().

Parameters
array$datacurrent data.
Return values
array

◆ get_final_update_data()

tool_uploadcourse_course::get_final_update_data ( $data,
$usedefaults = false,
$missingonly = false )
protected

Assemble the course data based on defaults.

This returns the final data to be passed to update_course().

Parameters
array$datacurrent data.
bool$usedefaultsare defaults allowed?
bool$missingonlyignore fields which are already set.
Return values
array

◆ get_id()

tool_uploadcourse_course::get_id ( )

Return the ID of the processed course.

Return values
int|null

◆ get_restore_content_dir()

tool_uploadcourse_course::get_restore_content_dir ( )
protected

Get the directory of the object to restore.

Return values
string|false|nullsubdirectory in $CFG->backuptempdir/..., false when an error occured and null when there is simply nothing.

◆ get_statuses()

tool_uploadcourse_course::get_statuses ( )

Return the errors found during preparation.

Return values
array

◆ get_valid_fields()

tool_uploadcourse_course::get_valid_fields ( )
protected

Return array of valid fields for default values.

Return values
array

◆ has_errors()

tool_uploadcourse_course::has_errors ( )

Return whether there were errors with this course.

Return values
boolean

◆ prepare()

tool_uploadcourse_course::prepare ( )

Validates and prepares the data.

Return values
boolfalse is any error occured.

◆ proceed()

tool_uploadcourse_course::proceed ( )

Proceed with the import of the course.

Return values
void

◆ process_enrolment_data()

tool_uploadcourse_course::process_enrolment_data ( $course)
protected

Add the enrolment data for the course.

Parameters
object$coursecourse record.
Return values
void

◆ reset()

tool_uploadcourse_course::reset ( $course)
protected

Reset the current course.

This does not reset any of the content of the activities.

Parameters
stdClass$coursethe course object of the course to reset.
Return values
arraystatus array of array component, item, error.

◆ status()

tool_uploadcourse_course::status ( $code,
lang_string $message )
protected

Log a status.

Parameters
string$codestatus code.
lang_string$messagestatus message.
Return values
void

◆ validate_enrolment_data()

tool_uploadcourse_course::validate_enrolment_data ( int $courseid,
array $enrolmentdata )
protected

Validate passed enrolment data against an existing course.

Parameters
int$courseid
array[]$enrolmentdata
Return values
lang_string[]Errors keyed on error code

◆ validate_role_context()

tool_uploadcourse_course::validate_role_context ( int $courseid,
int $roleid )
protected

Check if role is allowed in course context.

Parameters
int$courseidcourse context.
int$roleidRole ID.
Return values
bool

◆ validate_role_context_level()

tool_uploadcourse_course::validate_role_context_level ( int $roleid)
protected

Check if role is allowed at this context level.

Parameters
int$roleidRole ID.
Return values
bool

Member Data Documentation

◆ $importoptionsdefaults

array tool_uploadcourse_course::$importoptionsdefaults
staticprotected
Initial value:
= array('canrename' => false, 'candelete' => false, 'canreset' => false,
'reset' => false, 'restoredir' => null, 'shortnametemplate' => null)

options determining what can or cannot be done at an import level.

◆ $mode

int tool_uploadcourse_course::$mode
protected

import mode.

Matches tool_uploadcourse_processor\MODE_*

◆ $optionfields

array tool_uploadcourse_course::$optionfields
staticprotected
Initial value:
= array('delete' => false, 'rename' => null, 'backupfile' => null,
'templatecourse' => null, 'reset' => false)

fields which are considered as options.

◆ $updatemode

int tool_uploadcourse_course::$updatemode
protected

update mode.

Matches tool_uploadcourse_processor\UPDATE_*

◆ $validfields

array tool_uploadcourse_course::$validfields
staticprotected
Initial value:
= array('fullname', 'shortname', 'idnumber', 'category', 'visible', 'startdate', 'enddate',
'summary', 'format', 'theme', 'lang', 'newsitems', 'showgrades', 'showreports', 'legacyfiles', 'maxbytes',
'groupmode', 'groupmodeforce', 'enablecompletion', 'downloadcontent', 'showactivitydates')

fields allowed as course data.


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