Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
core_completion

Namespaces

namespace  core_completion
  
 
namespace  core_completion\external
  
 
namespace  core_completion\form
  
 
namespace  core_completion\privacy
  
 

Classes

class  behat_completion
 Steps definitions to deal with course and activities completion. More...
 
class  behat_core_completion_generator
 
class  completion_aggregation
 Course completion critieria aggregation. More...
 
class  completion_completion
 Course completion status for a particular user/course. More...
 
class  completion_criteria
 Completion criteria abstract definition. More...
 
class  completion_criteria_activity
 Course completion critieria - completion on activity completion. More...
 
class  completion_criteria_completion
 Completion data for a specific user, course and critieria. More...
 
class  completion_criteria_course
 Course completion critieria - completion on course completion. More...
 
class  completion_criteria_date
 Course completion critieria - completion on specified date. More...
 
class  completion_criteria_duration
 Course completion critieria - completion after specific duration from course enrolment. More...
 
class  completion_criteria_role
 Course completion critieria - marked by role. More...
 
class  completion_criteria_self
 Course completion critieria - student self marked. More...
 
class  completion_criteria_unenrol
 Course completion critieria - completion on unenrolment. More...
 
class  completion_info
 Class represents completion information for a course. More...
 
class  core_completion\activity_custom_completion
 
class  core_completion\api
 Class containing completion API. More...
 
class  core_completion\cm_completion_details
 Class for building the user's activity completion details. More...
 
class  core_completion\external\completion_info_exporter
 
class  core_completion\manager
 Bulk activity completion manager class. More...
 
class  core_completion\privacy\provider
 Privacy class for requesting user data. More...
 
class  core_completion\progress
 Class used to return completion progress information. More...
 
class  core_completion_bulkedit_form
 
class  core_completion_defaultedit_form
 
class  core_completion_edit_base_form
 
class  core_completion_external
 Completion external functions. More...
 
class  core_completion_generator
 
class  course_completion_form
 Defines the course completion settings form. More...
 
class  data_object
 A data abstraction object that holds methods and attributes. More...
 

Functions

 core_completion\form::add_completion_elements (string $modname=null, bool $supportviews=false, bool $supportgrades=false, bool $rating=false, ?int $courseid=null)
 Add completion elements to the form.
 
 core_completion\form::add_completion_rules ()
 Add completion elements to the form and return the list of element ids.
 
 core_completion\form::add_completiongrade_elements (string $modname, bool $rating=false)
 Add completion grade elements to the form.
 
 core_completion\form::add_completiongrade_rules ()
 Add completion grading elements to the form and return the list of element ids.
 
 aggregate_completions (int $coursecompletionid, bool $mtraceprogress=false)
 Aggregate courses completions.
 
 completion_can_view_data ($userid, $course=null)
 Utility function for checking if the logged in user can view another's completion data for a particular course.
 
 completion_cron_aggregate ($method, $data, &$state)
 Aggregate criteria status's as per configured aggregation method.
 
 core_completion\form::completion_rule_enabled ($data)
 Called during validation.
 
 core_completion\form::definition_after_data_completion (?cm_info $cm=null)
 It should be called from the definition_after_data() to setup the completion settings in the form.
 
 core_completion\form::get_form ()
 Get the form associated to this class, where the completion elements will be added.
 
 core_completion\form::get_suffix ()
 Get the suffix to be added to the completion elements when creating them (for example, 'completion_assign').
 
 core_completion\form::set_suffix (string $suffix)
 Set the suffix to be added to the completion elements when creating them (for example, 'completion_assign').
 
 core_completion\form::validate_completion (array $data)
 Perform some extra validation for completion settings.
 

Variables

global $COMPLETION_CRITERIA_TYPES
 Criteria type constant to class name mapping.
 
const COMPLETION_AGGREGATION_ALL 1
 Course completion criteria aggregation method.
 
const COMPLETION_AGGREGATION_ANY 2
 Course completion criteria aggregation method.
 
const COMPLETION_AND true
 Completion details should be ANDed together and you should return true if none apply.
 
const COMPLETION_COMPLETE 1
 The user has completed this activity.
 
const COMPLETION_COMPLETE_FAIL 3
 The user has completed this activity but their grade is less than the pass mark This is a completion state value (course_modules_completion/completionstate)
 
const COMPLETION_COMPLETE_FAIL_HIDDEN 4
 Indicates that the user has received a failing grade for a hidden grade item.
 
const COMPLETION_COMPLETE_PASS 2
 The user has completed this activity with a grade above the pass mark.
 
const COMPLETION_CRITERIA_TYPE_ACTIVITY 4
 Activity completion criteria type Criteria type constant, primarily for storing criteria type in the database.
 
const COMPLETION_CRITERIA_TYPE_COURSE 8
 Course completion criteria type Criteria type constant, primarily for storing criteria type in the database.
 
const COMPLETION_CRITERIA_TYPE_DATE 2
 Date completion criteria type Criteria type constant, primarily for storing criteria type in the database.
 
const COMPLETION_CRITERIA_TYPE_DURATION 5
 Duration completion criteria type Criteria type constant, primarily for storing criteria type in the database.
 
const COMPLETION_CRITERIA_TYPE_GRADE 6
 Grade completion criteria type Criteria type constant, primarily for storing criteria type in the database.
 
const COMPLETION_CRITERIA_TYPE_ROLE 7
 Role completion criteria type Criteria type constant, primarily for storing criteria type in the database.
 
const COMPLETION_CRITERIA_TYPE_SELF 1
 Self completion criteria type Criteria type constant, primarily for storing criteria type in the database.
 
const COMPLETION_CRITERIA_TYPE_UNENROL 3
 Unenrol completion criteria type Criteria type constant, primarily for storing criteria type in the database.
 
const COMPLETION_DISABLED 0
 The completion system is not enabled in this site/course.
 
const COMPLETION_ENABLED 1
 Include the required completion libraries.
 
const COMPLETION_GRADECHANGE -2
 The user's grade has changed, so their new state might be COMPLETION_COMPLETE_PASS or COMPLETION_COMPLETE_FAIL.
 
const COMPLETION_HIDE_CONDITIONS 0
 Completion conditions will be hidden from user.
 
const COMPLETION_INCOMPLETE 0
 The user has not completed this activity.
 
const COMPLETION_NOT_VIEWED 0
 User has not viewed this activity.
 
const COMPLETION_OR false
 Completion details should be ORed together and you should return false if none apply.
 
const COMPLETION_SHOW_CONDITIONS 1
 Completion conditions will be displayed to user.
 
const COMPLETION_TRACKING_AUTOMATIC 2
 Automatic completion tracking (system ticks box) is enabled for this activity This is a completion tracking option per-activity (course_modules/completion)
 
const COMPLETION_TRACKING_MANUAL 1
 Manual completion tracking (user ticks box) is enabled for this activity This is a completion tracking option per-activity (course_modules/completion)
 
const COMPLETION_TRACKING_NONE 0
 Completion tracking is disabled for this activity This is a completion tracking option per-activity (course_modules/completion)
 
const COMPLETION_UNKNOWN -1
 The effect of this change to completion status is unknown.
 
const COMPLETION_VIEW_NOT_REQUIRED 0
 User does not need to view this activity Whether view is required to create an activity (course_modules/completionview)
 
const COMPLETION_VIEW_REQUIRED 1
 User must view this activity.
 
const COMPLETION_VIEWED 1
 User has viewed this activity.
 
const DATA_OBJECT_FETCH_BY_KEY 2
 Trigger for the new data_object api.
 
trait core_completion\form::form_trait
 

Detailed Description

Function Documentation

◆ add_completion_elements()

core_completion\form\add_completion_elements ( string $modname = null,
bool $supportviews = false,
bool $supportgrades = false,
bool $rating = false,
?int $courseid = null )
protected

Add completion elements to the form.

Parameters
string | null$modnameThe module name (for example, 'assign'). If null and form is moodleform_mod, the parameters are overriden with the expected values from the form.
bool$supportviewsTrue if the module supports views and false otherwise.
bool$supportgradesTrue if the module supports grades and false otherwise.
bool$ratingTrue if the rating feature is enabled and false otherwise.
int | null$courseidCourse where to add completion elements.
Exceptions
coding_exceptionIf the form is not moodleform_mod and $modname is null.

◆ add_completion_rules()

core_completion\form\add_completion_rules ( )
abstractprotected

Add completion elements to the form and return the list of element ids.

Return values
arrayArray of string IDs of added items, empty array if none

◆ add_completiongrade_elements()

core_completion\form\add_completiongrade_elements ( string $modname,
bool $rating = false )
protected

Add completion grade elements to the form.

Parameters
string$modnameThe name of the module (for example, 'assign').
bool$ratingTrue if the rating feature is enabled and false otherwise.

◆ add_completiongrade_rules()

core_completion\form\add_completiongrade_rules ( )
abstract

Add completion grading elements to the form and return the list of element ids.

Return values
arrayArray of string IDs of added items, empty array if none

◆ aggregate_completions()

aggregate_completions ( int $coursecompletionid,
bool $mtraceprogress = false )

Aggregate courses completions.

This function is called when activity completion status is updated for single user. Also when regular completion task runs it aggregates completions for all courses and users.

Parameters
int$coursecompletionidCourse completion ID to update (if 0 - update for all courses and users)
bool$mtraceprogressTo output debug info
Since
Moodle 4.0

◆ completion_can_view_data()

completion_can_view_data ( $userid,
$course = null )

Utility function for checking if the logged in user can view another's completion data for a particular course.

Parameters
int$useridCompletion data's owner
mixed$courseCourse object or Course ID (optional)
Return values
boolean

◆ completion_cron_aggregate()

completion_cron_aggregate ( $method,
$data,
& $state )

Aggregate criteria status's as per configured aggregation method.

Parameters
int$methodCOMPLETION_AGGREGATION_* constant.
bool$dataCriteria completion status.
bool | null$stateAggregation state.

◆ completion_rule_enabled()

core_completion\form\completion_rule_enabled ( $data)
abstractprotected

Called during validation.

Override this method to indicate, based on the data, whether a custom completion rule is selected or not.

Parameters
array$dataInput data (not yet validated)
Return values
boolTrue if one or more rules are enabled; false if none are.

◆ definition_after_data_completion()

core_completion\form\definition_after_data_completion ( ?cm_info $cm = null)
protected

It should be called from the definition_after_data() to setup the completion settings in the form.

Parameters
cm_info | null$cmThe course module associated to this form.

◆ get_form()

core_completion\form\get_form ( )
protected

Get the form associated to this class, where the completion elements will be added.

This method must be overriden by the class using this trait if it doesn't include a _form property.

Return values
MoodleQuickForm
Exceptions
coding_exceptionIf the class does not have a _form property.

◆ get_suffix()

core_completion\form\get_suffix ( )

Get the suffix to be added to the completion elements when creating them (for example, 'completion_assign').

Return values
stringThe suffix

◆ set_suffix()

core_completion\form\set_suffix ( string $suffix)

Set the suffix to be added to the completion elements when creating them (for example, 'completion_assign').

Parameters
string$suffix

◆ validate_completion()

core_completion\form\validate_completion ( array $data)
protected

Perform some extra validation for completion settings.

Parameters
array$dataArray of ["fieldname" => value] of submitted data.
Return values
arrayList of ["element_name" => "error_description"] if there are errors or an empty array if everything is OK.

Variable Documentation

◆ $COMPLETION_CRITERIA_TYPES

$COMPLETION_CRITERIA_TYPES
Initial value:
= array(
)
const COMPLETION_CRITERIA_TYPE_DURATION
Duration completion criteria type Criteria type constant, primarily for storing criteria type in the ...
Definition completion_criteria.php:59
const COMPLETION_CRITERIA_TYPE_SELF
Self completion criteria type Criteria type constant, primarily for storing criteria type in the data...
Definition completion_criteria.php:35
const COMPLETION_CRITERIA_TYPE_ROLE
Role completion criteria type Criteria type constant, primarily for storing criteria type in the data...
Definition completion_criteria.php:71
const COMPLETION_CRITERIA_TYPE_UNENROL
Unenrol completion criteria type Criteria type constant, primarily for storing criteria type in the d...
Definition completion_criteria.php:47
const COMPLETION_CRITERIA_TYPE_DATE
Date completion criteria type Criteria type constant, primarily for storing criteria type in the data...
Definition completion_criteria.php:41
const COMPLETION_CRITERIA_TYPE_COURSE
Course completion criteria type Criteria type constant, primarily for storing criteria type in the da...
Definition completion_criteria.php:77
const COMPLETION_CRITERIA_TYPE_GRADE
Grade completion criteria type Criteria type constant, primarily for storing criteria type in the dat...
Definition completion_criteria.php:65
const COMPLETION_CRITERIA_TYPE_ACTIVITY
Activity completion criteria type Criteria type constant, primarily for storing criteria type in the ...
Definition completion_criteria.php:53

Criteria type constant to class name mapping.

This global variable would be improved if it was implemented as a cache.

◆ COMPLETION_COMPLETE

const COMPLETION_COMPLETE 1

The user has completed this activity.

It is not specified whether they have passed or failed it. This is a completion state value (course_modules_completion/completionstate)

◆ COMPLETION_COMPLETE_PASS

const COMPLETION_COMPLETE_PASS 2

The user has completed this activity with a grade above the pass mark.

This is a completion state value (course_modules_completion/completionstate)

◆ COMPLETION_ENABLED

const COMPLETION_ENABLED 1

Include the required completion libraries.

The completion system is enabled in this site/course

◆ COMPLETION_GRADECHANGE

const COMPLETION_GRADECHANGE -2

The user's grade has changed, so their new state might be COMPLETION_COMPLETE_PASS or COMPLETION_COMPLETE_FAIL.

A completion effect changes (used only in update_state)

◆ COMPLETION_INCOMPLETE

const COMPLETION_INCOMPLETE 0

The user has not completed this activity.

This is a completion state value (course_modules_completion/completionstate)

◆ COMPLETION_NOT_VIEWED

const COMPLETION_NOT_VIEWED 0

User has not viewed this activity.

Completion viewed state (course_modules_completion/viewed)

◆ COMPLETION_UNKNOWN

const COMPLETION_UNKNOWN -1

The effect of this change to completion status is unknown.

A completion effect changes (used only in update_state)

◆ COMPLETION_VIEW_REQUIRED

const COMPLETION_VIEW_REQUIRED 1

User must view this activity.

Whether view is required to create an activity (course_modules/completionview)

◆ COMPLETION_VIEWED

const COMPLETION_VIEWED 1

User has viewed this activity.

Completion viewed state (course_modules_completion/viewed)

◆ DATA_OBJECT_FETCH_BY_KEY

const DATA_OBJECT_FETCH_BY_KEY 2

Trigger for the new data_object api.

See data_object\__constructor

◆ form_trait

trait core_completion::form\form_trait
Initial value:
{
protected string $suffix = ''