diff --git a/lang/en/completion.php b/lang/en/completion.php index 41bc6c2656e..6024ecf6dae 100644 --- a/lang/en/completion.php +++ b/lang/en/completion.php @@ -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. diff --git a/lib/modinfolib.php b/lib/modinfolib.php index f7179b4f3a1..fca2b84b7f1 100644 --- a/lib/modinfolib.php +++ b/lib/modinfolib.php @@ -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; + } } diff --git a/mod/assign/lib.php b/mod/assign/lib.php index 8016f7a93f1..96d21dca968 100644 --- a/mod/assign/lib.php +++ b/mod/assign/lib.php @@ -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 diff --git a/mod/choice/lib.php b/mod/choice/lib.php index dfce5c3bb29..662b2a3476e 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -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; +} diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index 27da47dfd5e..c1f25ce06be 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -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; +} diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php index 4ee96940cfd..4970f19651e 100644 --- a/mod/forum/lang/en/forum.php +++ b/mod/forum/lang/en/forum.php @@ -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.'; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 4ed4e4a336d..a3fc2b58547 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -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; +} diff --git a/mod/glossary/lang/en/glossary.php b/mod/glossary/lang/en/glossary.php index 0eb9bf50f98..caf685a820a 100644 --- a/mod/glossary/lang/en/glossary.php +++ b/mod/glossary/lang/en/glossary.php @@ -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'; diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index a2a00ae01cb..04ad29ef4ea 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -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; +} diff --git a/mod/lesson/lang/en/lesson.php b/mod/lesson/lang/en/lesson.php index b61512ee5a0..48a4b70f0a3 100644 --- a/mod/lesson/lang/en/lesson.php +++ b/mod/lesson/lang/en/lesson.php @@ -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.'; diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index 0e216448af5..817f34d966d 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -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; +} diff --git a/mod/quiz/lang/en/quiz.php b/mod/quiz/lang/en/quiz.php index fac4f4f5b8d..aab2fcf1fd9 100644 --- a/mod/quiz/lang/en/quiz.php +++ b/mod/quiz/lang/en/quiz.php @@ -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.'; diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 23d894cd7df..26ddc29fa52 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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; +} diff --git a/mod/scorm/lang/en/scorm.php b/mod/scorm/lang/en/scorm.php index b31c5db7b35..e78e94d495b 100644 --- a/mod/scorm/lang/en/scorm.php +++ b/mod/scorm/lang/en/scorm.php @@ -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'; diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 4bd3045f603..bf2db5f0413 100644 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -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 ); -} \ No newline at end of file +} + +/** + * 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; +} diff --git a/mod/survey/lib.php b/mod/survey/lib.php index 15e13e42060..24307330a87 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -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; +}