MDL-58460 completion: add callbacks to mod_data for bulk completion

Part of MDL-58138 epic
This commit is contained in:
Jake Dallimore
2017-04-19 08:56:11 +08:00
parent 6445f17bfc
commit d233adbb77
3 changed files with 98 additions and 0 deletions
+59
View File
@@ -4320,3 +4320,62 @@ function mod_data_core_calendar_provide_event_action(calendar_event $event,
$actionable
);
}
/**
* Add a get_coursemodule_info function in case any database 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 data_get_coursemodule_info($coursemodule) {
global $DB;
$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, completionentries';
if (!$data = $DB->get_record('data', $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'] = $data->completionentries;
}
return $result;
}
/**
* Callback which returns human-readable strings describing the active completion custom rules for the module instance.
*
* @param cm_info|stdClass $cm object with fields ->completion and ->customdata['customcompletionrules']
* @return array $descriptions the array of descriptions for the custom rules.
*/
function mod_data_get_completion_active_rule_descriptions($cm) {
// Values will be present in cm_info, and we assume these are up to date.
if (empty($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', 'data', $val);
break;
default:
break;
}
}
return $descriptions;
}