Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
core_competency\competency Class Reference

Class for loading/storing competencies from the DB. More...

Inheritance diagram for core_competency\competency:
core_competency\persistent core\persistent

Public Member Functions

 __call ($method, $arguments)
 Magic method to capture getters and setters.
 
 create ()
 Insert a record in the DB.
 
 delete ()
 Delete an entry from the database.
 
 from_record (stdClass $record)
 Populate this class with data from a DB record.
 
 get ($property)
 Data getter.
 
 get_ancestors ()
 Get competency ancestors.
 
 get_context ()
 Get the context from the framework.
 
 get_default_grade ()
 Extracts the default grade from the scale configuration.
 
 get_errors ()
 Returns the validation errors.
 
 get_framework ()
 Get the competency framework.
 
 get_level ()
 Get the competency level.
 
 get_parent ()
 Return the parent competency.
 
 get_proficiency_of_grade ($grade)
 Extracts the proficiency of a grade from the scale configuration.
 
 get_related_competencies ()
 Return the related competencies.
 
 get_rule_object ()
 Get the rule object.
 
 get_scale ()
 Return the scale.
 
 has_user_competencies ()
 Returns true when the competency has user competencies.
 
 is_parent_of (array $ids)
 Check if the competency is the parent of passed competencies.
 
 is_valid ()
 Returns whether or not the model is valid.
 
 read ()
 Load the data from the DB.
 
 reset_rule ()
 Reset the rule.
 
 save ()
 Saves the record to the database.
 
 set ($property, $value)
 Data setter.
 
 set_many (array $values)
 Data setter for multiple properties.
 
 to_record ()
 Create a DB record from this class.
 
 update ()
 Update the existing record in the DB.
 
 validate ()
 Validates the data.
 

Static Public Member Functions

static can_all_be_deleted ($ids)
 Check if we can delete competencies safely.
 
static count_records (array $conditions=array())
 Count a list of records.
 
static count_records_select ($select, $params=null)
 Count a list of records.
 
static delete_by_frameworkid ($id)
 Delete competencies by framework ID.
 
static delete_multiple ($ids)
 Delete the competencies.
 
static extract_record ($row, $prefix=null)
 Extract a record from a row of data.
 
static get_available_rules ()
 Get the available rules.
 
static get_descendants_ids ($competency)
 Get descendant ids.
 
static get_formatted_properties ()
 Gets all the formatted properties.
 
static get_framework_depth ($frameworkid)
 Return the current depth of a competency framework.
 
static get_framework_tree ($frameworkid)
 Build a framework tree with competency nodes.
 
static get_ids_by_frameworkid ($frameworkid)
 Get competencyids by frameworkid.
 
static get_record (array $filters=[], int $strictness=IGNORE_MISSING)
 Load a single record.
 
static get_records ($filters=array(), $sort='', $order='ASC', $skip=0, $limit=0)
 Load a list of records.
 
static get_records_select ($select, $params=null, $sort='', $fields=' *', $limitfrom=0, $limitnum=0)
 Load a list of records based on a select query.
 
static get_sql_fields ($alias, $prefix=null)
 Return the list of fields for use in a SELECT clause.
 
static has_property ($property)
 Returns whether or not a property was defined.
 
static is_property_required ($property)
 Returns whether or not a property is required.
 
static properties_definition ()
 Get the properties definition of this model.
 
static properties_filter (stdClass $record)
 For a given record, return an array containing only those properties that are defined by the persistent.
 
static record_exists ($id)
 Check if a record exists by ID.
 
static record_exists_select ($select, array $params=null)
 Check if a records exists.
 
static search ($searchtext, $competencyframeworkid)
 This does a specialised search that finds all nodes in the tree with matching text on any text like field, and returns this node and all its parents in a displayable sort order.
 
static share_same_framework (array $ids)
 Return whether or not the competency IDs share the same framework.
 

Public Attributes

const OUTCOME_COMPLETE = 2
 Outcome complete.
 
const OUTCOME_EVIDENCE = 1
 Outcome evidence.
 
const OUTCOME_NONE = 0
 Outcome none.
 
const OUTCOME_RECOMMEND = 3
 Outcome recommend.
 
const TABLE = 'competency'
 

Protected Member Functions

 after_create ()
 Hook to execute after a create.
 
 after_delete ($result)
 Hook to execute after a delete.
 
 after_update ($result)
 Hook to execute after an update.
 
 before_create ()
 Hook to execute before a create.
 
 before_delete ()
 Hook to execute before a delete.
 
 before_update ()
 Hook to execute before an update.
 
 before_validate ()
 Hook to execute before validate.
 
 raw_get ($property)
 Internal Data getter.
 
 raw_set ($property, $value)
 Data setter.
 
 set_new_path (competency $parent=null)
 Helper method to set the path.
 
 set_new_sortorder ()
 Helper method to set the sortorder.
 
 validate_competencyframeworkid ($value)
 Validate the competency framework ID.
 
 validate_idnumber ($value)
 Validate the ID number.
 
 validate_parentid ($value)
 Validate the parent ID.
 
 validate_path ($value)
 Validate the path.
 
 validate_ruleconfig ($value)
 Validate the rule config.
 
 validate_ruletype ($value)
 Validate the rule.
 
 validate_scaleconfiguration ($value)
 Validate the scale configuration.
 
 validate_scaleid ($value)
 Validate the scale ID.
 
 verify_protected_methods ()
 This function is used to verify that custom getters and setters are declared as protected.
 

Static Protected Member Functions

static build_tree ($all, $parentid)
 Recursively build up the tree of nodes.
 
static define_properties ()
 Return the definition of the properties of this model.
 
static get_property_default_value ($property)
 Gets the default value for a property.
 
static get_property_error_message ($property)
 Gets the error message for a property.
 

Protected Attributes

competency $beforeupdate = null
 Object before update.
 
competency null $newparent
 To store new parent.
 

Detailed Description

Class for loading/storing competencies from the DB.

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

Member Function Documentation

◆ __call()

core_competency\persistent::__call ( $method,
$arguments )
finalinherited

Magic method to capture getters and setters.

This is only available for competency persistents for backwards compatibility. It is recommended to use get('propertyname') and set('propertyname', 'value') directly.

Parameters
string$methodCallee.
array$argumentsList of arguments.
Return values
mixed

◆ after_create()

core\persistent::after_create ( )
protectedinherited

◆ after_delete()

core_competency\competency::after_delete ( $result)
protected

Hook to execute after a delete.

Parameters
bool$resultWhether or not the delete was successful.
Return values
void

Reimplemented from core\persistent.

◆ after_update()

core_competency\competency::after_update ( $result)
protected

Hook to execute after an update.

Parameters
bool$resultWhether or not the update was successful.
Return values
void

Reimplemented from core\persistent.

◆ before_create()

core\persistent::before_create ( )
protectedinherited

Hook to execute before a create.

Please note that at this stage the data has already been validated and therefore any new data being set will not be validated before it is sent to the database.

This is only intended to be used by child classes, do not put any logic here!

Return values
void

Reimplemented in quizaccess_seb\seb_quiz_settings, and quizaccess_seb\template.

◆ before_delete()

core\persistent::before_delete ( )
protectedinherited

Hook to execute before a delete.

This is only intended to be used by child classes, do not put any logic here!

Return values
void

Reimplemented in core_reportbuilder\local\models\report, mod_bigbluebuttonbn\recording, quizaccess_seb\seb_quiz_settings, tool_dataprivacy\contextlevel, tool_dataprivacy\purpose, and tool_dataprivacy\purpose_override.

◆ before_update()

core\persistent::before_update ( )
protectedinherited

Hook to execute before an update.

Please note that at this stage the data has already been validated and therefore any new data being set will not be validated before it is sent to the database.

This is only intended to be used by child classes, do not put any logic here!

Return values
void

Reimplemented in mod_bigbluebuttonbn\recording, quizaccess_seb\seb_quiz_settings, and quizaccess_seb\template.

◆ before_validate()

core_competency\competency::before_validate ( )
protected

Hook to execute before validate.

Return values
void

Reimplemented from core\persistent.

◆ build_tree()

static core_competency\competency::build_tree ( $all,
$parentid )
staticprotected

Recursively build up the tree of nodes.

Parameters
array$all- List of all competency classes.
int$parentid- The current parent ID. Pass 0 to build the tree from the top.
Return values
stdClass[]\$treetree of nodes

◆ can_all_be_deleted()

static core_competency\competency::can_all_be_deleted ( $ids)
static

Check if we can delete competencies safely.

This moethod does not check any capablities. Check if competency is used in a plan and user competency. Check if competency is used in a template. Check if competency is linked to a course.

Parameters
array$idsArray of competencies ids.
Return values
boolTrue if we can delete the competencies.

◆ count_records()

static core\persistent::count_records ( array $conditions = array())
staticinherited

Count a list of records.

Parameters
array$conditionsAn array of conditions.
Return values
int

◆ count_records_select()

static core\persistent::count_records_select ( $select,
$params = null )
staticinherited

Count a list of records.

Parameters
string$select
array$params
Return values
int

◆ create()

core\persistent::create ( )
finalinherited

Insert a record in the DB.

Return values
static

◆ define_properties()

static core_competency\competency::define_properties ( )
staticprotected

Return the definition of the properties of this model.

Return values
array

Reimplemented from core\persistent.

◆ delete()

core\persistent::delete ( )
finalinherited

Delete an entry from the database.

Return values
boolTrue on success.

◆ delete_by_frameworkid()

static core_competency\competency::delete_by_frameworkid ( $id)
static

Delete competencies by framework ID.

This method is reserved to core usage. This method does not trigger the after_delete event. This method does not delete related objects such as related competencies and evidences.

Parameters
int$idthe framework ID
Return values
boolReturn true if delete was successful.

◆ delete_multiple()

static core_competency\competency::delete_multiple ( $ids)
static

Delete the competencies.

This method is reserved to core usage. This method does not trigger the after_delete event. This method does not delete related objects such as related competencies and evidences.

Parameters
array$idsThe competencies ids.
Return values
boolTrue if the competencies were deleted successfully.

◆ extract_record()

static core\persistent::extract_record ( $row,
$prefix = null )
staticinherited

Extract a record from a row of data.

Most likely used in combination with self::get_sql_fields(). This method is simple enough to be used by non-persistent classes, keep that in mind when modifying it.

e.g. persistent\extract_record($row, 'user'); should work.

Parameters
stdClass$rowThe row of data.
string$prefixThe prefix the data fields are prefixed with, defaults to the table name followed by underscore.
Return values
stdClassThe extracted data.

◆ from_record()

core\persistent::from_record ( stdClass $record)
finalinherited

Populate this class with data from a DB record.

Note that this does not use any custom setter because the data here is intended to represent what is stored in the database.

Parameters
stdClass$recordA DB record.
Return values
static

◆ get()

core\persistent::get ( $property)
finalinherited

Data getter.

This is the main getter for all the properties. Developers can implement their own getters (get_propertyname) and they will be called by this function. Custom getters can use raw_get to get the raw value. Internally this is not used by self::to_record() or self::from_record() because the data is not expected to be validated or changed when reading/writing raw records from the DB.

Parameters
string$propertyThe property name.
Return values
mixed

◆ get_ancestors()

core_competency\competency::get_ancestors ( )

Get competency ancestors.

Return values
competency[]Return array of ancestors.

◆ get_available_rules()

static core_competency\competency::get_available_rules ( )
static

Get the available rules.

Return values
arrayKeys are the class names, values are the name of the rule.

◆ get_context()

core_competency\competency::get_context ( )

Get the context from the framework.

Return values
context

◆ get_default_grade()

core_competency\competency::get_default_grade ( )

Extracts the default grade from the scale configuration.

Returns an array where the first element is the grade, and the second is a boolean representing whether or not this grade is considered 'proficient'.

Return values
array(intgrade, bool proficient)

◆ get_descendants_ids()

static core_competency\competency::get_descendants_ids ( $competency)
static

Get descendant ids.

Parameters
competency$competencyThe competency.
Return values
arrayArray of competencies ids.

◆ get_errors()

core\persistent::get_errors ( )
finalinherited

Returns the validation errors.

Return values
array

◆ get_formatted_properties()

static core\persistent::get_formatted_properties ( )
staticfinalinherited

Gets all the formatted properties.

Formatted properties are properties which have a format associated with them.

Return values
arrayKeys are property names, values are property format names.

◆ get_framework()

core_competency\competency::get_framework ( )

Get the competency framework.

Return values
competency_framework

◆ get_framework_depth()

static core_competency\competency::get_framework_depth ( $frameworkid)
static

Return the current depth of a competency framework.

Parameters
int$frameworkidThe framework ID.
Return values
int

◆ get_framework_tree()

static core_competency\competency::get_framework_tree ( $frameworkid)
static

Build a framework tree with competency nodes.

Parameters
int$frameworkidthe framework id
Return values
stdClass[]tree of framework competency nodes

◆ get_ids_by_frameworkid()

static core_competency\competency::get_ids_by_frameworkid ( $frameworkid)
static

Get competencyids by frameworkid.

Parameters
int$frameworkidThe competency framework ID.
Return values
arrayArray of competency ids.

◆ get_level()

core_competency\competency::get_level ( )

Get the competency level.

Return values
int

◆ get_parent()

core_competency\competency::get_parent ( )

Return the parent competency.

Return values
null|competency

◆ get_proficiency_of_grade()

core_competency\competency::get_proficiency_of_grade ( $grade)

Extracts the proficiency of a grade from the scale configuration.

Parameters
int$gradeThe grade (scale item ID).
Return values
array(intgrade, bool proficient)

◆ get_property_default_value()

static core\persistent::get_property_default_value ( $property)
staticfinalprotectedinherited

Gets the default value for a property.

This assumes that the property exists.

Parameters
string$propertyThe property name.
Return values
mixed

◆ get_property_error_message()

static core\persistent::get_property_error_message ( $property)
staticfinalprotectedinherited

Gets the error message for a property.

This assumes that the property exists.

Parameters
string$propertyThe property name.
Return values
lang_string

◆ get_record()

static core\persistent::get_record ( array $filters = [],
int $strictness = IGNORE_MISSING )
staticinherited

Load a single record.

Parameters
array$filtersFilters to apply.
int$strictnessSimilar to the internal DB get_record call, indicate whether a missing record should be ignored/return false ({
See also
IGNORE_MISSING}) or should cause an exception to be thrown ({
MUST_EXIST})
Return values
false|static

◆ get_records()

static core\persistent::get_records ( $filters = array(),
$sort = '',
$order = 'ASC',
$skip = 0,
$limit = 0 )
staticinherited

Load a list of records.

Parameters
array$filtersFilters to apply.
string$sortField to sort by.
string$orderSort order.
int$skipLimitstart.
int$limitNumber of rows to return.
Return values
static[]

◆ get_records_select()

static core\persistent::get_records_select ( $select,
$params = null,
$sort = '',
$fields = '*',
$limitfrom = 0,
$limitnum = 0 )
staticinherited

Load a list of records based on a select query.

Parameters
string$select
array$params
string$sort
string$fields
int$limitfrom
int$limitnum
Return values
static[]

◆ get_related_competencies()

core_competency\competency::get_related_competencies ( )

Return the related competencies.

Return values
competency[]

◆ get_rule_object()

core_competency\competency::get_rule_object ( )

Get the rule object.

Return values
null|competency_rule

◆ get_scale()

core_competency\competency::get_scale ( )

Return the scale.

Return values
grade_scale

◆ get_sql_fields()

static core\persistent::get_sql_fields ( $alias,
$prefix = null )
staticinherited

Return the list of fields for use in a SELECT clause.

Having the complete list of fields prefixed allows for multiple persistents to be fetched in a single query. Use self::extract_record() to extract the records from the query result.

Parameters
string$aliasThe alias used for the table.
string$prefixThe prefix to use for each field, defaults to the table name followed by underscore.
Return values
stringThe SQL fragment.

◆ has_property()

static core\persistent::has_property ( $property)
staticfinalinherited

Returns whether or not a property was defined.

Parameters
string$propertyThe property name.
Return values
boolean

◆ has_user_competencies()

core_competency\competency::has_user_competencies ( )

Returns true when the competency has user competencies.

This is useful to determine if the competency, or part of it, should be locked down.

Return values
boolean

◆ is_parent_of()

core_competency\competency::is_parent_of ( array $ids)

Check if the competency is the parent of passed competencies.

Parameters
array$idsIDs of supposedly direct children.
Return values
boolean

◆ is_property_required()

static core\persistent::is_property_required ( $property)
staticfinalinherited

Returns whether or not a property is required.

By definition a property with a default value is not required.

Parameters
string$propertyThe property name.
Return values
boolean

◆ is_valid()

core\persistent::is_valid ( )
finalinherited

Returns whether or not the model is valid.

Return values
booleanTrue when it is.

◆ properties_definition()

static core\persistent::properties_definition ( )
staticfinalinherited

Get the properties definition of this model.

Return values
array

◆ properties_filter()

static core\persistent::properties_filter ( stdClass $record)
staticfinalinherited

For a given record, return an array containing only those properties that are defined by the persistent.

Parameters
stdClass$record
Return values
array

◆ raw_get()

core\persistent::raw_get ( $property)
finalprotectedinherited

Internal Data getter.

This is the main getter for all the properties. Developers can implement their own getters but they should be calling self::get() in order to retrieve the value. Essentially the getters defined by the developers would only ever be used as helper methods and will not be called internally at this stage. In other words, do not expect self::to_record() or self::from_record() to use them.

This is protected because it is only for raw low level access to the data fields. Note this function is named raw_get and not get_raw to avoid naming clashes with a property named raw.

Parameters
string$propertyThe property name.
Return values
mixed

◆ raw_set()

core\persistent::raw_set ( $property,
$value )
finalprotectedinherited

Data setter.

This is the main setter for all the properties. Developers can implement their own setters but they should always be calling self::set() in order to set the value. Essentially the setters defined by the developers are helper methods and will not be called internally at this stage. In other words do not expect self::to_record() or self::from_record() to use them.

This is protected because it is only for raw low level access to the data fields.

Parameters
string$propertyThe property name.
mixed$valueThe value.
Return values
$this

◆ read()

core\persistent::read ( )
finalinherited

Load the data from the DB.

Return values
static

◆ record_exists()

static core\persistent::record_exists ( $id)
staticinherited

Check if a record exists by ID.

Parameters
int$idRecord ID.
Return values
bool

◆ record_exists_select()

static core\persistent::record_exists_select ( $select,
array $params = null )
staticinherited

Check if a records exists.

Parameters
string$select
array$params
Return values
bool

◆ reset_rule()

core_competency\competency::reset_rule ( )

Reset the rule.

Return values
void

◆ save()

core\persistent::save ( )
finalinherited

Saves the record to the database.

If this record has an ID, then self::update() is called, otherwise self::create() is called. Before and after hooks for create() or update() will be called appropriately.

Return values
void

◆ search()

static core_competency\competency::search ( $searchtext,
$competencyframeworkid )
static

This does a specialised search that finds all nodes in the tree with matching text on any text like field, and returns this node and all its parents in a displayable sort order.

Parameters
string$searchtextThe text to search for.
int$competencyframeworkidThe competency framework to limit the search.
Return values
persistent[]

◆ set()

core\persistent::set ( $property,
$value )
finalinherited

Data setter.

This is the main setter for all the properties. Developers can implement their own setters (set_propertyname) and they will be called by this function. Custom setters should call internal_set() to finally set the value. Internally this is not used self::to_record() or self::from_record() because the data is not expected to be validated or changed when reading/writing raw records from the DB.

Parameters
string$propertyThe property name.
Return values
$this
Exceptions
coding_exception

◆ set_many()

core\persistent::set_many ( array $values)
finalinherited

Data setter for multiple properties.

Internally calls {

See also
set} on each property
Parameters
array$valuesArray of property => value elements
Return values
$this

◆ set_new_path()

core_competency\competency::set_new_path ( competency $parent = null)
protected

Helper method to set the path.

Parameters
competency$parentThe parent competency object.
Return values
void

◆ set_new_sortorder()

core_competency\competency::set_new_sortorder ( )
protected

Helper method to set the sortorder.

Return values
void

◆ share_same_framework()

static core_competency\competency::share_same_framework ( array $ids)
static

Return whether or not the competency IDs share the same framework.

Parameters
array$idsCompetency IDs
Return values
bool

◆ to_record()

core\persistent::to_record ( )
finalinherited

Create a DB record from this class.

Note that this does not use any custom getter because the data here is intended to represent what is stored in the database.

Return values
stdClass

◆ update()

core\persistent::update ( )
finalinherited

Update the existing record in the DB.

Return values
boolTrue on success.

◆ validate()

core\persistent::validate ( )
finalinherited

Validates the data.

Developers can implement addition validation by defining a method as follows. Note that the method MUST return a lang_string() when there is an error, and true when the data is valid.

protected function validate_propertyname($value) { if ($value !== 'My expected value') { return new lang_string('invaliddata', 'error'); } return true }

It is OK to use other properties in your custom validation methods when you need to, however note they might not have been validated yet, so try not to rely on them too much.

Note that the validation methods should be protected. Validating just one field is not recommended because of the possible dependencies between one field and another,also the field ID can be used to check whether the object is being updated or created.

When validating foreign keys the persistent should only check that the associated model exists. The validation methods should not be used to check for a change in that relationship. The API method setting the attributes on the model should be responsible for that. E.g. On a course model, the method validate_categoryid will check that the category exists. However, if a course can never be moved outside of its category it would be up to the calling code to ensure that the category ID will not be altered.

Return values
array|trueReturns true when the validation passed, or an array of properties with errors.

◆ validate_competencyframeworkid()

core_competency\competency::validate_competencyframeworkid ( $value)
protected

Validate the competency framework ID.

Parameters
int$valueThe framework ID.
Return values
true|lang_string

◆ validate_idnumber()

core_competency\competency::validate_idnumber ( $value)
protected

Validate the ID number.

Parameters
string$valueThe ID number.
Return values
true|lang_string

◆ validate_parentid()

core_competency\competency::validate_parentid ( $value)
protected

Validate the parent ID.

Parameters
string$valueThe ID.
Return values
true|lang_string

◆ validate_path()

core_competency\competency::validate_path ( $value)
protected

Validate the path.

Parameters
string$valueThe path.
Return values
true|lang_string

◆ validate_ruleconfig()

core_competency\competency::validate_ruleconfig ( $value)
protected

Validate the rule config.

Parameters
string$valueThe ID.
Return values
true|lang_string

◆ validate_ruletype()

core_competency\competency::validate_ruletype ( $value)
protected

Validate the rule.

Parameters
string$valueThe ID.
Return values
true|lang_string

◆ validate_scaleconfiguration()

core_competency\competency::validate_scaleconfiguration ( $value)
protected

Validate the scale configuration.

This logic is adapted from core_competency::competency_framework::validate_scaleconfiguration().

Parameters
string$valueThe scale configuration.
Return values
bool|lang_string

◆ validate_scaleid()

core_competency\competency::validate_scaleid ( $value)
protected

Validate the scale ID.

Note that the value for a scale can never be 0, null has to be used when the framework's scale has to be used.

Parameters
int$value
Return values
true|lang_string

◆ verify_protected_methods()

core\persistent::verify_protected_methods ( )
finalprotectedinherited

This function is used to verify that custom getters and setters are declared as protected.

Persistent properties should always be accessed via get('property') and set('property', 'value') which will call the custom getter or setter if it exists. We do not want to allow inconsistent access to the properties.


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