MDL-58190 completion: callbacks to get completion rule descriptions

- Activities can have their custom completion rules added to cm_info
through the get_coursemodule_info callback.
- Descriptions of a modules active completion rules can be fetched using
the component callback mod_xxx_get_completion_active_rule_descriptions
which takes in a cm_info object and returns an array of strings.

Part of MDL-58138 epic
This commit is contained in:
Jake Dallimore 2017-03-07 17:34:26 +08:00
parent 6d14355ce8
commit b54bcddda4
16 changed files with 598 additions and 2 deletions

View File

@ -68,6 +68,7 @@ $string['completiondisabled'] = 'Disabled, not shown in activity settings';
$string['completionenabled'] = 'Enabled, control via completion and activity settings';
$string['completionexpected'] = 'Expect completed on';
$string['completionexpected_help'] = 'This setting specifies the date when the activity is expected to be completed.';
$string['completionexpecteddesc'] = 'Completion expected on {$a}';
$string['completionexpectedfor'] = 'Expected completion for \'{$a->modulename}\' activity \'{$a->instancename}\'';
$string['completionicons'] = 'Completion tick boxes';
$string['completionicons_help'] = 'A tick next to an activity name may be used to indicate when the activity is complete.

View File

@ -2049,6 +2049,34 @@ class cm_info implements IteratorAggregate {
$this->call_mod_function('cm_info_view');
$this->state = self::STATE_VIEW;
}
/**
* Get the descriptions for all active conditional completion rules for the current module.
*
* @return array $activeruledescriptions an array of strings describing the active completion rules.
*/
public function get_completion_active_rule_descriptions() {
$activeruledescriptions = [];
// Generate the description strings for the core conditional completion rules (if set).
if (!empty($this->completionview)) {
$activeruledescriptions[] = get_string('completionview_desc', 'core_completion');
}
if (!empty($this->completionexpected)) {
$activeruledescriptions[] = get_string('completionexpecteddesc', 'core_completion',
userdate($this->completionexpected));
}
if (!is_null($this->completiongradeitemnumber)) {
$activeruledescriptions[] = get_string('completionusegrade_desc', 'core_completion');
}
// Now, ask the module to provide descriptions for its custom conditional completion rules.
if ($customruledescriptions = component_callback($this->modname, 'get_completion_active_rule_descriptions', [$this])) {
$activeruledescriptions = array_merge($activeruledescriptions, $customruledescriptions);
}
return $activeruledescriptions;
}
}

View File

@ -456,7 +456,7 @@ function assign_get_coursemodule_info($coursemodule) {
global $CFG, $DB;
$dbparams = array('id'=>$coursemodule->instance);
$fields = 'id, name, alwaysshowdescription, allowsubmissionsfromdate, intro, introformat';
$fields = 'id, name, alwaysshowdescription, allowsubmissionsfromdate, intro, introformat, completionsubmit';
if (! $assignment = $DB->get_record('assign', $dbparams, $fields)) {
return false;
}
@ -469,9 +469,44 @@ function assign_get_coursemodule_info($coursemodule) {
$result->content = format_module_intro('assign', $assignment, $coursemodule->id, false);
}
}
// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$result->customdata['customcompletionrules']['completionsubmit'] = $assignment->completionsubmit;
}
return $result;
}
/**
* Callback which returns human-readable strings describing the active completion custom rules for the module instance.
*
* @param object $cm the cm_info object.
* @return array $descriptions the array of descriptions for the custom rules.
*/
function mod_assign_get_completion_active_rule_descriptions($cm) {
// Values will be present in cm_info, and we assume these are up to date.
if (!$cm instanceof cm_info || !isset($cm->customdata['customcompletionrules'])
|| $cm->completion != COMPLETION_TRACKING_AUTOMATIC) {
return [];
}
$descriptions = [];
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionsubmit':
if (empty($val)) {
continue;
}
$descriptions[] = get_string('completionsubmit', 'assign');
break;
default:
break;
}
}
return $descriptions;
}
/**
* Return a list of page types
* @param string $pagetype current page type

View File

@ -1226,3 +1226,62 @@ function mod_choice_get_fontawesome_icon_map() {
'mod_choice:column' => 'fa-columns',
];
}
/**
* Add a get_coursemodule_info function in case any choice type wants to add 'extra' information
* for the course (see resource).
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param stdClass $coursemodule The coursemodule object (record).
* @return cached_cm_info An object on information that the courses
* will know about (most noticeably, an icon).
*/
function choice_get_coursemodule_info($coursemodule) {
global $DB;
$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, completionsubmit';
if (!$choice = $DB->get_record('choice', $dbparams, $fields)) {
return false;
}
$result = new cached_cm_info();
// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$result->customdata['customcompletionrules']['completionsubmit'] = $choice->completionsubmit;
}
return $result;
}
/**
* Callback which returns human-readable strings describing the active completion custom rules for the module instance.
*
* @param object $cm the cm_info object.
* @return array $descriptions the array of descriptions for the custom rules.
*/
function mod_choice_get_completion_active_rule_descriptions($cm) {
// Values will be present in cm_info, and we assume these are up to date.
if (!$cm instanceof cm_info || !isset($cm->customdata['customcompletionrules'])
|| $cm->completion != COMPLETION_TRACKING_AUTOMATIC) {
return [];
}
$descriptions = [];
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionsubmit':
if (empty($val)) {
continue;
}
$descriptions[] = get_string('completionsubmit', 'choice');
break;
default:
break;
}
}
return $descriptions;
}

View File

@ -3454,3 +3454,61 @@ function mod_feedback_core_calendar_provide_event_action(calendar_event $event,
);
}
/**
* Add a get_coursemodule_info function in case any feedback type wants to add 'extra' information
* for the course (see resource).
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param stdClass $coursemodule The coursemodule object (record).
* @return cached_cm_info An object on information that the courses
* will know about (most noticeably, an icon).
*/
function feedback_get_coursemodule_info($coursemodule) {
global $DB;
$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, completionsubmit';
if (!$feedback = $DB->get_record('feedback', $dbparams, $fields)) {
return false;
}
$result = new cached_cm_info();
// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$result->customdata['customcompletionrules']['completionsubmit'] = $feedback->completionsubmit;
}
return $result;
}
/**
* Callback which returns human-readable strings describing the active completion custom rules for the module instance.
*
* @param object $cm the cm_info object.
* @return array $descriptions the array of descriptions for the custom rules.
*/
function mod_feedback_get_completion_active_rule_descriptions($cm) {
// Values will be present in cm_info, and we assume these are up to date.
if (!$cm instanceof cm_info || !isset($cm->customdata['customcompletionrules'])
|| $cm->completion != COMPLETION_TRACKING_AUTOMATIC) {
return [];
}
$descriptions = [];
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionsubmit':
if (empty($val)) {
continue;
}
$descriptions[] = get_string('completionsubmit', 'feedback');
break;
default:
break;
}
}
return $descriptions;
}

View File

@ -82,12 +82,15 @@ $string['cleanreadtime'] = 'Mark old posts as read hour';
$string['clicktounsubscribe'] = 'You are subscribed to this discussion. Click to unsubscribe.';
$string['clicktosubscribe'] = 'You are not subscribed to this discussion. Click to subscribe.';
$string['completiondiscussions'] = 'Student must create discussions:';
$string['completiondiscussionsdesc'] = 'Student must create at least {$a} discussion(s)';
$string['completiondiscussionsgroup'] = 'Require discussions';
$string['completiondiscussionshelp'] = 'requiring discussions to complete';
$string['completionposts'] = 'Student must post discussions or replies:';
$string['completionpostsdesc'] = 'Student must post at least {$a} discussion(s) or reply(s)';
$string['completionpostsgroup'] = 'Require posts';
$string['completionpostshelp'] = 'requiring discussions or replies to complete';
$string['completionreplies'] = 'Student must post replies:';
$string['completionrepliesdesc'] = 'Student must post at least {$a} reply(s)';
$string['completionrepliesgroup'] = 'Require replies';
$string['completionreplieshelp'] = 'requiring replies to complete';
$string['configcleanreadtime'] = 'The hour of the day to clean old posts from the \'read\' table.';

View File

@ -8180,6 +8180,7 @@ function mod_forum_get_fontawesome_icon_map() {
}
/**
<<<<<<< HEAD
* Callback function that determines whether an action event should be showing its item count
* based on the event type and the item count.
*
@ -8228,3 +8229,76 @@ function mod_forum_core_calendar_provide_event_action(calendar_event $event,
true
);
}
/**
* Add a get_coursemodule_info function in case any forum type wants to add 'extra' information
* for the course (see resource).
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param stdClass $coursemodule The coursemodule object (record).
* @return cached_cm_info An object on information that the courses
* will know about (most noticeably, an icon).
*/
function forum_get_coursemodule_info($coursemodule) {
global $DB;
$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, completionposts, completiondiscussions, completionreplies';
if (!$forum = $DB->get_record('forum', $dbparams, $fields)) {
return false;
}
$result = new cached_cm_info();
// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$result->customdata['customcompletionrules']['completiondiscussions'] = $forum->completiondiscussions;
$result->customdata['customcompletionrules']['completionreplies'] = $forum->completionreplies;
$result->customdata['customcompletionrules']['completionposts'] = $forum->completionposts;
}
return $result;
}
/**
* Callback which returns human-readable strings describing the active completion custom rules for the module instance.
*
* @param object $cm the cm_info object.
* @return array $descriptions the array of descriptions for the custom rules.
*/
function mod_forum_get_completion_active_rule_descriptions($cm) {
// Values will be present in cm_info, and we assume these are up to date.
if (!$cm instanceof cm_info || !isset($cm->customdata['customcompletionrules'])
|| $cm->completion != COMPLETION_TRACKING_AUTOMATIC) {
return [];
}
$descriptions = [];
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completiondiscussions':
if (empty($val)) {
continue;
}
$descriptions[] = get_string('completiondiscussionsdesc', 'forum', $val);
break;
case 'completionreplies':
if (empty($val)) {
continue;
}
$descriptions[] = get_string('completionrepliesdesc', 'forum', $val);
break;
case 'completionposts':
if (empty($val)) {
continue;
}
$descriptions[] = get_string('completionpostsdesc', 'forum', $val);
break;
default:
break;
}
}
return $descriptions;
}

View File

@ -87,6 +87,7 @@ $string['comments'] = 'Comments';
$string['commentson'] = 'Comments on';
$string['commentupdated'] = 'The comment has been updated.';
$string['completionentries'] = 'Student must create entries:';
$string['completionentriesdesc'] = 'Student must create at least {$a} entry(s)';
$string['completionentriesgroup'] = 'Require entries';
$string['concept'] = 'Concept';
$string['concepts'] = 'Concepts';

View File

@ -4201,3 +4201,62 @@ function mod_glossary_core_calendar_provide_event_action(calendar_event $event,
true
);
}
/**
* Add a get_coursemodule_info function in case any glossary type wants to add 'extra' information
* for the course (see resource).
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param stdClass $coursemodule The coursemodule object (record).
* @return cached_cm_info An object on information that the courses
* will know about (most noticeably, an icon).
*/
function glossary_get_coursemodule_info($coursemodule) {
global $DB;
$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, completionentries';
if (!$choice = $DB->get_record('glossary', $dbparams, $fields)) {
return false;
}
$result = new cached_cm_info();
// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$result->customdata['customcompletionrules']['completionentries'] = $choice->completionentries;
}
return $result;
}
/**
* Callback which returns human-readable strings describing the active completion custom rules for the module instance.
*
* @param object $cm the cm_info object.
* @return array $descriptions the array of descriptions for the custom rules.
*/
function mod_glossary_get_completion_active_rule_descriptions($cm) {
// Values will be present in cm_info, and we assume these are up to date.
if (!$cm instanceof cm_info || !isset($cm->customdata['customcompletionrules'])
|| $cm->completion != COMPLETION_TRACKING_AUTOMATIC) {
return [];
}
$descriptions = [];
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionentries':
if (empty($val)) {
continue;
}
$descriptions[] = get_string('completionentriesdesc', 'glossary', $val);
break;
default:
break;
}
}
return $descriptions;
}

View File

@ -105,6 +105,7 @@ $string['completethefollowingconditions'] = 'You must complete the following con
$string['completionendreached'] = 'Require end reached';
$string['completionendreached_desc'] = 'Student must reach the end of lesson page to complete this activity';
$string['completiontimespent'] = 'Student must do this activity at least for';
$string['completiontimespentdesc'] = 'Student must do this activity for at least {$a}';
$string['completiontimespentgroup'] = 'Require time spent';
$string['conditionsfordependency'] = 'Condition(s) for the dependency';
$string['configintro'] = 'The values set here define the default values that are used in the settings form when creating a new lesson activity. Settings specified as advanced are only shown when the \'Show more...\' link is clicked.';

View File

@ -1644,3 +1644,69 @@ function mod_lesson_core_calendar_provide_event_action(calendar_event $event,
$lesson->is_accessible()
);
}
/**
* Add a get_coursemodule_info function in case any lesson type wants to add 'extra' information
* for the course (see resource).
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param stdClass $coursemodule The coursemodule object (record).
* @return cached_cm_info An object on information that the courses
* will know about (most noticeably, an icon).
*/
function lesson_get_coursemodule_info($coursemodule) {
global $DB;
$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, completionendreached, completiontimespent';
if (!$lesson = $DB->get_record('lesson', $dbparams, $fields)) {
return false;
}
$result = new cached_cm_info();
// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$result->customdata['customcompletionrules']['completionendreached'] = $lesson->completionendreached;
$result->customdata['customcompletionrules']['completiontimespent'] = $lesson->completiontimespent;
}
return $result;
}
/**
* Callback which returns human-readable strings describing the active completion custom rules for the module instance.
*
* @param object $cm the cm_info object.
* @return array $descriptions the array of descriptions for the custom rules.
*/
function mod_lesson_get_completion_active_rule_descriptions($cm) {
// Values will be present in cm_info, and we assume these are up to date.
if (!$cm instanceof cm_info || !isset($cm->customdata['customcompletionrules'])
|| $cm->completion != COMPLETION_TRACKING_AUTOMATIC) {
return [];
}
$descriptions = [];
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionendreached':
if (empty($val)) {
continue;
}
$descriptions[] = get_string('completionendreached_desc', 'lesson', $val);
break;
case 'completiontimespent':
if (empty($val)) {
continue;
}
$descriptions[] = get_string('completiontimespentdesc', 'lesson', format_time($val));
break;
default:
break;
}
}
return $descriptions;
}

View File

@ -168,8 +168,10 @@ $string['commentorgrade'] = 'Make comment or override grade';
$string['comments'] = 'Comments';
$string['completedon'] = 'Completed on';
$string['completionpass'] = 'Require passing grade';
$string['completionpassdesc'] = 'Student must achieve a passing grade to complete this activity';
$string['completionpass_help'] = 'If enabled, this activity is considered complete when the student receives a passing grade, with the pass grade set in the gradebook.';
$string['completionattemptsexhausted'] = 'Or all available attempts completed';
$string['completionattemptsexhausteddesc'] = 'Complete if all available attempts are exhausted';
$string['completionattemptsexhausted_help'] = 'Mark quiz complete when the student has exhausted the maximum number of attempts.';
$string['configadaptive'] = 'If you choose Yes for this option then the student will be allowed multiple responses to a question even within the same attempt at the quiz.';
$string['configattemptsallowed'] = 'Restriction on the number of attempts students are allowed at the quiz.';

View File

@ -2162,3 +2162,69 @@ function mod_quiz_core_calendar_provide_event_action(calendar_event $event,
$actionable
);
}
/**
* Add a get_coursemodule_info function in case any quiz type wants to add 'extra' information
* for the course (see resource).
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param stdClass $coursemodule The coursemodule object (record).
* @return cached_cm_info An object on information that the courses
* will know about (most noticeably, an icon).
*/
function quiz_get_coursemodule_info($coursemodule) {
global $DB;
$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, completionattemptsexhausted, completionpass';
if (!$quiz = $DB->get_record('quiz', $dbparams, $fields)) {
return false;
}
$result = new cached_cm_info();
// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$result->customdata['customcompletionrules']['completionattemptsexhausted'] = $quiz->completionattemptsexhausted;
$result->customdata['customcompletionrules']['completionpass'] = $quiz->completionpass;
}
return $result;
}
/**
* Callback which returns human-readable strings describing the active completion custom rules for the module instance.
*
* @param object $cm the cm_info object.
* @return array $descriptions the array of descriptions for the custom rules.
*/
function mod_quiz_get_completion_active_rule_descriptions($cm) {
// Values will be present in cm_info, and we assume these are up to date.
if (!$cm instanceof cm_info || !isset($cm->customdata['customcompletionrules'])
|| $cm->completion != COMPLETION_TRACKING_AUTOMATIC) {
return [];
}
$descriptions = [];
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionattemptsexhausted':
if (empty($val)) {
continue;
}
$descriptions[] = get_string('completionattemptsexhausteddesc', 'quiz');
break;
case 'completionpass':
if (empty($val)) {
continue;
}
$descriptions[] = get_string('completionpassdesc', 'quiz', format_time($val));
break;
default:
break;
}
}
return $descriptions;
}

View File

@ -82,12 +82,14 @@ $string['collapsetocwinsizedesc'] = 'This setting lets you specify the window si
$string['compatibilitysettings'] = 'Compatibility settings';
$string['completed'] = 'Completed';
$string['completionscorerequired'] = 'Require minimum score';
$string['completionscorerequireddesc'] = 'Minimum score of {$a} is required for completion';
$string['completionscorerequired_help'] = 'Enabling this setting will require a user to have at least the minimum score entered to be marked complete in this SCORM activity, as well as any other Activity Completion requirements.';
$string['completionstatus_passed'] = 'Passed';
$string['completionstatus_completed'] = 'Completed';
$string['completionstatusallscos'] = 'Require all scos to return completion status';
$string['completionstatusallscos_help'] = 'Some SCORM packages contain multiple components or "scos" - when this is enabled all scos within the package must return the relevant lesson_status for this activity to be flagged complete.';
$string['completionstatusrequired'] = 'Require status';
$string['completionstatusrequireddesc'] = 'Student must achieve at least one of the following statuses: {$a}';
$string['completionstatusrequired_help'] = 'Checking one or more statuses will require a user to achieve at least one of the checked statuses in order to be marked complete in this SCORM activity, as well as any other Activity Completion requirements.';
$string['confirmloosetracks'] = 'WARNING: The package seems to be changed or modified. If the package structure is changed, some users tracks may be lost during update process.';
$string['contents'] = 'Contents';

View File

@ -1580,6 +1580,7 @@ function mod_scorm_get_fontawesome_icon_map() {
}
/**
<<<<<<< HEAD
* This standard function will check all instances of this module
* and make sure there are up-to-date events created for each of them.
* If courseid = 0, then every scorm event in the site is checked, else
@ -1643,4 +1644,85 @@ function mod_scorm_core_calendar_provide_event_action(calendar_event $event,
1,
$actionable
);
}
}
/**
* Add a get_coursemodule_info function in case any SCORM type wants to add 'extra' information
* for the course (see resource).
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param stdClass $coursemodule The coursemodule object (record).
* @return cached_cm_info An object on information that the courses
* will know about (most noticeably, an icon).
*/
function scorm_get_coursemodule_info($coursemodule) {
global $DB;
$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, completionstatusrequired, completionscorerequired, completionstatusallscos';
if (!$scorm = $DB->get_record('scorm', $dbparams, $fields)) {
return false;
}
$result = new cached_cm_info();
// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$result->customdata['customcompletionrules']['completionstatusrequired'] = $scorm->completionstatusrequired;
$result->customdata['customcompletionrules']['completionscorerequired'] = $scorm->completionscorerequired;
$result->customdata['customcompletionrules']['completionstatusallscos'] = $scorm->completionstatusallscos;
}
return $result;
}
/**
* Callback which returns human-readable strings describing the active completion custom rules for the module instance.
*
* @param object $cm the cm_info object.
* @return array $descriptions the array of descriptions for the custom rules.
*/
function mod_scorm_get_completion_active_rule_descriptions($cm) {
// Values will be present in cm_info, and we assume these are up to date.
if (!$cm instanceof cm_info || !isset($cm->customdata['customcompletionrules'])
|| $cm->completion != COMPLETION_TRACKING_AUTOMATIC) {
return [];
}
$descriptions = [];
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionstatusrequired':
if (is_null($val)) {
continue;
}
// Determine the selected statuses using a bitwise operation.
$cvalues = array();
foreach (scorm_status_options(true) as $bit => $string) {
if (($val & $bit) == $bit) {
$cvalues[] = $string;
}
}
$statusstring = implode(', ', $cvalues);
$descriptions[] = get_string('completionstatusrequireddesc', 'scorm', $statusstring);
break;
case 'completionscorerequired':
if (is_null($val)) {
continue;
}
$descriptions[] = get_string('completionscorerequireddesc', 'scorm', $val);
break;
case 'completionstatusallscos':
if (empty($val)) {
continue;
}
$descriptions[] = get_string('completionstatusallscos', 'scorm');
break;
default:
break;
}
}
return $descriptions;
}

View File

@ -1145,3 +1145,62 @@ function mod_survey_core_calendar_provide_event_action(calendar_event $event,
true
);
}
/**
* Add a get_coursemodule_info function in case any survey type wants to add 'extra' information
* for the course (see resource).
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param stdClass $coursemodule The coursemodule object (record).
* @return cached_cm_info An object on information that the courses
* will know about (most noticeably, an icon).
*/
function survey_get_coursemodule_info($coursemodule) {
global $DB;
$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, completionsubmit';
if (!$survey = $DB->get_record('survey', $dbparams, $fields)) {
return false;
}
$result = new cached_cm_info();
// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$result->customdata['customcompletionrules']['completionsubmit'] = $survey->completionsubmit;
}
return $result;
}
/**
* Callback which returns human-readable strings describing the active completion custom rules for the module instance.
*
* @param object $cm the cm_info object.
* @return array $descriptions the array of descriptions for the custom rules.
*/
function mod_survey_get_completion_active_rule_descriptions($cm) {
// Values will be present in cm_info, and we assume these are up to date.
if (!$cm instanceof cm_info || !isset($cm->customdata['customcompletionrules'])
|| $cm->completion != COMPLETION_TRACKING_AUTOMATIC) {
return [];
}
$descriptions = [];
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionsubmit':
if (empty($val)) {
continue;
}
$descriptions[] = get_string('completionsubmit', 'survey');
break;
default:
break;
}
}
return $descriptions;
}