From 94a8b91cd39fc2b391bd89b67019f26247a254e7 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Tue, 9 Mar 2021 06:42:09 +0800 Subject: [PATCH] MDL-70781 course: setting for displaying completion conditions Part of MDL-70817 --- admin/settings/courses.php | 11 +++++++++++ course/edit_form.php | 6 ++++++ lang/en/completion.php | 2 ++ lib/completionlib.php | 9 +++++++++ lib/db/install.xml | 1 + lib/db/upgrade.php | 14 ++++++++++++++ version.php | 2 +- 7 files changed, 44 insertions(+), 1 deletion(-) diff --git a/admin/settings/courses.php b/admin/settings/courses.php index c6fce346ff2..4d00f5cd772 100644 --- a/admin/settings/courses.php +++ b/admin/settings/courses.php @@ -170,6 +170,17 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) { $temp->add(new admin_setting_configselect('moodlecourse/enablecompletion', new lang_string('completion', 'completion'), new lang_string('enablecompletion_help', 'completion'), 1, array(0 => new lang_string('no'), 1 => new lang_string('yes')))); + // Display completion conditions. + $temp->add(new admin_setting_heading('showcompletionconditions', + new lang_string('showcompletionconditions', 'completion'), '')); + $temp->add(new admin_setting_configselect('moodlecourse/showcompletionconditions', + new lang_string('showcompletionconditions', 'completion'), + new lang_string('showcompletionconditions_help', 'completion'), 1, [ + 0 => new lang_string('no'), + 1 => new lang_string('yes') + ] + )); + // Groups. $temp->add(new admin_setting_heading('groups', new lang_string('groups', 'group'), '')); $choices = array(); diff --git a/course/edit_form.php b/course/edit_form.php index 399ea7a6ff8..3233a4d2f04 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -317,6 +317,12 @@ class course_edit_form extends moodleform { $mform->addElement('selectyesno', 'enablecompletion', get_string('enablecompletion', 'completion')); $mform->setDefault('enablecompletion', $courseconfig->enablecompletion); $mform->addHelpButton('enablecompletion', 'enablecompletion', 'completion'); + + $showcompletionconditions = $courseconfig->showcompletionconditions ?? COMPLETION_SHOW_CONDITIONS; + $mform->addElement('selectyesno', 'showcompletionconditions', get_string('showcompletionconditions', 'completion')); + $mform->addHelpButton('showcompletionconditions', 'showcompletionconditions', 'completion'); + $mform->setDefault('showcompletionconditions', $showcompletionconditions); + $mform->hideIf('showcompletionconditions', 'enablecompletion', 'eq', COMPLETION_HIDE_CONDITIONS); } else { $mform->addElement('hidden', 'enablecompletion'); $mform->setType('enablecompletion', PARAM_INT); diff --git a/lang/en/completion.php b/lang/en/completion.php index 1d2ab75294f..fd35b945793 100644 --- a/lang/en/completion.php +++ b/lang/en/completion.php @@ -221,6 +221,8 @@ $string['seedetails'] = 'See details'; $string['select'] = 'Select'; $string['self'] = 'Self'; $string['selfcompletion'] = 'Self completion'; +$string['showcompletionconditions'] = 'Show completion conditions'; +$string['showcompletionconditions_help'] = 'The activity completion conditions are displayed in the list of activities on the course page.'; $string['showinguser'] = 'Showing user'; $string['unenrolingfromcourse'] = 'Unenrolling from course'; $string['unenrolment'] = 'Unenrolment'; diff --git a/lib/completionlib.php b/lib/completionlib.php index 0b920fefd80..e72de6ed75d 100644 --- a/lib/completionlib.php +++ b/lib/completionlib.php @@ -141,6 +141,15 @@ define('COMPLETION_AGGREGATION_ALL', 1); */ define('COMPLETION_AGGREGATION_ANY', 2); +/** + * Completion conditions will be displayed to user. + */ +define('COMPLETION_SHOW_CONDITIONS', 1); + +/** + * Completion conditions will be hidden from user. + */ +define('COMPLETION_HIDE_CONDITIONS', 0); /** * Utility function for checking if the logged in user can view diff --git a/lib/db/install.xml b/lib/db/install.xml index 01a1fcd1157..433a5fcc2a2 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -104,6 +104,7 @@ + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 998e94e31fa..69c232acaf8 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2535,5 +2535,19 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2021033100.00); } + if ($oldversion < 2021033100.01) { + // Define field 'showcompletionconditions' to be added to course. + $table = new xmldb_table('course'); + $field = new xmldb_field('showcompletionconditions', XMLDB_TYPE_INTEGER, '1', null, + XMLDB_NOTNULL, null, '1', 'completionnotify'); + + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2021033100.01); + } + return true; } diff --git a/version.php b/version.php index 7444238b623..95b8cc58123 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2021033100.00; // 20201109 = branching date YYYYMMDD - do not modify! +$version = 2021033100.01; // 20201109 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '3.11dev+ (Build: 20210330)';// Human-friendly version name -- 2.43.0