]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10383 adding new standard elements method - modules now must specify what they...
authorskodak <skodak>
Mon, 20 Aug 2007 07:27:04 +0000 (07:27 +0000)
committerskodak <skodak>
Mon, 20 Aug 2007 07:27:04 +0000 (07:27 +0000)
course/modedit.php
course/moodleform_mod.php
mod/glossary/mod_form.php
mod/lesson/mod_form.php
mod/resource/mod_form.php

index 2b9764f6469ef4c18da9cd38fedd128572c97dc2..7f575ec0908ce5b603eaa71bbac629e3a07b05d0 100644 (file)
         $updateinstancefunction = $fromform->modulename."_update_instance";
 
         if (!empty($fromform->update)) {
+            if (!isset($fromform->groupingid)) {
+                $fromform->groupingid = 0;
+            }
 
-            if (isset($fromform->name)) {
-                if (trim($fromform->name) == '') {
-                    unset($fromform->name);
-                }
+            if (!isset($fromform->groupmembersonly)) {
+                $fromform->groupmembersonly = 0;
+            }
+
+            if (!isset($fromform->groupmode)) {
+                $fromform->groupmode = 0;
             }
 
             $returnfromfunc = $updateinstancefunction($fromform);
             }
 
             set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
-
-            if (isset($fromform->groupmode)) {
-                set_coursemodule_groupmode($fromform->coursemodule, $fromform->groupmode);
-            }
-
-            if (isset($fromform->groupingid)) {
-                set_coursemodule_groupingid($fromform->coursemodule, $fromform->groupingid);
-            }
-
-            if (isset($fromform->groupmembersonly)) {
-                set_coursemodule_groupmembersonly($fromform->coursemodule, $fromform->groupmembersonly);
-            }
+            set_coursemodule_groupmode($fromform->coursemodule, $fromform->groupmode);
+            set_coursemodule_groupingid($fromform->coursemodule, $fromform->groupingid);
+            set_coursemodule_groupmembersonly($fromform->coursemodule, $fromform->groupmembersonly);
 
             // set cm id number
             set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
                        "$fromform->instance", $fromform->coursemodule);
 
         } else if (!empty($fromform->add)){
-
             if (!course_allowed_module($course,$fromform->modulename)) {
                 error("This module ($fromform->modulename) has been disabled for this particular course");
             }
 
-            if (!isset($fromform->name) || trim($fromform->name) == '') {
-                $fromform->name = get_string("modulename", $fromform->modulename);
+            if (!isset($fromform->groupingid)) {
+                $fromform->groupingid = 0;
+            }
+
+            if (!isset($fromform->groupmembersonly)) {
+                $fromform->groupmembersonly = 0;
+            }
+
+            if (!isset($fromform->groupmode)) {
+                $fromform->groupmode = 0;
             }
 
             $returnfromfunc = $addinstancefunction($fromform);
index adc7f69e026110843bac85668580d6362d117813..b3cc68d50d50f6f92436237e28ef67e3d3943eaa 100644 (file)
@@ -85,6 +85,11 @@ class moodleform_mod extends moodleform {
 
         $errors = array();
 
+        $name = trim($data['name']);
+        if ($name == '') {
+            $errors['name'] = get_string('required');
+        }
+
         $grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$data['modulename'],
                      'iteminstance'=>$data['instance'], 'itemnumber'=>0, 'courseid'=>$COURSE->id));
         if ($data['coursemodule']) {
@@ -123,13 +128,37 @@ class moodleform_mod extends moodleform {
     /**
      * Adds all the standard elements to a form to edit the settings for an activity module.
      *
-     * @param bool $supportsgroups does this module support groups?
-     * @param bool $supportgroupmembersonly does this module support groupmembersonly access?
+     * @param mixed array or object describing supported features - groups, groupings, groupmembersonly
      */
-    function standard_coursemodule_elements($supportsgroups=true, $supportgroupmembersonly=false){
+    function standard_coursemodule_elements($features=null){
         global $COURSE, $CFG;
         $mform =& $this->_form;
 
+        // deal with legacy $supportgroups param
+        if ($features === true or $features === false) {
+            $groupmode = $features;
+            $features = new object();
+            $features->groups = $groupmode;
+
+        } else if (is_array($features)) {
+            $features = (object)$features;
+
+        } else if (empty($features)) {
+            $features = new object();
+        }
+
+        if (!isset($features->groups)) {
+            $features->groups = true;
+        }
+
+        if (!isset($features->groupings)) {
+            $features->groupings = false;
+        }
+
+        if (!isset($features->groupmembersonly)) {
+            $features->groupmembersonly = false;
+        }
+
         if (!empty($CFG->enableoutcomes)) {
             if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
                 $mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
@@ -140,23 +169,25 @@ class moodleform_mod extends moodleform {
         }
 
         $mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
-        if ($supportsgroups){
+        if ($features->groups){
             $mform->addElement('modgroupmode', 'groupmode', get_string('groupmode'));
         }
 
         if (!empty($CFG->enablegroupings)) {
-            //groupings selector
-            $options = array();
-            $options[0] = get_string('none');
-            if ($groupings = get_records('groupings', 'courseid', $COURSE->id)) {
-                foreach ($groupings as $grouping) {
-                    $options[$grouping->id] = format_string($grouping->name);
+            if ($features->groupings or $features->groupmembersonly) {
+                //groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly
+                $options = array();
+                $options[0] = get_string('none');
+                if ($groupings = get_records('groupings', 'courseid', $COURSE->id)) {
+                    foreach ($groupings as $grouping) {
+                        $options[$grouping->id] = format_string($grouping->name);
+                    }
                 }
+                $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
+                $mform->setAdvanced('groupingid');
             }
-            $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
-            $mform->setAdvanced('groupingid');
-            
-            if ($supportgroupmembersonly) {
+
+            if ($features->groupmembersonly) {
                 $mform->addElement('advcheckbox', 'groupmembersonly', get_string('groupmembersonly', 'group'));
                 $mform->setAdvanced('groupmembersonly');
             }
index 752ef26a32e5538c38d51cc1458bcd75542d7c4b..5de7f0f6dac51505a593bdb16c0deacebdb56670 100644 (file)
@@ -143,7 +143,7 @@ class mod_glossary_mod_form extends moodleform_mod {
         $mform->disabledIf('assesstimefinish', 'ratingtime');
 
 //-------------------------------------------------------------------------------
-        $this->standard_coursemodule_elements(false);
+        $this->standard_coursemodule_elements(array('groups'=>false));
 
 //-------------------------------------------------------------------------------
         // buttons
index 9ddeab79ca2770848d7cfca16ef7057297981d49..68c3506da19e986a908518b276c09ab98d3e044a 100644 (file)
@@ -278,7 +278,7 @@ class mod_lesson_mod_form extends moodleform_mod {
         $mform->setDefault('lessondefault', 0);
 
 //-------------------------------------------------------------------------------
-        $this->standard_coursemodule_elements(false);
+        $this->standard_coursemodule_elements(array('groups'=>false));
 //-------------------------------------------------------------------------------
 // buttons
         $this->add_action_buttons();
index 3d9b4bb076056021c23f1a6bfb47a52be846fc84..f1d64f814e91a7f2e5d42e60e9b5b92264bd2ea4 100644 (file)
@@ -43,7 +43,7 @@ class mod_resource_mod_form extends moodleform_mod {
         $mform->addElement('header', 'typedesc', get_string('resourcetype'.$type,'resource'));
         $this->_resinstance->setup_elements($mform);
 
-        $this->standard_coursemodule_elements(false, true);
+        $this->standard_coursemodule_elements(array('groups'=>false, 'groupmembersonly'=>true));
 
         $this->add_action_buttons();
     }