Merge branch 'MDL-59478-master' of git://github.com/junpataleta/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 11 Sep 2017 22:21:48 +0000 (00:21 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 11 Sep 2017 22:21:48 +0000 (00:21 +0200)
mod/scorm/mod_form.php

index 783d542..82d650a 100644 (file)
@@ -331,15 +331,19 @@ class mod_scorm_mod_form extends moodleform_mod {
         }
 
         // Set some completion default data.
-        if (!empty($defaultvalues['completionstatusrequired']) && !is_array($defaultvalues['completionstatusrequired'])) {
+        $cvalues = array();
+        if (empty($this->_instance)) {
+            // When in add mode, set a default completion rule that requires the SCORM's status be set to "Completed".
+            $cvalues[4] = 1;
+        } else if (!empty($defaultvalues['completionstatusrequired']) && !is_array($defaultvalues['completionstatusrequired'])) {
             // Unpack values.
-            $cvalues = array();
             foreach (scorm_status_options() as $key => $value) {
                 if (($defaultvalues['completionstatusrequired'] & $key) == $key) {
                     $cvalues[$key] = 1;
                 }
             }
-
+        }
+        if (!empty($cvalues)) {
             $defaultvalues['completionstatusrequired'] = $cvalues;
         }
 
@@ -481,7 +485,6 @@ class mod_scorm_mod_form extends moodleform_mod {
             }
         }
 
-        $this->data_preprocessing($defaultvalues);
         parent::set_data($defaultvalues);
     }
 
@@ -513,10 +516,6 @@ class mod_scorm_mod_form extends moodleform_mod {
                 $firstkey = $key;
             }
             $mform->addElement('checkbox', $key, $name, $value);
-            // Default completion rule that requires the SCORM's status be set to "Completed".
-            if ($key === 'completionstatusrequired[4]') {
-                $mform->setDefault($key, 1);
-            }
             $mform->setType($key, PARAM_BOOL);
             $items[] = $key;
         }