Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Class for loading/storing competencies from the DB. More...
Public Member Functions | |
__call ($method, $arguments) | |
Magic method to capture getters and setters. More... | |
create () | |
Insert a record in the DB. More... | |
delete () | |
Delete an entry from the database. More... | |
from_record (stdClass $record) | |
Populate this class with data from a DB record. More... | |
get ($property) | |
Data getter. More... | |
get_ancestors () | |
Get competency ancestors. More... | |
get_context () | |
Get the context from the framework. More... | |
get_default_grade () | |
Extracts the default grade from the scale configuration. More... | |
get_errors () | |
Returns the validation errors. More... | |
get_framework () | |
Get the competency framework. More... | |
get_level () | |
Get the competency level. More... | |
get_parent () | |
Return the parent competency. More... | |
get_proficiency_of_grade ($grade) | |
Extracts the proficiency of a grade from the scale configuration. More... | |
get_related_competencies () | |
Return the related competencies. More... | |
get_rule_object () | |
Get the rule object. More... | |
get_scale () | |
Return the scale. More... | |
has_user_competencies () | |
Returns true when the competency has user competencies. More... | |
is_parent_of (array $ids) | |
Check if the competency is the parent of passed competencies. More... | |
is_valid () | |
Returns whether or not the model is valid. More... | |
read () | |
Load the data from the DB. More... | |
reset_rule () | |
Reset the rule. More... | |
save () | |
Saves the record to the database. More... | |
set ($property, $value) | |
Data setter. More... | |
to_record () | |
Create a DB record from this class. More... | |
update () | |
Update the existing record in the DB. More... | |
validate () | |
Validates the data. More... | |
Static Public Member Functions | |
static | can_all_be_deleted ($ids) |
Check if we can delete competencies safely. More... | |
static | count_records (array $conditions=array()) |
Count a list of records. More... | |
static | count_records_select ($select, $params=null) |
Count a list of records. More... | |
static | delete_by_frameworkid ($id) |
Delete competencies by framework ID. More... | |
static | delete_multiple ($ids) |
Delete the competencies. More... | |
static | extract_record ($row, $prefix=null) |
Extract a record from a row of data. More... | |
static | get_available_rules () |
Get the available rules. More... | |
static | get_descendants_ids ($competency) |
Get descendant ids. More... | |
static | get_formatted_properties () |
Gets all the formatted properties. More... | |
static | get_framework_depth ($frameworkid) |
Return the current depth of a competency framework. More... | |
static | get_framework_tree ($frameworkid) |
Build a framework tree with competency nodes. More... | |
static | get_ids_by_frameworkid ($frameworkid) |
Get competencyids by frameworkid. More... | |
static | get_record ($filters=array()) |
Load a single record. More... | |
static | get_records ($filters=array(), $sort='', $order='ASC', $skip=0, $limit=0) |
Load a list of records. More... | |
static | get_records_select ($select, $params=null, $sort='', $fields=' *', $limitfrom=0, $limitnum=0) |
Load a list of records based on a select query. More... | |
static | get_sql_fields ($alias, $prefix=null) |
Return the list of fields for use in a SELECT clause. More... | |
static | has_property ($property) |
Returns whether or not a property was defined. More... | |
static | is_property_required ($property) |
Returns whether or not a property is required. More... | |
static | properties_definition () |
Get the properties definition of this model. More... | |
static | record_exists ($id) |
Check if a record exists by ID. More... | |
static | record_exists_select ($select, array $params=null) |
Check if a records exists. More... | |
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. More... | |
static | share_same_framework (array $ids) |
Return whether or not the competency IDs share the same framework. More... | |
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. More... | |
after_delete ($result) | |
Hook to execute after a delete. More... | |
after_update ($result) | |
Hook to execute after an update. More... | |
before_create () | |
Hook to execute before a create. More... | |
before_delete () | |
Hook to execute before a delete. More... | |
before_update () | |
Hook to execute before an update. More... | |
before_validate () | |
Hook to execute before validate. More... | |
raw_get ($property) | |
Internal Data getter. More... | |
raw_set ($property, $value) | |
Data setter. More... | |
set_new_path (competency $parent=null) | |
Helper method to set the path. More... | |
set_new_sortorder () | |
Helper method to set the sortorder. More... | |
validate_competencyframeworkid ($value) | |
Validate the competency framework ID. More... | |
validate_idnumber ($value) | |
Validate the ID number. More... | |
validate_parentid ($value) | |
Validate the parent ID. More... | |
validate_path ($value) | |
Validate the path. More... | |
validate_ruleconfig ($value) | |
Validate the rule config. More... | |
validate_ruletype ($value) | |
Validate the rule. More... | |
validate_scaleconfiguration ($value) | |
Validate the scale configuration. More... | |
validate_scaleid ($value) | |
Validate the scale ID. More... | |
verify_protected_methods () | |
This function is used to verify that custom getters and setters are declared as protected. More... | |
Static Protected Member Functions | |
static | build_tree ($all, $parentid) |
Recursively build up the tree of nodes. More... | |
static | define_properties () |
Return the definition of the properties of this model. More... | |
static | get_property_default_value ($property) |
Gets the default value for a property. More... | |
static | get_property_error_message ($property) |
Gets the error message for a property. More... | |
Protected Attributes | |
competency | $beforeupdate = null |
Object before update. | |
Class for loading/storing competencies from the DB.
|
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.
string | $method | Callee. |
array | $arguments | List of arguments. |
mixed |
|
protectedinherited |
Hook to execute after a create.
This is only intended to be used by child classes, do not put any logic here!
void |
Reimplemented in tool_dataprivacy\purpose_override, tool_dataprivacy\purpose, and tool_dataprivacy\contextlevel.
|
protected |
Hook to execute after a delete.
bool | $result | Whether or not the delete was successful. |
void |
Reimplemented from core\persistent.
|
protected |
Hook to execute after an update.
bool | $result | Whether or not the update was successful. |
void |
Reimplemented from core\persistent.
|
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!
void |
|
protectedinherited |
Hook to execute before a delete.
This is only intended to be used by child classes, do not put any logic here!
void |
Reimplemented in tool_dataprivacy\purpose_override, tool_dataprivacy\purpose, and tool_dataprivacy\contextlevel.
|
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!
void |
|
protected |
|
staticprotected |
Recursively build up the tree of nodes.
array | $all | - List of all competency classes. |
int | $parentid | - The current parent ID. Pass 0 to build the tree from the top. |
node[]::$tree | tree of nodes |
|
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.
array | $ids | Array of competencies ids. |
bool | True if we can delete the competencies. |
|
staticinherited |
Count a list of records.
array | $conditions | An array of conditions. |
int |
|
staticinherited |
Count a list of records.
string | $select | |
array | $params |
int |
|
finalinherited |
Insert a record in the DB.
static |
|
staticprotected |
Return the definition of the properties of this model.
array |
Reimplemented from core\persistent.
|
finalinherited |
Delete an entry from the database.
bool | True on success. |
|
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.
int | $id | the framework ID |
bool | Return true if delete was successful. |
|
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.
array | $ids | The competencies ids. |
bool | True if the competencies were deleted successfully. |
|
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.
stdClass | $row | The row of data. |
string | $prefix | The prefix the data fields are prefixed with, defaults to the table name followed by underscore. |
stdClass | The extracted data. |
|
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.
stdClass | $record | A DB record. |
static |
|
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 } or * self::from_record() because the data is not expected to be validated or changed when reading/writing raw records from the DB.
string | $property | The property name. |
mixed |
core_competency\competency::get_ancestors | ( | ) |
Get competency ancestors.
competency[] | Return array of ancestors. |
|
static |
Get the available rules.
array | Keys are the class names, values are the name of the rule. |
core_competency\competency::get_context | ( | ) |
Get the context from the framework.
context |
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'.
array(int | grade, bool proficient) |
|
static |
Get descendant ids.
competency | $competency | The competency. |
array | Array of competencies ids. |
|
finalinherited |
Returns the validation errors.
array |
|
staticfinalinherited |
Gets all the formatted properties.
Formatted properties are properties which have a format associated with them.
array | Keys are property names, values are property format names. |
core_competency\competency::get_framework | ( | ) |
Get the competency framework.
competency_framework |
|
static |
Return the current depth of a competency framework.
int | $frameworkid | The framework ID. |
int |
|
static |
Build a framework tree with competency nodes.
int | $frameworkid | the framework id |
node[] | tree of framework competency nodes |
|
static |
Get competencyids by frameworkid.
int | $frameworkid | The competency framework ID. |
array | Array of competency ids. |
core_competency\competency::get_level | ( | ) |
Get the competency level.
int |
core_competency\competency::get_parent | ( | ) |
Return the parent competency.
null|competency |
core_competency\competency::get_proficiency_of_grade | ( | $grade | ) |
Extracts the proficiency of a grade from the scale configuration.
int | $grade | The grade (scale item ID). |
array(int | grade, bool proficient) |
|
staticfinalprotectedinherited |
Gets the default value for a property.
This assumes that the property exists.
string | $property | The property name. |
mixed |
|
staticfinalprotectedinherited |
Gets the error message for a property.
This assumes that the property exists.
string | $property | The property name. |
lang_string |
|
staticinherited |
Load a single record.
array | $filters | Filters to apply. |
false|static |
|
staticinherited |
Load a list of records.
array | $filters | Filters to apply. |
string | $sort | Field to sort by. |
string | $order | Sort order. |
int | $skip | Limitstart. |
int | $limit | Number of rows to return. |
static[] |
|
staticinherited |
Load a list of records based on a select query.
string | $select | |
array | $params | |
string | $sort | |
string | $fields | |
int | $limitfrom | |
int | $limitnum |
static[] |
core_competency\competency::get_related_competencies | ( | ) |
Return the related competencies.
competency[] |
core_competency\competency::get_rule_object | ( | ) |
Get the rule object.
null|competency_rule |
core_competency\competency::get_scale | ( | ) |
Return the scale.
grade_scale |
|
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.
string | $alias | The alias used for the table. |
string | $prefix | The prefix to use for each field, defaults to the table name followed by underscore. |
string | The SQL fragment. |
|
staticfinalinherited |
Returns whether or not a property was defined.
string | $property | The property name. |
boolean |
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.
boolean |
core_competency\competency::is_parent_of | ( | array | $ids | ) |
Check if the competency is the parent of passed competencies.
array | $ids | IDs of supposedly direct children. |
boolean |
|
staticfinalinherited |
Returns whether or not a property is required.
By definition a property with a default value is not required.
string | $property | The property name. |
boolean |
|
finalinherited |
Returns whether or not the model is valid.
boolean | True when it is. |
|
staticfinalinherited |
Get the properties definition of this model.
array |
|
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 } 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.
string | $property | The property name. |
mixed |
|
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 } or * self::from_record() to use them.
This is protected because it is only for raw low level access to the data fields.
string | $property | The property name. |
mixed | $value | The value. |
$this |
|
finalinherited |
Load the data from the DB.
static |
|
staticinherited |
Check if a record exists by ID.
int | $id | Record ID. |
bool |
|
staticinherited |
Check if a records exists.
string | $select | |
array | $params |
bool |
core_competency\competency::reset_rule | ( | ) |
Reset the rule.
void |
|
finalinherited |
Saves the record to the database.
If this record has an ID, then } is called, otherwise self::create() is called. Before and after hooks for create() or update() will be called appropriately.
void |
|
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.
string | $searchtext | The text to search for. |
int | $competencyframeworkid | The competency framework to limit the search. |
persistent[] |
|
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 } or * self::from_record() because the data is not expected to be validated or changed when reading/writing raw records from the DB.
string | $property | The property name. |
$this |
|
protected |
Helper method to set the path.
competency | $parent | The parent competency object. |
void |
|
protected |
Helper method to set the sortorder.
void |
|
static |
Return whether or not the competency IDs share the same framework.
array | $ids | Competency IDs |
bool |
|
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.
stdClass |
|
finalinherited |
Update the existing record in the DB.
bool | True on success. |
|
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.
array|true | Returns true when the validation passed, or an array of properties with errors. |
|
protected |
Validate the competency framework ID.
int | $value | The framework ID. |
true|lang_string |
|
protected |
Validate the ID number.
string | $value | The ID number. |
true|lang_string |
|
protected |
Validate the parent ID.
string | $value | The ID. |
true|lang_string |
|
protected |
Validate the path.
string | $value | The path. |
true|lang_string |
|
protected |
Validate the rule config.
string | $value | The ID. |
true|lang_string |
|
protected |
Validate the rule.
string | $value | The ID. |
true|lang_string |
|
protected |
Validate the scale configuration.
This logic is adapted from ().
string | $value | The scale configuration. |
bool|lang_string |
|
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.
int | $value |
true|lang_string |
|
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.