Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
convert_path Class Reference

Class representing a path to be converted from XML file. More...

Public Member Functions

 __construct ($name, $path, array $recipe=array(), $grouped=false)
 Constructor. More...
 
 apply_recipes (array $data)
 Cooks the parsed tags data by applying known recipes. More...
 
 get_end_method ()
 
 get_name ()
 
 get_path ()
 
 get_processing_method ()
 
 get_processing_object ()
 
 get_start_method ()
 
 get_tags ()
 
 is_grouped ()
 
 set_dropped_fields (array $fields)
 Sets the list of deprecated fields to drop. More...
 
 set_end_method ($emethod)
 Sets the name of the path end event listener. More...
 
 set_new_fields (array $fields)
 Sets the new fields and their values. More...
 
 set_processing_method ($pmethod)
 Sets the name of the processing method. More...
 
 set_processing_object ($pobject)
 Validates and sets the given processing object. More...
 
 set_renamed_fields (array $fields)
 Sets the required new names of the current fields. More...
 
 set_start_method ($smethod)
 Sets the name of the path start event listener. More...
 
 set_tags ($tags)
 Sets the element tags. More...
 

Protected Member Functions

 validate_name ($name)
 end of public API ////////////////////////////////////////////////////// More...
 
 validate_pobject ($pobject)
 Makes sure that the given object is a valid processing object. More...
 

Protected Attributes

array $dropfields = array()
 of deprecated fields that are dropped
 
string $emethod = null
 the name of the path end event handler
 
bool $grouped
 flag to define if this element will get child ones grouped or no
 
string $name
 name of the element
 
array $newfields = array()
 of new fields to add and their initial values
 
string $path
 path within the XML file this element will handle
 
string $pmethod = null
 the name of the processing method
 
object $pobject = null
 object instance in charge of processing this element.
 
array $renamefields = array()
 of fields renaming
 
string $smethod = null
 the name of the path start event handler
 
mixed $tags = null
 last data read for this element or returned data by processing method
 

Detailed Description

Class representing a path to be converted from XML file.

This was created as a copy of restore_path_element and should be refactored probably.

Constructor & Destructor Documentation

◆ __construct()

convert_path::__construct (   $name,
  $path,
array  $recipe = array(),
  $grouped = false 
)

Constructor.

The optional recipe array can have three keys, and for each key, the value is another array.

  • newfields => array fieldname => defaultvalue indicates fields that have been added to the table, and so should be added to the XML.
  • dropfields => array fieldname indicates fieldsthat have been dropped from the table, and so can be dropped from the XML.
  • renamefields => array oldname => newname indicates fieldsthat have been renamed in the table, and so should be renamed in the XML. {
Parameters
string$namename of the element
string$pathpath of the element
array$recipebasic description of the structure conversion
bool$groupedto gather information in grouped mode or no

Member Function Documentation

◆ apply_recipes()

convert_path::apply_recipes ( array  $data)

Cooks the parsed tags data by applying known recipes.

Recipes are used for common trivial operations like adding new fields or renaming fields. The handler's processing method receives cooked data.

Parameters
array$datathe contents of the element
Return values
array

◆ get_end_method()

convert_path::get_end_method ( )
Return values
stringthe name of the path end event listener

◆ get_name()

convert_path::get_name ( )
Return values
stringthe element given name

◆ get_path()

convert_path::get_path ( )
Return values
stringthe path to the element

◆ get_processing_method()

convert_path::get_processing_method ( )
Return values
stringthe name of the method to call to process the element

◆ get_processing_object()

convert_path::get_processing_object ( )
Return values
objectthe processing object providing the processing method

◆ get_start_method()

convert_path::get_start_method ( )
Return values
stringthe name of the path start event listener

◆ get_tags()

convert_path::get_tags ( )
Return values
mixedthe element data

◆ is_grouped()

convert_path::is_grouped ( )
Return values
boolflag to define if this element will get child ones grouped or no

◆ set_dropped_fields()

convert_path::set_dropped_fields ( array  $fields)

Sets the list of deprecated fields to drop.

Parameters
array$fields

◆ set_end_method()

convert_path::set_end_method (   $emethod)

Sets the name of the path end event listener.

Parameters
string$emethod

◆ set_new_fields()

convert_path::set_new_fields ( array  $fields)

Sets the new fields and their values.

Parameters
array$fields(string)$field => (mixed)value

◆ set_processing_method()

convert_path::set_processing_method (   $pmethod)

Sets the name of the processing method.

Parameters
string$pmethod

◆ set_processing_object()

convert_path::set_processing_object (   $pobject)

Validates and sets the given processing object.

Parameters
object$pobjectprocessing object, must provide a method to be called

◆ set_renamed_fields()

convert_path::set_renamed_fields ( array  $fields)

Sets the required new names of the current fields.

Parameters
array$fields(string)$currentname => (string)$newname

◆ set_start_method()

convert_path::set_start_method (   $smethod)

Sets the name of the path start event listener.

Parameters
string$smethod

◆ set_tags()

convert_path::set_tags (   $tags)

Sets the element tags.

Parameters
array$tags

◆ validate_name()

convert_path::validate_name (   $name)
protected

end of public API //////////////////////////////////////////////////////

Makes sure the given name is a valid element name

Note it may look as if we used exceptions for code flow control here. That's not the case as we actually validate the code, not the user data. And the code is supposed to be correct.

Parameters
string
Exceptions
convert_path_exception
Return values
void

◆ validate_pobject()

convert_path::validate_pobject (   $pobject)
protected

Makes sure that the given object is a valid processing object.

The processing object must be an object providing at least element's processing method or path-reached-end event listener or path-reached-start listener method.

Note it may look as if we used exceptions for code flow control here. That's not the case as we actually validate the code, not the user data. And the code is supposed to be correct.

Parameters
object$pobject
Exceptions
convert_path_exception
Return values
void

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