MDL-48773 mod_choice: Lock number of responses if selections are made.
authorStephen Bourget <steve.bourget@sau19.org>
Fri, 12 Aug 2016 02:11:57 +0000 (22:11 -0400)
committerStephen Bourget <steve.bourget@sau19.org>
Fri, 12 Aug 2016 02:11:57 +0000 (22:11 -0400)
mod/choice/mod_form.php

index 8256390..512c051 100644 (file)
@@ -34,6 +34,12 @@ class mod_choice_mod_form extends moodleform_mod {
         $mform->addElement('selectyesno', 'allowupdate', get_string("allowupdate", "choice"));
 
         $mform->addElement('selectyesno', 'allowmultiple', get_string('allowmultiple', 'choice'));
+        if ($this->_instance) {
+            if ($DB->count_records('choice_answers', array('choiceid' => $this->_instance)) > 0) {
+                // Prevent user from toggeling the number of allowed answers once there are submissions.
+                $mform->freeze('allowmultiple');
+            }
+        }
 
         $mform->addElement('selectyesno', 'limitanswers', get_string('limitanswers', 'choice'));
         $mform->addHelpButton('limitanswers', 'limitanswers', 'choice');