Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]

Class for loading/storing competency frameworks from the DB.

Copyright: 2015 Damyon Wiese
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 5388 lines (210 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

api:: (140 methods):
  is_enabled()
  show_links()
  skip_enabled()
  check_enabled()
  require_enabled()
  is_scale_used_anywhere()
  validate_course_module()
  validate_course()
  create_competency()
  delete_competency()
  move_down_competency()
  move_up_competency()
  set_parent_competency()
  update_competency()
  read_competency()
  search_competencies()
  list_competencies()
  count_competencies()
  create_framework()
  duplicate_framework()
  delete_framework()
  update_framework()
  read_framework()
  competency_framework_viewed()
  competency_viewed()
  list_frameworks()
  count_frameworks()
  get_related_contexts()
  count_courses_using_competency()
  list_course_modules_using_competency()
  list_course_module_competencies_in_course_module()
  list_courses_using_competency()
  count_proficient_competencies_in_course_for_user()
  count_competencies_in_course()
  list_course_competencies()
  get_user_competency()
  get_user_competency_by_id()
  count_course_module_competencies()
  list_course_module_competencies()
  get_user_competency_in_course()
  list_user_competencies_in_course()
  list_user_competencies_to_review()
  add_competency_to_course_module()
  remove_competency_from_course_module()
  reorder_course_module_competency()
  set_course_module_competency_ruleoutcome()
  add_competency_to_course()
  remove_competency_from_course()
  reorder_course_competency()
  set_course_competency_ruleoutcome()
  create_template()
  duplicate_template()
  delete_template()
  update_template()
  read_template()
  list_templates()
  count_templates()
  count_templates_using_competency()
  list_templates_using_competency()
  count_competencies_in_template()
  count_competencies_in_template_with_no_courses()
  list_competencies_in_template()
  add_competency_to_template()
  remove_competency_from_template()
  reorder_template_competency()
  create_template_cohort()
  delete_template_cohort()
  list_user_plans()
  list_plans_to_review()
  create_plan()
  create_plan_from_template()
  create_plans_from_template_cohort()
  unlink_plan_from_template()
  update_plan()
  read_plan()
  plan_viewed()
  delete_plan()
  plan_cancel_review_request()
  plan_request_review()
  plan_start_review()
  plan_stop_review()
  approve_plan()
  unapprove_plan()
  complete_plan()
  reopen_plan()
  get_plan_competency()
  list_plans_with_competency()
  list_plan_competencies()
  add_competency_to_plan()
  remove_competency_from_plan()
  reorder_plan_competency()
  user_competency_cancel_review_request()
  user_competency_request_review()
  user_competency_start_review()
  user_competency_stop_review()
  user_competency_viewed()
  user_competency_viewed_in_plan()
  user_competency_viewed_in_course()
  user_competency_plan_viewed()
  template_has_related_data()
  list_related_competencies()
  add_related_competency()
  remove_related_competency()
  read_user_evidence()
  create_user_evidence()
  update_user_evidence()
  delete_user_evidence()
  list_user_evidence()
  create_user_evidence_competency()
  delete_user_evidence_competency()
  request_review_of_user_evidence_linked_competencies()
  duplicate_competency_tree()
  migrate_competency_tree_rules()
  archive_user_competencies_in_plan()
  remove_archived_user_competencies_in_plan()
  list_evidence()
  list_evidence_in_course()
  add_evidence()
  read_evidence()
  delete_evidence()
  apply_competency_rules_from_usercompetency()
  observe_course_module_completion_updated()
  observe_course_completed()
  hook_course_module_deleted()
  hook_course_deleted()
  hook_course_reset_competency_ratings()
  hook_cohort_deleted()
  hook_user_deleted()
  grade_competency()
  grade_competency_in_plan()
  grade_competency_in_course()
  count_plans_for_template()
  count_user_competency_plans_for_template()
  list_plans_for_template()
  get_least_proficient_competencies_for_course()
  get_least_proficient_competencies_for_template()
  template_viewed()
  read_course_competency_settings()
  update_course_competency_settings()
  filter_users_with_capability_on_user_context_sql()


Class: api  - X-Ref

Class for doing things with competency frameworks.

is_enabled()   X-Ref
Returns whether competencies are enabled.

This method should never do more than checking the config setting, the reason
being that some other code could be checking the config value directly
to avoid having to load this entire file into memory.

return: boolean True when enabled.

show_links()   X-Ref
When competencies used to be enabled, we can show the text but do not include links.

return: boolean True means show links.

skip_enabled()   X-Ref
Allow calls to competency api functions even if competencies are not currently enabled.


check_enabled()   X-Ref
Restore the checking that competencies are enabled with any api function.


require_enabled()   X-Ref
Throws an exception if competencies are not enabled.

return: void

is_scale_used_anywhere($scaleid)   X-Ref
Checks whether a scale is used anywhere in the plugin.

This public API has two exceptions:
- It MUST NOT perform any capability checks.
- It MUST ignore whether competencies are enabled or not ({@link self::is_enabled()}).

param: int $scaleid The scale ID.
return: bool

validate_course_module($cmmixed, $throwexception = true)   X-Ref
Validate if current user have acces to the course_module if hidden.

param: mixed $cmmixed The cm_info class, course module record or its ID.
param: bool $throwexception Throw an exception or not.
return: bool

validate_course($courseorid, $throwexception = true)   X-Ref
Validate if current user have acces to the course if hidden.

param: mixed $courseorid The course or it ID.
param: bool $throwexception Throw an exception or not.
return: bool

create_competency(stdClass $record)   X-Ref
Create a competency from a record containing all the data for the class.

Requires moodle/competency:competencymanage capability at the system context.

param: stdClass $record Record containing all the data for an instance of the class.
return: competency

delete_competency($id)   X-Ref
Delete a competency by id.

Requires moodle/competency:competencymanage capability at the system context.

param: int $id The record to delete. This will delete alot of related data - you better be sure.
return: boolean

move_down_competency($id)   X-Ref
Reorder this competency.

Requires moodle/competency:competencymanage capability at the system context.

param: int $id The id of the competency to move.
return: boolean

move_up_competency($id)   X-Ref
Reorder this competency.

Requires moodle/competency:competencymanage capability at the system context.

param: int $id The id of the competency to move.
return: boolean

set_parent_competency($id, $newparentid)   X-Ref
Move this competency so it sits in a new parent.

Requires moodle/competency:competencymanage capability at the system context.

param: int $id The id of the competency to move.
param: int $newparentid The new parent id for the competency.
return: boolean

update_competency($record)   X-Ref
Update the details for a competency.

Requires moodle/competency:competencymanage capability at the system context.

param: stdClass $record The new details for the competency.
return: boolean

read_competency($id, $includerelated = false)   X-Ref
Read a the details for a single competency and return a record.

Requires moodle/competency:competencyview capability at the system context.

param: int $id The id of the competency to read.
param: bool $includerelated Include related tags or not.
return: competency

search_competencies($textsearch, $competencyframeworkid)   X-Ref
Perform a text search based and return all results and their parents.

Requires moodle/competency:competencyview capability at the framework context.

param: string $textsearch A string to search for.
param: int $competencyframeworkid The id of the framework to limit the search.
return: array of competencies

list_competencies($filters, $sort = '', $order = 'ASC', $skip = 0, $limit = 0)   X-Ref
Perform a search based on the provided filters and return a paginated list of records.

Requires moodle/competency:competencyview capability at some context.

param: array $filters A list of filters to apply to the list.
param: string $sort The column to sort on
param: string $order ('ASC' or 'DESC')
param: int $skip Number of records to skip (pagination)
param: int $limit Max of records to return (pagination)
return: array of competencies

count_competencies($filters)   X-Ref
Perform a search based on the provided filters and return a paginated list of records.

Requires moodle/competency:competencyview capability at some context.

param: array $filters A list of filters to apply to the list.
return: int

create_framework(stdClass $record)   X-Ref
Create a competency framework from a record containing all the data for the class.

Requires moodle/competency:competencymanage capability at the system context.

param: stdClass $record Record containing all the data for an instance of the class.
return: competency_framework

duplicate_framework($id)   X-Ref
Duplicate a competency framework by id.

Requires moodle/competency:competencymanage capability at the system context.

param: int $id The record to duplicate. All competencies associated and related will be duplicated.
return: competency_framework the framework duplicated

delete_framework($id)   X-Ref
Delete a competency framework by id.

Requires moodle/competency:competencymanage capability at the system context.

param: int $id The record to delete. This will delete alot of related data - you better be sure.
return: boolean

update_framework($record)   X-Ref
Update the details for a competency framework.

Requires moodle/competency:competencymanage capability at the system context.

param: stdClass $record The new details for the framework. Note - must contain an id that points to the framework to update.
return: boolean

read_framework($id)   X-Ref
Read a the details for a single competency framework and return a record.

Requires moodle/competency:competencyview capability at the system context.

param: int $id The id of the framework to read.
return: competency_framework

competency_framework_viewed($frameworkorid)   X-Ref
Logg the competency framework viewed event.

param: competency_framework|int $frameworkorid The competency_framework object or competency framework id
return: bool

competency_viewed($competencyorid)   X-Ref
Logg the competency viewed event.

param: competency|int $competencyorid The competency object or competency id
return: bool

list_frameworks($sort, $order, $skip, $limit, $context, $includes = 'children',$onlyvisible = false, $query = '')   X-Ref
Perform a search based on the provided filters and return a paginated list of records.

Requires moodle/competency:competencyview capability at the system context.

param: string $sort The column to sort on
param: string $order ('ASC' or 'DESC')
param: int $skip Number of records to skip (pagination)
param: int $limit Max of records to return (pagination)
param: context $context The parent context of the frameworks.
param: string $includes Defines what other contexts to fetch frameworks from.
param: bool $onlyvisible If true return only visible frameworks
param: string $query A string to use to filter down the frameworks.
return: array of competency_framework

count_frameworks($context, $includes)   X-Ref
Perform a search based on the provided filters and return a paginated list of records.

Requires moodle/competency:competencyview capability at the system context.

param: context $context The parent context of the frameworks.
param: string $includes Defines what other contexts to fetch frameworks from.
return: int

get_related_contexts($context, $includes, array $hasanycapability = null)   X-Ref
Fetches all the relevant contexts.

Note: This currently only supports system, category and user contexts. However user contexts
behave a bit differently and will fallback on the system context. This is what makes the most
sense because a user context does not have descendants, and only has system as a parent.

param: context $context The context to start from.
param: string $includes Defines what other contexts to find.
param: array $hasanycapability Array of capabilities passed to {@link has_any_capability()} in each context.
return: context[] An array of contexts where keys are context IDs.

count_courses_using_competency($competencyid)   X-Ref
Count all the courses using a competency.

param: int $competencyid The id of the competency to check.
return: int

list_course_modules_using_competency($competencyid, $courseid)   X-Ref
List all the courses modules using a competency in a course.

param: int $competencyid The id of the competency to check.
param: int $courseid The id of the course to check.
return: array[int] Array of course modules ids.

list_course_module_competencies_in_course_module($cmorid)   X-Ref
List all the competencies linked to a course module.

param: mixed $cmorid The course module, or its ID.
return: array[competency] Array of competency records.

list_courses_using_competency($competencyid)   X-Ref
List all the courses using a competency.

param: int $competencyid The id of the competency to check.
return: array[stdClass] Array of stdClass containing id and shortname.

count_proficient_competencies_in_course_for_user($courseid, $userid)   X-Ref
Count the proficient competencies in a course for one user.

param: int $courseid The id of the course to check.
param: int $userid The id of the user to check.
return: int

count_competencies_in_course($courseid)   X-Ref
Count all the competencies in a course.

param: int $courseid The id of the course to check.
return: int

list_course_competencies($courseorid)   X-Ref
List the competencies associated to a course.

param: mixed $courseorid The course, or its ID.
return: array( array(

get_user_competency($userid, $competencyid)   X-Ref
Get a user competency.

param: int $userid The user ID.
param: int $competencyid The competency ID.
return: user_competency

get_user_competency_by_id($usercompetencyid)   X-Ref
Get a user competency by ID.

param: int $usercompetencyid The user competency ID.
return: user_competency

count_course_module_competencies($cmorid)   X-Ref
Count the competencies associated to a course module.

param: mixed $cmorid The course module, or its ID.
return: int

list_course_module_competencies($cmorid)   X-Ref
List the competencies associated to a course module.

param: mixed $cmorid The course module, or its ID.
return: array( array(

get_user_competency_in_course($courseid, $userid, $competencyid)   X-Ref
Get a user competency in a course.

param: int $courseid The id of the course to check.
param: int $userid The id of the course to check.
param: int $competencyid The id of the competency.
return: user_competency_course

list_user_competencies_in_course($courseid, $userid)   X-Ref
List all the user competencies in a course.

param: int $courseid The id of the course to check.
param: int $userid The id of the course to check.
return: array of user_competency_course objects

list_user_competencies_to_review($skip = 0, $limit = 50, $userid = null)   X-Ref
List the user competencies to review.

The method returns values in this format:

array(
'competencies' => array(
(stdClass)(
'usercompetency' => (user_competency),
'competency' => (competency),
'user' => (user)
)
),
'count' => (int)
)

param: int $skip The number of records to skip.
param: int $limit The number of results to return.
param: int $userid The user we're getting the competencies to review for.
return: array Containing the keys 'count', and 'competencies'. The 'competencies' key contains an object

add_competency_to_course_module($cmorid, $competencyid)   X-Ref
Add a competency to this course module.

param: mixed $cmorid The course module, or id of the course module
param: int $competencyid The id of the competency
return: bool

remove_competency_from_course_module($cmorid, $competencyid)   X-Ref
Remove a competency from this course module.

param: mixed $cmorid The course module, or id of the course module
param: int $competencyid The id of the competency
return: bool

reorder_course_module_competency($cmorid, $competencyidfrom, $competencyidto)   X-Ref
Move the course module competency up or down in the display list.

Requires moodle/competency:coursecompetencymanage capability at the course module context.

param: mixed $cmorid The course module, or id of the course module
param: int $competencyidfrom The id of the competency we are moving.
param: int $competencyidto The id of the competency we are moving to.
return: boolean

set_course_module_competency_ruleoutcome($coursemodulecompetencyorid, $ruleoutcome,$overridegrade = false)   X-Ref
Update ruleoutcome value for a course module competency.

param: int|course_module_competency $coursemodulecompetencyorid The course_module_competency, or its ID.
param: int $ruleoutcome The value of ruleoutcome.
param: bool $overridegrade If true, will override existing grades in related competencies.
return: bool True on success.

add_competency_to_course($courseid, $competencyid)   X-Ref
Add a competency to this course.

param: int $courseid The id of the course
param: int $competencyid The id of the competency
return: bool

remove_competency_from_course($courseid, $competencyid)   X-Ref
Remove a competency from this course.

param: int $courseid The id of the course
param: int $competencyid The id of the competency
return: bool

reorder_course_competency($courseid, $competencyidfrom, $competencyidto)   X-Ref
Move the course competency up or down in the display list.

Requires moodle/competency:coursecompetencymanage capability at the course context.

param: int $courseid The course
param: int $competencyidfrom The id of the competency we are moving.
param: int $competencyidto The id of the competency we are moving to.
return: boolean

set_course_competency_ruleoutcome($coursecompetencyorid, $ruleoutcome)   X-Ref
Update ruleoutcome value for a course competency.

param: int|course_competency $coursecompetencyorid The course_competency, or its ID.
param: int $ruleoutcome The value of ruleoutcome.
return: bool True on success.

create_template(stdClass $record)   X-Ref
Create a learning plan template from a record containing all the data for the class.

Requires moodle/competency:templatemanage capability.

param: stdClass $record Record containing all the data for an instance of the class.
return: template

duplicate_template($id)   X-Ref
Duplicate a learning plan template.

Requires moodle/competency:templatemanage capability at the template context.

param: int $id the template id.
return: template

delete_template($id, $deleteplans = true)   X-Ref
Delete a learning plan template by id.
If the learning plan template has associated cohorts they will be deleted.

Requires moodle/competency:templatemanage capability.

param: int $id The record to delete.
param: boolean $deleteplans True to delete plans associaated to template, false to unlink them.
return: boolean

update_template($record)   X-Ref
Update the details for a learning plan template.

Requires moodle/competency:templatemanage capability.

param: stdClass $record The new details for the template. Note - must contain an id that points to the template to update.
return: boolean

read_template($id)   X-Ref
Read a the details for a single learning plan template and return a record.

Requires moodle/competency:templateview capability at the system context.

param: int $id The id of the template to read.
return: template

list_templates($sort, $order, $skip, $limit, $context, $includes = 'children', $onlyvisible = false)   X-Ref
Perform a search based on the provided filters and return a paginated list of records.

Requires moodle/competency:templateview capability at the system context.

param: string $sort The column to sort on
param: string $order ('ASC' or 'DESC')
param: int $skip Number of records to skip (pagination)
param: int $limit Max of records to return (pagination)
param: context $context The parent context of the frameworks.
param: string $includes Defines what other contexts to fetch frameworks from.
param: bool $onlyvisible If should list only visible templates
return: array of competency_framework

count_templates($context, $includes)   X-Ref
Perform a search based on the provided filters and return how many results there are.

Requires moodle/competency:templateview capability at the system context.

param: context $context The parent context of the frameworks.
param: string $includes Defines what other contexts to fetch frameworks from.
return: int

count_templates_using_competency($competencyid)   X-Ref
Count all the templates using a competency.

param: int $competencyid The id of the competency to check.
return: int

list_templates_using_competency($competencyid)   X-Ref
List all the learning plan templatesd using a competency.

param: int $competencyid The id of the competency to check.
return: array[stdClass] Array of stdClass containing id and shortname.

count_competencies_in_template($templateorid)   X-Ref
Count all the competencies in a learning plan template.

param: template|int $templateorid The template or its ID.
return: int

count_competencies_in_template_with_no_courses($templateorid)   X-Ref
Count all the competencies in a learning plan template with no linked courses.

param: template|int $templateorid The template or its ID.
return: int

list_competencies_in_template($templateorid)   X-Ref
List all the competencies in a template.

param: template|int $templateorid The template or its ID.
return: array of competencies

add_competency_to_template($templateid, $competencyid)   X-Ref
Add a competency to this template.

param: int $templateid The id of the template
param: int $competencyid The id of the competency
return: bool

remove_competency_from_template($templateid, $competencyid)   X-Ref
Remove a competency from this template.

param: int $templateid The id of the template
param: int $competencyid The id of the competency
return: bool

reorder_template_competency($templateid, $competencyidfrom, $competencyidto)   X-Ref
Move the template competency up or down in the display list.

Requires moodle/competency:templatemanage capability at the system context.

param: int $templateid The template id
param: int $competencyidfrom The id of the competency we are moving.
param: int $competencyidto The id of the competency we are moving to.
return: boolean

create_template_cohort($templateorid, $cohortorid)   X-Ref
Create a relation between a template and a cohort.

This silently ignores when the relation already existed.

param: template|int $templateorid The template or its ID.
param: stdClass|int $cohortorid   The cohort ot its ID.
return: template_cohort

delete_template_cohort($templateorid, $cohortorid)   X-Ref
Remove a relation between a template and a cohort.

param: template|int $templateorid The template or its ID.
param: stdClass|int $cohortorid   The cohort ot its ID.
return: boolean True on success or when the relation did not exist.

list_user_plans($userid)   X-Ref
Lists user plans.

param: int $userid
return: \core_competency\plan[]

list_plans_to_review($skip = 0, $limit = 100, $userid = null)   X-Ref
List the plans to review.

The method returns values in this format:

array(
'plans' => array(
(stdClass)(
'plan' => (plan),
'template' => (template),
'owner' => (stdClass)
)
),
'count' => (int)
)

param: int $skip The number of records to skip.
param: int $limit The number of results to return.
param: int $userid The user we're getting the plans to review for.
return: array Containing the keys 'count', and 'plans'. The 'plans' key contains an object

create_plan(stdClass $record)   X-Ref
Creates a learning plan based on the provided data.

param: stdClass $record
return: \core_competency\plan

create_plan_from_template($templateorid, $userid)   X-Ref
Create a learning plan from a template.

param: mixed $templateorid The template object or ID.
param: int $userid
return: false|\core_competency\plan Returns false when the plan already exists.

create_plans_from_template_cohort($templateorid, $cohortid, $recreateunlinked = false)   X-Ref
Create learning plans from a template and cohort.

param: mixed $templateorid The template object or ID.
param: int $cohortid The cohort ID.
param: bool $recreateunlinked When true the plans that were unlinked from this template will be re-created.
return: int The number of plans created.

unlink_plan_from_template($planorid)   X-Ref
Unlink a plan from its template.

param: \core_competency\plan|int $planorid The plan or its ID.
return: bool

update_plan(stdClass $record)   X-Ref
Updates a plan.

param: stdClass $record
return: \core_competency\plan

read_plan($id)   X-Ref
Returns a plan data.

param: int $id
return: \core_competency\plan

plan_viewed($planorid)   X-Ref
Plan event viewed.

param: mixed $planorid The id or the plan.
return: boolean

delete_plan($id)   X-Ref
Deletes a plan.

Plans based on a template can be removed just like any other one.

param: int $id
return: bool Success?

plan_cancel_review_request($planorid)   X-Ref
Cancel the review of a plan.

param: int|plan $planorid The plan, or its ID.
return: bool

plan_request_review($planorid)   X-Ref
Request the review of a plan.

param: int|plan $planorid The plan, or its ID.
return: bool

plan_start_review($planorid)   X-Ref
Start the review of a plan.

param: int|plan $planorid The plan, or its ID.
return: bool

plan_stop_review($planorid)   X-Ref
Stop reviewing a plan.

param: int|plan $planorid The plan, or its ID.
return: bool

approve_plan($planorid)   X-Ref
Approve a plan.

This means making the plan active.

param: int|plan $planorid The plan, or its ID.
return: bool

unapprove_plan($planorid)   X-Ref
Unapprove a plan.

This means making the plan draft.

param: int|plan $planorid The plan, or its ID.
return: bool

complete_plan($planorid)   X-Ref
Complete a plan.

param: int|plan $planorid The plan, or its ID.
return: bool

reopen_plan($planorid)   X-Ref
Reopen a plan.

param: int|plan $planorid The plan, or its ID.
return: bool

get_plan_competency($planorid, $competencyid)   X-Ref
Get a single competency from the user plan.

param: int $planorid The plan, or its ID.
param: int $competencyid The competency id.
return: (object) array(

list_plans_with_competency($userid, $competencyorid)   X-Ref
List the plans with a competency.

param: int $userid The user id we want the plans for.
param: int $competencyorid The competency, or its ID.
return: array[plan] Array of learning plans.

list_plan_competencies($planorid)   X-Ref
List the competencies in a user plan.

param: int $planorid The plan, or its ID.
return: array((object) array(

add_competency_to_plan($planid, $competencyid)   X-Ref
Add a competency to a plan.

param: int $planid The id of the plan
param: int $competencyid The id of the competency
return: bool

remove_competency_from_plan($planid, $competencyid)   X-Ref
Remove a competency from a plan.

param: int $planid The plan id
param: int $competencyid The id of the competency
return: bool

reorder_plan_competency($planid, $competencyidfrom, $competencyidto)   X-Ref
Move the plan competency up or down in the display list.

Requires moodle/competency:planmanage capability at the system context.

param: int $planid The plan  id
param: int $competencyidfrom The id of the competency we are moving.
param: int $competencyidto The id of the competency we are moving to.
return: boolean

user_competency_cancel_review_request($userid, $competencyid)   X-Ref
Cancel a user competency review request.

param: int $userid       The user ID.
param: int $competencyid The competency ID.
return: bool

user_competency_request_review($userid, $competencyid)   X-Ref
Request a user competency review.

param: int $userid       The user ID.
param: int $competencyid The competency ID.
return: bool

user_competency_start_review($userid, $competencyid)   X-Ref
Start a user competency review.

param: int $userid       The user ID.
param: int $competencyid The competency ID.
return: bool

user_competency_stop_review($userid, $competencyid)   X-Ref
Stop a user competency review.

param: int $userid       The user ID.
param: int $competencyid The competency ID.
return: bool

user_competency_viewed($usercompetencyorid)   X-Ref
Log user competency viewed event.

param: user_competency|int $usercompetencyorid The user competency object or user competency id
return: bool

user_competency_viewed_in_plan($usercompetencyorid, $planid)   X-Ref
Log user competency viewed in plan event.

param: user_competency|int $usercompetencyorid The user competency object or user competency id
param: int $planid The plan ID
return: bool

user_competency_viewed_in_course($usercoursecompetencyorid)   X-Ref
Log user competency viewed in course event.

param: user_competency_course|int $usercoursecompetencyorid The user competency course object or its ID.
param: int $courseid The course ID
return: bool

user_competency_plan_viewed($usercompetencyplanorid)   X-Ref
Log user competency plan viewed event.

param: user_competency_plan|int $usercompetencyplanorid The user competency plan object or user competency plan id
return: bool

template_has_related_data($templateid)   X-Ref
Check if template has related data.

param: int $templateid The id of the template to check.
return: boolean

list_related_competencies($competencyid)   X-Ref
List all the related competencies.

param: int $competencyid The id of the competency to check.
return: competency[]

add_related_competency($competencyid, $relatedcompetencyid)   X-Ref
Add a related competency.

param: int $competencyid The id of the competency
param: int $relatedcompetencyid The id of the related competency.
return: bool False when create failed, true on success, or if the relation already existed.

remove_related_competency($competencyid, $relatedcompetencyid)   X-Ref
Remove a related competency.

param: int $competencyid The id of the competency.
param: int $relatedcompetencyid The id of the related competency.
return: bool True when it was deleted, false when it wasn't or the relation doesn't exist.

read_user_evidence($id)   X-Ref
Read a user evidence.

param: int $id
return: user_evidence

create_user_evidence($data, $draftitemid = null)   X-Ref
Create a new user evidence.

param: object $data        The data.
param: int    $draftitemid The draft ID in which files have been saved.
return: user_evidence

update_user_evidence($data, $draftitemid = null)   X-Ref
Create a new user evidence.

param: object $data        The data.
param: int    $draftitemid The draft ID in which files have been saved.
return: user_evidence

delete_user_evidence($id)   X-Ref
Delete a user evidence.

param: int $id The user evidence ID.
return: bool

list_user_evidence($userid)   X-Ref
List the user evidence of a user.

param: int $userid The user ID.
return: user_evidence[]

create_user_evidence_competency($userevidenceorid, $competencyid)   X-Ref
Link a user evidence with a competency.

param: user_evidence|int $userevidenceorid User evidence or its ID.
param: int $competencyid Competency ID.
return: user_evidence_competency

delete_user_evidence_competency($userevidenceorid, $competencyid)   X-Ref
Delete a relationship between a user evidence and a competency.

param: user_evidence|int $userevidenceorid User evidence or its ID.
param: int $competencyid Competency ID.
return: bool

request_review_of_user_evidence_linked_competencies($id)   X-Ref
Send request review for user evidence competencies.

param: int $id The user evidence ID.
return: bool

duplicate_competency_tree($frameworkid, $tree, $oldparent = 0, $newparent = 0)   X-Ref
Recursively duplicate competencies from a tree, we start duplicating from parents to children to have a correct path.
This method does not copy the related competencies.

param: int $frameworkid - framework id
param: stdClass[] $tree - list of framework competency nodes
param: int $oldparent - old parent id
param: int $newparent - new parent id
return: competency[] $matchids - List of old competencies ids matched with new competencies object.

migrate_competency_tree_rules($tree, $matchids)   X-Ref
Recursively migrate competency rules.

param: array $tree - array of competencies object
param: competency[] $matchids - List of old competencies ids matched with new competencies object

archive_user_competencies_in_plan($plan)   X-Ref
Archive user competencies in a plan.

param: plan $plan The plan object.
return: void

remove_archived_user_competencies_in_plan($plan)   X-Ref
Delete archived user competencies in a plan.

param: plan $plan The plan object.
return: void

list_evidence($userid = 0, $competencyid = 0, $planid = 0, $sort = 'timecreated',$order = 'DESC', $skip = 0, $limit = 0)   X-Ref
List all the evidence for a user competency.

param: int $userid The user id - only used if usercompetencyid is 0.
param: int $competencyid The competency id - only used it usercompetencyid is 0.
param: int $planid The plan id - not used yet - but can be used to only list archived evidence if a plan is completed.
param: string $sort The field to sort the evidence by.
param: string $order The ordering of the sorting.
param: int $skip Number of records to skip.
param: int $limit Number of records to return.
return: \core_competency\evidence[]
return: array of \core_competency\evidence

list_evidence_in_course($userid = 0, $courseid = 0, $competencyid = 0, $sort = 'timecreated',$order = 'DESC', $skip = 0, $limit = 0)   X-Ref
List all the evidence for a user competency in a course.

param: int $userid The user ID.
param: int $courseid The course ID.
param: int $competencyid The competency ID.
param: string $sort The field to sort the evidence by.
param: string $order The ordering of the sorting.
param: int $skip Number of records to skip.
param: int $limit Number of records to return.
return: \core_competency\evidence[]

add_evidence($userid, $competencyorid, $contextorid, $action, $descidentifier, $desccomponent,$desca = null, $recommend = false, $url = null, $grade = null, $actionuserid = null,$note = null, $overridegrade = false)   X-Ref
Create an evidence from a list of parameters.

Requires no capability because evidence can be added in many situations under any user.

param: int $userid The user id for which evidence is added.
param: competency|int $competencyorid The competency, or its id for which evidence is added.
param: context|int $contextorid The context in which the evidence took place.
param: int $action The type of action to take on the competency. \core_competency\evidence::ACTION_*.
param: string $descidentifier The strings identifier.
param: string $desccomponent The strings component.
param: mixed $desca Any arguments the string requires.
param: bool $recommend When true, the user competency will be sent for review.
param: string $url The url the evidence may link to.
param: int $grade The grade, or scale ID item.
param: int $actionuserid The ID of the user who took the action of adding the evidence. Null when system.
param: string $note A note to attach to the evidence.
return: evidence

read_evidence($evidenceid)   X-Ref
Read an evidence.

param: int $evidenceid The evidence ID.
return: evidence

delete_evidence($evidenceorid)   X-Ref
Delete an evidence.

param: evidence|int $evidenceorid The evidence, or its ID.
return: bool

apply_competency_rules_from_usercompetency(user_competency $usercompetency,competency $competency = null, $overridegrade = false)   X-Ref
Apply the competency rules from a user competency.

The user competency passed should be one that was recently marked as complete.
A user competency is considered 'complete' when it's proficiency value is true.

This method will check if the parent of this usercompetency's competency has any
rules and if so will see if they match. When matched it will take the required
step to add evidence and trigger completion, etc...

param: user_competency $usercompetency The user competency recently completed.
param: competency|null $competency     The competency of the user competency, useful to avoid unnecessary read.
return: void

observe_course_module_completion_updated(\core\event\course_module_completion_updated $event)   X-Ref
Observe when a course module is marked as completed.

Note that the user being logged in while this happens may be anyone.
Do not rely on capability checks here!

param: \core\event\course_module_completion_updated $event
return: void

observe_course_completed(\core\event\course_completed $event)   X-Ref
Observe when a course is marked as completed.

Note that the user being logged in while this happens may be anyone.
Do not rely on capability checks here!

param: \core\event\course_completed $event
return: void

hook_course_module_deleted(stdClass $cm)   X-Ref
Action to perform when a course module is deleted.

Do not call this directly, this is reserved for core use.

param: stdClass $cm The CM object.
return: void

hook_course_deleted(stdClass $course)   X-Ref
Action to perform when a course is deleted.

Do not call this directly, this is reserved for core use.

param: stdClass $course The course object.
return: void

hook_course_reset_competency_ratings($courseid)   X-Ref
Action to perform when a course is being reset.

Do not call this directly, this is reserved for core use.

param: int $courseid The course ID.
return: void

hook_cohort_deleted(\stdClass $cohort)   X-Ref
Action to perform when a cohort is deleted.

Do not call this directly, this is reserved for core use.

param: \stdClass $cohort The cohort object.
return: void

hook_user_deleted($userid)   X-Ref
Action to perform when a user is deleted.

param: int $userid The user id.

grade_competency($userid, $competencyid, $grade, $note = null)   X-Ref
Manually grade a user competency.

param: int $userid
param: int $competencyid
param: int $grade
param: string $note A note to attach to the evidence
return: array of \core_competency\user_competency

grade_competency_in_plan($planorid, $competencyid, $grade, $note = null)   X-Ref
Manually grade a user competency from the plans page.

param: mixed $planorid
param: int $competencyid
param: int $grade
param: string $note A note to attach to the evidence
return: array of \core_competency\user_competency

grade_competency_in_course($courseorid, $userid, $competencyid, $grade, $note = null)   X-Ref
Manually grade a user course competency from the course page.

This may push the rating to the user competency
if the course is configured this way.

param: mixed $courseorid
param: int $userid
param: int $competencyid
param: int $grade
param: string $note A note to attach to the evidence
return: array of \core_competency\user_competency

count_plans_for_template($templateorid, $status = 0)   X-Ref
Count the plans in the template, filtered by status.

Requires moodle/competency:templateview capability at the system context.

param: mixed $templateorid The id or the template.
param: int $status One of the plan status constants (or 0 for all plans).
return: int

count_user_competency_plans_for_template($templateorid, $proficiency = null)   X-Ref
Count the user-completency-plans in the template, optionally filtered by proficiency.

Requires moodle/competency:templateview capability at the system context.

param: mixed $templateorid The id or the template.
param: mixed $proficiency If true, filter by proficiency, if false filter by not proficient, if null - no filter.
return: int

list_plans_for_template($templateorid, $status = 0, $skip = 0, $limit = 100)   X-Ref
List the plans in the template, filtered by status.

Requires moodle/competency:templateview capability at the system context.

param: mixed $templateorid The id or the template.
param: int $status One of the plan status constants (or 0 for all plans).
param: int $skip The number of records to skip
param: int $limit The max number of records to return
return: plan[]

get_least_proficient_competencies_for_course($courseid, $skip = 0, $limit = 100)   X-Ref
Get the most often not completed competency for this course.

Requires moodle/competency:coursecompetencyview capability at the course context.

param: int $courseid The course id
param: int $skip The number of records to skip
param: int $limit The max number of records to return
return: competency[]

get_least_proficient_competencies_for_template($templateorid, $skip = 0, $limit = 100)   X-Ref
Get the most often not completed competency for this template.

Requires moodle/competency:templateview capability at the system context.

param: mixed $templateorid The id or the template.
param: int $skip The number of records to skip
param: int $limit The max number of records to return
return: competency[]

template_viewed($templateorid)   X-Ref
Template event viewed.

Requires moodle/competency:templateview capability at the system context.

param: mixed $templateorid The id or the template.
return: boolean

read_course_competency_settings($courseid)   X-Ref
Get the competency settings for a course.

Requires moodle/competency:coursecompetencyview capability at the course context.

param: int $courseid The course id
return: course_competency_settings

update_course_competency_settings($courseid, $settings)   X-Ref
Update the competency settings for a course.

Requires moodle/competency:coursecompetencyconfigure capability at the course context.

param: int $courseid The course id
param: stdClass $settings List of settings. The only valid setting ATM is pushratginstouserplans (boolean).
return: bool

filter_users_with_capability_on_user_context_sql($capability, $userid = 0, $type = SQL_PARAMS_QM,$prefix='param')   X-Ref
Function used to return a list of users where the given user has a particular capability.

This is used e.g. to find all the users where someone is able to manage their learning plans,
it also would be useful for mentees etc.

param: string $capability - The capability string we are filtering for. If '' is passed,
param: int $userid - The user id we are using for the access checks. Defaults to current user.
param: int $type - The type of named params to return (passed to $DB->get_in_or_equal).
param: string $prefix - The type prefix for the db table (passed to $DB->get_in_or_equal).
return: list($sql, $params) Same as $DB->get_in_or_equal().