From a9f5fc158cee524385fbc6e07a59e2ce097d2d25 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Tue, 5 Mar 2013 16:32:20 +0000 Subject: [PATCH] MDL-38315 Completion: Bugs with 'locked' status in activity form --- course/modlib.php | 2 +- course/moodleform_mod.php | 7 +++++-- mod/assign/locallib.php | 4 +++- mod/choice/mod_form.php | 6 ++++-- mod/feedback/mod_form.php | 15 +++++++-------- mod/forum/mod_form.php | 20 +++++++++++--------- mod/glossary/mod_form.php | 10 ++++++---- mod/scorm/mod_form.php | 31 ++++++++++++++++--------------- 8 files changed, 53 insertions(+), 42 deletions(-) diff --git a/course/modlib.php b/course/modlib.php index 614ac8aabfb..daf6d9c11dc 100644 --- a/course/modlib.php +++ b/course/modlib.php @@ -438,7 +438,7 @@ function update_moduleinfo($cm, $moduleinfo, $course, $mform = null) { } $completion = new completion_info($course); - if ($completion->is_enabled()) { + if ($completion->is_enabled() && !empty($moduleinfo->completionunlocked)) { // Update completion settings. $cm->completion = $moduleinfo->completion; $cm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber; diff --git a/course/moodleform_mod.php b/course/moodleform_mod.php index dd5652a9e2e..f83bf790648 100644 --- a/course/moodleform_mod.php +++ b/course/moodleform_mod.php @@ -312,8 +312,11 @@ abstract class moodleform_mod extends moodleform { } // Completion: Don't let them choose automatic completion without turning - // on some conditions - if (array_key_exists('completion', $data) && $data['completion']==COMPLETION_TRACKING_AUTOMATIC) { + // on some conditions. Ignore this check when completion settings are + // locked, as the options are then disabled. + if (array_key_exists('completion', $data) && + $data['completion'] == COMPLETION_TRACKING_AUTOMATIC && + !empty($data['completionunlocked'])) { if (empty($data['completionview']) && empty($data['completionusegrade']) && !$this->completion_rule_enabled($data)) { $errors['completion'] = get_string('badautocompletion', 'completion'); diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index db6ae51b318..a6cc859fa2e 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -846,7 +846,9 @@ class assign { $update->cutoffdate = $formdata->cutoffdate; $update->allowsubmissionsfromdate = $formdata->allowsubmissionsfromdate; $update->grade = $formdata->grade; - $update->completionsubmit = !empty($formdata->completionsubmit); + if (!empty($formdata->completionunlocked)) { + $update->completionsubmit = !empty($formdata->completionsubmit); + } $update->teamsubmission = $formdata->teamsubmission; $update->requireallteammemberssubmit = $formdata->requireallteammemberssubmit; $update->teamsubmissiongroupingid = $formdata->teamsubmissiongroupingid; diff --git a/mod/choice/mod_form.php b/mod/choice/mod_form.php index 8cca80fd67d..472fcd8c141 100644 --- a/mod/choice/mod_form.php +++ b/mod/choice/mod_form.php @@ -122,8 +122,10 @@ class mod_choice_mod_form extends moodleform_mod { return false; } // Set up completion section even if checkbox is not ticked - if (empty($data->completionsection)) { - $data->completionsection=0; + if (!empty($data->completionunlocked)) { + if (empty($data->completionsubmit)) { + $data->completionsubmit = 0; + } } return $data; } diff --git a/mod/feedback/mod_form.php b/mod/feedback/mod_form.php index 6256de76c10..e8cf5497185 100644 --- a/mod/feedback/mod_form.php +++ b/mod/feedback/mod_form.php @@ -202,14 +202,13 @@ class mod_feedback_mod_form extends moodleform_mod { $data->page_after_submitformat = $data->page_after_submit_editor['format']; $data->page_after_submit = $data->page_after_submit_editor['text']; - // Turn off completion settings if the checkboxes aren't ticked - $autocompletion = !empty($data->completion) AND - $data->completion==COMPLETION_TRACKING_AUTOMATIC; - if (empty($data->completion) || !$autocompletion) { - $data->completionsubmit=0; - } - if (empty($data->completionsubmit)) { - $data->completionsubmit=0; + if (!empty($data->completionunlocked)) { + // Turn off completion settings if the checkboxes aren't ticked + $autocompletion = !empty($data->completion) && + $data->completion == COMPLETION_TRACKING_AUTOMATIC; + if (!$autocompletion || empty($data->completionsubmit)) { + $data->completionsubmit=0; + } } } diff --git a/mod/forum/mod_form.php b/mod/forum/mod_form.php index a173bb07b63..4c44b59a4e1 100644 --- a/mod/forum/mod_form.php +++ b/mod/forum/mod_form.php @@ -245,15 +245,17 @@ class mod_forum_mod_form extends moodleform_mod { return false; } // Turn off completion settings if the checkboxes aren't ticked - $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC; - if (empty($data->completiondiscussionsenabled) || !$autocompletion) { - $data->completiondiscussions = 0; - } - if (empty($data->completionrepliesenabled) || !$autocompletion) { - $data->completionreplies = 0; - } - if (empty($data->completionpostsenabled) || !$autocompletion) { - $data->completionposts = 0; + if (!empty($data->completionunlocked)) { + $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC; + if (empty($data->completiondiscussionsenabled) || !$autocompletion) { + $data->completiondiscussions = 0; + } + if (empty($data->completionrepliesenabled) || !$autocompletion) { + $data->completionreplies = 0; + } + if (empty($data->completionpostsenabled) || !$autocompletion) { + $data->completionposts = 0; + } } return $data; } diff --git a/mod/glossary/mod_form.php b/mod/glossary/mod_form.php index 0362aed1d61..f86ee10e5be 100644 --- a/mod/glossary/mod_form.php +++ b/mod/glossary/mod_form.php @@ -204,10 +204,12 @@ class mod_glossary_mod_form extends moodleform_mod { if (!$data) { return false; } - // Turn off completion settings if the checkboxes aren't ticked - $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC; - if (empty($data->completionentriesenabled) || !$autocompletion) { - $data->completionentries = 0; + if (!empty($data->completionunlocked)) { + // Turn off completion settings if the checkboxes aren't ticked + $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC; + if (empty($data->completionentriesenabled) || !$autocompletion) { + $data->completionentries = 0; + } } return $data; } diff --git a/mod/scorm/mod_form.php b/mod/scorm/mod_form.php index c6588229cc7..b9459410223 100644 --- a/mod/scorm/mod_form.php +++ b/mod/scorm/mod_form.php @@ -519,24 +519,25 @@ class mod_scorm_mod_form extends moodleform_mod { return false; } - // Turn off completion settings if the checkboxes aren't ticked - $autocompletion = isset($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC; + if (!empty($data->completionunlocked)) { + // Turn off completion settings if the checkboxes aren't ticked + $autocompletion = isset($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC; - if (isset($data->completionstatusrequired) && is_array($data->completionstatusrequired)) { - $total = 0; - foreach (array_keys($data->completionstatusrequired) as $state) { - $total |= $state; + if (isset($data->completionstatusrequired) && + is_array($data->completionstatusrequired) && $autocompletion) { + $total = 0; + foreach (array_keys($data->completionstatusrequired) as $state) { + $total |= $state; + } + + $data->completionstatusrequired = $total; + } else { + $data->completionstatusrequired = null; } - $data->completionstatusrequired = $total; - } - - if (!$autocompletion) { - $data->completionstatusrequired = null; - } - - if (!empty($data->completionscoredisabled) || !$autocompletion) { - $data->completionscorerequired = null; + if (!empty($data->completionscoredisabled) || !$autocompletion) { + $data->completionscorerequired = null; + } } return $data;