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

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

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

Public Member Functions

 __call ($method, $arguments)
 Magic method to capture getters and setters. More...
 
 can_comment ()
 Whether the current user can comment on this user competency. More...
 
 can_read ()
 Whether the current user can read this user competency. More...
 
 can_read_comments ()
 Whether the current user can read comments on this user competency. More...
 
 can_request_review ()
 Can the current user send the user competency for review? More...
 
 can_review ()
 Can the current user review the user competency? 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_comment_object ()
 Get the comment object. More...
 
 get_competency ()
 Return the competency Object. More...
 
 get_context ()
 Get the context. More...
 
 get_errors ()
 Returns the validation errors. More...
 
 get_plans ()
 Find the plans for the user and this competency. More...
 
 is_valid ()
 Returns whether or not the model is valid. More...
 
 read ()
 Load the data from the DB. 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_comment_user ($userid)
 Can the current user comment on a user's competency? More...
 
static can_grade_user ($userid)
 Can the current user grade a user's user competency? More...
 
static can_grade_user_in_course ($userid, $courseid)
 Can the current user grade a user's user competency in a course? More...
 
static can_read_comments_user ($userid)
 Can the current user read the comments on a user's competency? More...
 
static can_read_user ($userid)
 Can the current user read a user's competency? More...
 
static can_read_user_in_course ($userid, $courseid)
 Can the current user read the user competencies of a user in a course? More...
 
static can_request_review_user ($userid)
 Can the current user send a user's competency for review? More...
 
static can_review_user ($userid)
 Can the current user review the user competency? 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 create_relation ($userid, $competencyid)
 Create a new user_competency object. More...
 
static extract_record ($row, $prefix=null)
 Extract a record from a row of data. More...
 
static get_competency_by_usercompetencyid ($id)
 Fetch a competency by user competency ID. More...
 
static get_formatted_properties ()
 Gets all the formatted properties. More...
 
static get_multiple ($userid, array $competenciesorids=null)
 Get multiple user_competency for a user. 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 get_status_list ()
 Get list of competency status. More...
 
static get_status_name ($status)
 Human readable status name. More...
 
static has_property ($property)
 Returns whether or not a property was defined. More...
 
static has_records_for_competencies ($competencyids)
 Check if user competency has records for competencies. More...
 
static has_records_for_competency ($competencyid)
 Checks if a competency has user competency records. More...
 
static has_records_for_framework ($frameworkid)
 Checks if any of the competencies of a framework has a user competency record. 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...
 

Public Attributes

const STATUS_IDLE = 0
 Idle status.
 
const STATUS_IN_REVIEW = 2
 In review status.
 
const STATUS_WAITING_FOR_REVIEW = 1
 Waiting for review status.
 
const TABLE = 'competency_usercomp'
 Table name for user_competency persistency.
 

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 the validation. More...
 
 raw_get ($property)
 Internal Data getter. More...
 
 raw_set ($property, $value)
 Data setter. More...
 
 validate_competencyid ($value)
 Validate the competency ID. More...
 
 validate_grade ($value)
 Validate the grade. More...
 
 validate_proficiency ($value)
 Validate the proficiency. More...
 
 validate_reviewerid ($value)
 Validate the reviewer ID. More...
 
 validate_userid ($value)
 Validate the user 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 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...
 

Detailed Description

Class for loading/storing user_competency 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

Hook to execute after a create.

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

Return values
void

Reimplemented in tool_dataprivacy\purpose_override, tool_dataprivacy\purpose, and tool_dataprivacy\contextlevel.

◆ after_delete()

core\persistent::after_delete (   $result)
protectedinherited

Hook to execute after a delete.

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

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

Reimplemented in core_competency\template_competency, core_competency\plan_competency, core_competency\course_module_competency, core_competency\course_competency, core_competency\competency, and tool_policy\policy_version.

◆ after_update()

core\persistent::after_update (   $result)
protectedinherited

Hook to execute after an update.

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

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

Reimplemented in core_competency\template, core_competency\competency, tool_policy\policy_version, tool_dataprivacy\purpose_override, tool_dataprivacy\purpose, and tool_dataprivacy\contextlevel.

◆ 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

◆ 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 tool_dataprivacy\purpose_override, tool_dataprivacy\purpose, and tool_dataprivacy\contextlevel.

◆ 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

◆ before_validate()

core\persistent::before_validate ( )
protectedinherited

Hook to execute before the validation.

This hook will not affect the validation results in any way but is useful to internally set properties which will need to be validated.

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

Return values
void

Reimplemented in core\oauth2\issuer, core_competency\template_competency, core_competency\template, core_competency\plan_competency, core_competency\plan, core_competency\course_module_competency, core_competency\course_competency, core_competency\competency_framework, and core_competency\competency.

◆ can_comment()

core_competency\user_competency::can_comment ( )

Whether the current user can comment on this user competency.

Return values
bool

◆ can_comment_user()

static core_competency\user_competency::can_comment_user (   $userid)
static

Can the current user comment on a user's competency?

Parameters
int$useridThe user ID the competency belongs to.
Return values
bool

◆ can_grade_user()

static core_competency\user_competency::can_grade_user (   $userid)
static

Can the current user grade a user's user competency?

Parameters
int$useridThe user ID the competency belongs to.
Return values
bool

◆ can_grade_user_in_course()

static core_competency\user_competency::can_grade_user_in_course (   $userid,
  $courseid 
)
static

Can the current user grade a user's user competency in a course?

Parameters
int$useridThe user ID the competency belongs to.
int$courseidThe course ID.
Return values
bool

◆ can_read()

core_competency\user_competency::can_read ( )

Whether the current user can read this user competency.

Return values
bool

◆ can_read_comments()

core_competency\user_competency::can_read_comments ( )

Whether the current user can read comments on this user competency.

Return values
bool

◆ can_read_comments_user()

static core_competency\user_competency::can_read_comments_user (   $userid)
static

Can the current user read the comments on a user's competency?

Parameters
int$useridThe user ID the competency belongs to.
Return values
bool

◆ can_read_user()

static core_competency\user_competency::can_read_user (   $userid)
static

Can the current user read a user's competency?

Parameters
int$useridThe user ID the competency belongs to.
Return values
bool

◆ can_read_user_in_course()

static core_competency\user_competency::can_read_user_in_course (   $userid,
  $courseid 
)
static

Can the current user read the user competencies of a user in a course?

Parameters
int$useridThe user ID the competency belongs to.
int$courseidThe course ID.
Return values
bool

◆ can_request_review()

core_competency\user_competency::can_request_review ( )

Can the current user send the user competency for review?

Return values
bool

◆ can_request_review_user()

static core_competency\user_competency::can_request_review_user (   $userid)
static

Can the current user send a user's competency for review?

Note that the status 'review' is not meant to be used for student to self-assess themselves, then to ask the teacher to review their assessment. It is more intended for a student to provide evidence of prior learning and request their review.

Parameters
int$useridThe user ID the competency belongs to.
Return values
bool

◆ can_review()

core_competency\user_competency::can_review ( )

Can the current user review the user competency?

Return values
bool

◆ can_review_user()

static core_competency\user_competency::can_review_user (   $userid)
static

Can the current user review the user competency?

Parameters
int$useridThe user ID the competency belongs to.
Return values
bool

◆ 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

◆ create_relation()

static core_competency\user_competency::create_relation (   $userid,
  $competencyid 
)
static

Create a new user_competency object.

Note, this is intended to be used to create a blank relation, for instance when the record was not found in the database. This does not save the model.

Parameters
int$useridThe user ID.
int$competencyidThe competency ID.
Return values
core_competency

◆ define_properties()

static core_competency\user_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.

◆ 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 } 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_comment_object()

core_competency\user_competency::get_comment_object ( )

Get the comment object.

Return values
comment

◆ get_competency()

core_competency\user_competency::get_competency ( )

Return the competency Object.

Return values
competencyCompetency Object

◆ get_competency_by_usercompetencyid()

static core_competency\user_competency::get_competency_by_usercompetencyid (   $id)
static

Fetch a competency by user competency ID.

This is a convenience method to attempt to efficiently fetch a competency when the only information we have is the user_competency ID, in evidence for instance.

Parameters
int$idThe user competency ID.
Return values
competency

◆ get_context()

core_competency\user_competency::get_context ( )

Get the context.

Return values
contextThe context.

◆ 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_multiple()

static core_competency\user_competency::get_multiple (   $userid,
array  $competenciesorids = null 
)
static

Get multiple user_competency for a user.

Parameters
int$userid
array$competenciesoridsLimit search to those competencies, or competency IDs.
Return values
core_competency

◆ get_plans()

core_competency\user_competency::get_plans ( )

Find the plans for the user and this competency.

Note that this:

  • does not perform any capability check.
  • may return completed plans.
  • may return an empty array.
Return values
plans[]

◆ 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 (   $filters = array())
staticinherited

Load a single record.

Parameters
array$filtersFilters to apply.
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_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.

◆ get_status_list()

static core_competency\user_competency::get_status_list ( )
static

Get list of competency status.

Return values
array

◆ get_status_name()

static core_competency\user_competency::get_status_name (   $status)
static

Human readable status name.

Parameters
int$statusThe status code.
Return values
lang_string

◆ 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_records_for_competencies()

static core_competency\user_competency::has_records_for_competencies (   $competencyids)
static

Check if user competency has records for competencies.

Parameters
array$competencyidsThe competencies ids.
Return values
booleanReturn true if the delete was successfull.

◆ has_records_for_competency()

static core_competency\user_competency::has_records_for_competency (   $competencyid)
static

Checks if a competency has user competency records.

Parameters
int$competencyidThe competency ID
Return values
boolean

◆ has_records_for_framework()

static core_competency\user_competency::has_records_for_framework (   $frameworkid)
static

Checks if any of the competencies of a framework has a user competency record.

Parameters
int$frameworkidThe competency framework ID.
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

◆ 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 } 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 } 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

◆ save()

core\persistent::save ( )
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.

Return values
void

◆ 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 } 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

◆ 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_competencyid()

core_competency\user_competency::validate_competencyid (   $value)
protected

Validate the competency ID.

Parameters
int$valueThe value.
Return values
true|lang_string

◆ validate_grade()

core_competency\user_competency::validate_grade (   $value)
protected

Validate the grade.

Parameters
int$valueThe value.
Return values
true|lang_string

◆ validate_proficiency()

core_competency\user_competency::validate_proficiency (   $value)
protected

Validate the proficiency.

Parameters
int$valueThe value.
Return values
true|lang_string

◆ validate_reviewerid()

core_competency\user_competency::validate_reviewerid (   $value)
protected

Validate the reviewer ID.

Parameters
int$valueThe value.
Return values
true|lang_string

◆ validate_userid()

core_competency\user_competency::validate_userid (   $value)
protected

Validate the user ID.

Parameters
int$valueThe 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: