]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10383 - adding UI for new grouping settings into course and mod edit forms +...
authorskodak <skodak>
Fri, 17 Aug 2007 08:05:04 +0000 (08:05 +0000)
committerskodak <skodak>
Fri, 17 Aug 2007 08:05:04 +0000 (08:05 +0000)
course/edit_form.php
course/lib.php
course/modedit.php
course/moodleform_mod.php
lang/en_utf8/group.php

index 50518d0f949823854a2d78b3159e3ea33aed4dfc..61dd997898f685ab21f5c7c94e8684563a9d2693 100644 (file)
@@ -270,6 +270,13 @@ class course_edit_form extends moodleform {
         $mform->setHelpButton('groupmodeforce', array('groupmodeforce', get_string('groupmodeforce')), true);
         $mform->setDefault('groupmodeforce', 0);
 
+        if (!empty($CFG->enablegroupings)) {
+            //default groupings selector
+            $options = array();
+            $options[0] = get_string('none');
+            $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);
+        }
+
 //--------------------------------------------------------------------------------
         $mform->addElement('header','', get_string('availability'));
 
@@ -378,6 +385,24 @@ class course_edit_form extends moodleform {
         $mform->addElement('hidden', 'students', get_string('defaultcoursestudents'));
     }
 
+    function definition_after_data() {
+        global $CFG;
+
+        $mform =& $this->_form;
+
+        // add availabe groupings
+        if ($courseid = $mform->getElementValue('id') and $mform->elementExists('defaultgroupingid')) {
+            $options = array();
+            if ($groupings = get_records('groupings', 'courseid', $courseid)) {
+                foreach ($groupings as $grouping) {
+                    $options[$grouping->id] = format_string($grouping->name);
+                }
+            }
+            $gr_el =& $mform->getElement('defaultgroupingid');
+            $gr_el->load($options);
+        }
+    }
+        
 
 /// perform some extra moodle validation
     function validation($data){
index e6114ae310e1df663bddf430424619ca8106d899..c8e5989b833ee599109f6ffd64a2bec680903b29 100644 (file)
@@ -2042,6 +2042,14 @@ function set_coursemodule_groupmode($id, $groupmode) {
     return set_field("course_modules", "groupmode", $groupmode, "id", $id);
 }
 
+function set_coursemodule_groupingid($id, $groupingid) {
+    return set_field("course_modules", "groupingid", $groupingid, "id", $id);
+}
+
+function set_coursemodule_groupmembersonly($id, $groupmembersonly) {
+    return set_field("course_modules", "groupmembersonly", $groupmembersonly, "id", $id);
+}
+
 function set_coursemodule_idnumber($id, $idnumber) {
     return set_field("course_modules", "idnumber", $idnumber, "id", $id);  
 }
index 20958e11e05d30f544b15279cfec0024810e49c0..2b9764f6469ef4c18da9cd38fedd128572c97dc2 100644 (file)
@@ -8,11 +8,10 @@
 
     require_login();
 
-    $add           = optional_param('add', '', PARAM_ALPHA);
-    $update        = optional_param('update', 0, PARAM_INT);
-    //return to course/view.php if false or mod/modname/view.php if true
-    $return        = optional_param('return', 0, PARAM_BOOL);
-    $type          = optional_param('type', '', PARAM_ALPHANUM);
+    $add    = optional_param('add', 0, PARAM_ALPHA);
+    $update = optional_param('update', 0, PARAM_INT);
+    $return = optional_param('return', 0, PARAM_BOOL); //return to course/view.php if false or mod/modname/view.php if true
+    $type   = optional_param('type', '', PARAM_ALPHANUM);
 
     if (!empty($add)) {
         $section = required_param('section', PARAM_INT);
             error("This course doesn't exist");
         }
 
+        require_login($course);
+        $context = get_context_instance(CONTEXT_COURSE, $course->id);
+        require_capability('moodle/course:manageactivities', $context);
+
         if (! $module = get_record("modules", "name", $add)) {
             error("This module type doesn't exist");
         }
 
-        $context = get_context_instance(CONTEXT_COURSE, $course->id);
-        require_capability('moodle/course:manageactivities', $context);
+        if (! $cw = get_record("course_sections", "section", $section, "course", $course->id)) {
+            error("This course section doesn't exist");
+        }
 
         if (!course_allowed_module($course, $module->id)) {
             error("This module has been disabled for this particular course");
         }
 
-        require_login($course->id); // needed to setup proper $COURSE
+        $cm = null;
+
+        $form->section          = $section;  // The section number itself - relative!!! (section column in course_sections)
+        $form->visible          = $cw->visible;
+        $form->course           = $course->id;
+        $form->module           = $module->id;
+        $form->modulename       = $module->name;
+        $form->groupmode        = $course->groupmode;
+        $form->groupingid       = $course->defaultgroupingid;
+        $form->groupmembersonly = 0;
+        $form->instance         = '';
+        $form->coursemodule     = '';
+        $form->add              = $add;
+        $form->return           = 0; //must be false if this is an add, go back to course view on cancel
 
-        $form->section    = $section;         // The section number itself
-        $form->course     = $course->id;
-        $form->module     = $module->id;
-        $form->modulename = $module->name;
-        $form->instance   = "";
-        $form->coursemodule = "";
-        $form->add=$add;
-        $form->return=0;//must be false if this is an add, go back to course view on cancel
         if (!empty($type)) {
             $form->type = $type;
         }
@@ -65,6 +74,8 @@
             $CFG->pagepath .= '/mod';
         }
 
+        $navlinksinstancename = '';
+
     } else if (!empty($update)) {
         if (! $cm = get_record("course_modules", "id", $update)) {
             error("This course module doesn't exist");
@@ -74,7 +85,7 @@
             error("This course doesn't exist");
         }
 
-        require_login($course->id); // needed to setup proper $COURSE
+        require_login($course); // needed to setup proper $COURSE
         $context = get_context_instance(CONTEXT_MODULE, $cm->id);
         require_capability('moodle/course:manageactivities', $context);
 
             error("This course section doesn't exist");
         }
 
-
-        $form->coursemodule = $cm->id;
-        $form->section      = $cm->section;     // The section ID
-        $form->cmidnumber   = $cm->idnumber;    // The cm IDnumber
-        $form->course       = $course->id;
-        $form->module       = $module->id;
-        $form->modulename   = $module->name;
-        $form->instance     = $cm->instance;
-        $form->return = $return;
-        $form->update = $update;
+        $form->coursemodule     = $cm->id;
+        $form->section          = $cw->section;  // The section number itself - relative!!! (section column in course_sections)
+        $form->visible          = $cm->visible; //??  $cw->visible ? $cm->visible : 0; // section hiding overrides
+        $form->cmidnumber       = $cm->idnumber;          // The cm IDnumber
+        $form->groupmode        = groupmode($COURSE,$cm); // locked later if forced
+        $form->groupingid       = $cm->groupingid;
+        $form->groupmembersonly = $cm->groupmembersonly;
+        $form->course           = $course->id;
+        $form->module           = $module->id;
+        $form->modulename       = $module->name;
+        $form->instance         = $cm->instance;
+        $form->return           = $return;
+        $form->update           = $update;
 
         // add existing outcomes
         if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$form->modulename,
     }
 
     $mformclassname = 'mod_'.$module->name.'_mod_form';
-    $cousesection=isset($cw->section)?$cw->section:$section;
-    $mform=& new $mformclassname($form->instance, $cousesection, ((isset($cm))?$cm:null));
+    $mform =& new $mformclassname($form->instance, $cw->section, $cm);
     $mform->set_data($form);
 
     if ($mform->is_cancelled()) {
-        if ($return && isset($cm)){
+        if ($return && !empty($cm->id)){
             redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id");
         } else {
-            redirect("view.php?id=$course->id#section-".$cousesection);
+            redirect("view.php?id=$course->id#section-".$cw->section);
         }
     } else if ($fromform = $mform->get_data()) {
         if (empty($fromform->coursemodule)) { //add
                 error($returnfromfunc, "view.php?id=$course->id");
             }
 
-            if (isset($fromform->visible)) {
-                set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
-            }
+            set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
 
             if (isset($fromform->groupmode)) {
                 set_coursemodule_groupmode($fromform->coursemodule, $fromform->groupmode);
             }
 
-            // set cm id number
-            if (isset($fromform->cmidnumber)) {
-                set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
+            if (isset($fromform->groupingid)) {
+                set_coursemodule_groupingid($fromform->coursemodule, $fromform->groupingid);
             }
 
+            if (isset($fromform->groupmembersonly)) {
+                set_coursemodule_groupmembersonly($fromform->coursemodule, $fromform->groupmembersonly);
+            }
+
+            // set cm id number
+            set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
+
             add_to_log($course->id, "course", "update mod",
                        "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
                        "$fromform->modulename $fromform->instance");
 
             $returnfromfunc = $addinstancefunction($fromform);
             if (!$returnfromfunc) {
-                /*if (file_exists($moderr)) {
-                    $form = $fromform;
-                    include_once($moderr);
-                    die;
-                }*/
                 error("Could not add a new instance of $fromform->modulename", "view.php?id=$course->id");
             }
             if (is_string($returnfromfunc)) {
                 error($returnfromfunc, "view.php?id=$course->id");
             }
 
-            if (!isset($fromform->groupmode)) { // to deal with pre-1.5 modules
-                $fromform->groupmode = $course->groupmode;  /// Default groupmode the same as course
-            }
-
             $fromform->instance = $returnfromfunc;
 
             // course_modules and course_sections each contain a reference
                 error("Could not update the course module with the correct section");
             }
 
-            if (!isset($fromform->visible)) {   // We get the section's visible field status
-                $fromform->visible = get_field("course_sections","visible","id",$sectionid);
-            }
             // make sure visibility is set correctly (in particular in calendar)
             set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
 
             // set cm idnumber
-            if (isset($fromform->cmidnumber)) {
-                set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
-            }
+            set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
 
             add_to_log($course->id, "course", "add mod",
                        "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
 
         $navlinks = array();
         $navlinks[] = array('name' => $strmodulenameplural, 'link' => "$CFG->wwwroot/mod/$module->name/index.php?id=$course->id", 'type' => 'activity');
-        if (isset($navlinksinstancename)) {
+        if ($navlinksinstancename) {
             $navlinks[] = $navlinksinstancename;
         }
         $navlinks[] = array('name' => $streditinga, 'link' => '', 'type' => 'title');
index 82937aec652c4615a29803e569ce7ff58fa91bb9..261c789ce69b816d3d703fa80712bdadcb4fd331 100644 (file)
@@ -16,7 +16,7 @@ class moodleform_mod extends moodleform {
     var $_instance;
     /**
      * Section of course that module instance will be put in or is in.
-     * This is always the section number itself.
+     * This is always the section number itself (column 'section' from 'course_sections' table).
      *
      * @var mixed
      */
@@ -64,6 +64,12 @@ class moodleform_mod extends moodleform {
                 }
             }
         }
+
+        if ($mform->elementExists('groupmode')) {
+            if ($COURSE->groupmodeforce) {
+                $mform->hardFreeze('groupmode'); // groupmode can not be changed if forced from course settings
+            }
+        }
     }
 
     // form verification
@@ -104,7 +110,7 @@ class moodleform_mod extends moodleform {
             $default_values = (array)$default_values;
         }
         $this->data_preprocessing($default_values);
-        parent::set_data($default_values + $this->standard_coursemodule_elements_settings());//never slashed for moodleform_mod
+        parent::set_data($default_values); //never slashed for moodleform_mod
     }
 
     /**
@@ -127,9 +133,22 @@ class moodleform_mod extends moodleform {
 
         $mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
         if ($supportsgroups){
-            // TODO: we must define this as mod property!
             $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);
+                }
+            }
+            $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
+            $mform->addElement('advcheckbox', 'groupmembersonly', get_string('groupmembersonly', 'group'));
+        }
+
         $mform->addElement('modvisible', 'visible', get_string('visible'));
         $mform->addElement('text', 'cmidnumber', get_string('idnumber'));
 
@@ -166,53 +185,6 @@ class moodleform_mod extends moodleform {
         $mform->setType('return', PARAM_BOOL);
     }
 
-    /**
-     * This function is called by course/modedit.php to setup defaults for standard form
-     * elements.
-     *
-     * @param object $course
-     * @param object $cm
-     * @param integer $section
-     * @return unknown
-     */
-    function standard_coursemodule_elements_settings(){
-        return ($this->modgroupmode_settings() + $this->modvisible_settings());
-    }
-    /**
-     * This is called from modedit.php to load the default for the groupmode element.
-     *
-     * @param object $course
-     * @param object $cm
-     */
-    function modgroupmode_settings(){
-        global $COURSE;
-        return array('groupmode'=>groupmode($COURSE, $this->_cm));
-    }
-    /**
-     *  This is called from modedit.php to set the default for modvisible form element.
-     *
-     * @param object $course
-     * @param object $cm
-     * @param integer $section section is a db id when updating a activity config
-     *                   or the section no when adding a new activity
-     */
-    function modvisible_settings(){
-        global $COURSE;
-        $cm=$this->_cm;
-        $section=$this->_section;
-        if ($cm) {
-            $visible = $cm->visible;
-        } else {
-            $visible = 1;
-        }
-
-        $hiddensection = !get_field('course_sections', 'visible', 'section', $section, 'course', $COURSE->id);
-        if ($hiddensection) {
-            $visible = 0;
-        }
-        return array('visible'=>$visible);
-    }
-
 }
 
 ?>
index 1d41b387b8ab5799698aa2dc7b65e2512561c950..d17d98cf66f2829f98348f1e9d5748b21550783f 100644 (file)
@@ -90,6 +90,7 @@ $string['groupmembersselected'] = 'Members of selected group';
 
 $string['javascriptrequired'] = 'This page requires Javascript to be enabled.';
 
+$string['defaultgrouping'] = 'Default grouping';
 $string['groupmode'] = 'Group mode';
 $string['groupmodeforce'] = 'Force group mode';
 $string['groupmy'] = 'My group';
@@ -97,6 +98,7 @@ $string['groupnotamember'] = 'Sorry, you are not a member of that group';
 $string['groupsnone'] = 'No groups';
 $string['groupsseparate'] = 'Separate groups';
 $string['groupsvisible'] = 'Visible groups';
+$string['groupmembersonly'] = 'Available for group members only';
 
 $string['groupaddedsuccesfully'] = 'Group $a added succesfully';
 $string['nopermissionforcreation'] = 'Can\'t create group \"$a\" as you dont have the required permissions';