MDL-37085 fixed mess with code overwriting cm_info properties
authorMarina Glancy <marina@moodle.com>
Thu, 13 Dec 2012 06:27:11 +0000 (14:27 +0800)
committerMarina Glancy <marina@moodle.com>
Mon, 14 Jan 2013 04:01:25 +0000 (15:01 +1100)
In case when groupmode is forced by the course we should take it from the
course and not overwrite cm_info::groupmode externally

blocks/site_main_menu/block_site_main_menu.php
blocks/social_activities/block_social_activities.php
course/lib.php
lib/modinfolib.php

index 4cd681f..17729df 100644 (file)
@@ -65,9 +65,6 @@ class block_site_main_menu extends block_list {
         $modinfo = get_fast_modinfo($course);
         $section = $modinfo->get_section_info(0);
 
-        $groupbuttons = $course->groupmode;
-        $groupbuttonslink = (!$course->groupmodeforce);
-
         if ($ismoving) {
             $strmovehere = get_string('movehere');
             $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
@@ -90,14 +87,6 @@ class block_site_main_menu extends block_list {
                     continue;
                 }
                 if (!$ismoving) {
-                    if ($groupbuttons) {
-                        if (! $mod->groupmodelink = $groupbuttonslink) {
-                            $mod->groupmode = $course->groupmode;
-                        }
-
-                    } else {
-                        $mod->groupmode = false;
-                    }
                     $editbuttons = '<div class="buttons">'.make_editing_buttons($mod, true, true).'</div>';
                 } else {
                     $editbuttons = '';
index 0de13b7..0f409f6 100644 (file)
@@ -67,9 +67,6 @@ class block_social_activities extends block_list {
         $modinfo = get_fast_modinfo($course);
         $section = $modinfo->get_section_info(0);
 
-        $groupbuttons = $course->groupmode;
-        $groupbuttonslink = (!$course->groupmodeforce);
-
         if ($ismoving) {
             $strmovehere = get_string('movehere');
             $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
@@ -92,14 +89,6 @@ class block_social_activities extends block_list {
                     continue;
                 }
                 if (!$ismoving) {
-                    if ($groupbuttons) {
-                        if (! $mod->groupmodelink = $groupbuttonslink) {
-                            $mod->groupmode = $course->groupmode;
-                        }
-
-                    } else {
-                        $mod->groupmode = false;
-                    }
                     $editbuttons = '<br />'.make_editing_buttons($mod, true, true);
                 } else {
                     $editbuttons = '';
index 167b380..fcc9269 100644 (file)
@@ -1339,8 +1339,6 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
 
     static $initialised;
 
-    static $groupbuttons;
-    static $groupbuttonslink;
     static $isediting;
     static $ismoving;
     static $movingpix;
@@ -1348,8 +1346,6 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
     static $strunreadpostsone;
 
     if (!isset($initialised)) {
-        $groupbuttons     = ($course->groupmode or (!$course->groupmodeforce));
-        $groupbuttonslink = (!$course->groupmodeforce);
         $isediting        = $PAGE->user_is_editing();
         $ismoving         = $isediting && ismoving($course->id);
         if ($ismoving) {
@@ -1504,13 +1500,13 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
                     }
 
                     // If specified, display extra content after link.
-                    if ($content) {
-                        $contentpart = html_writer::tag('div', $content, array('class' =>
-                                trim('contentafterlink ' . $textclasses)));
-                    }
-                } else {
-                    // No link, so display only content.
-                    $contentpart = html_writer::tag('div', $accesstext . $content, array('class' => $textclasses));
+                if ($content) {
+                    $contentpart = html_writer::tag('div', $content, array('class' =>
+                            trim('contentafterlink ' . $textclasses)));
+                }
+            } else {
+                // No link, so display only content.
+                $contentpart = html_writer::tag('div', $accesstext . $content, array('class' => $textclasses));
                 }
 
             // Module can put text after the link (e.g. forum unread)
@@ -1530,14 +1526,6 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
             }
 
             if ($isediting) {
-                if ($groupbuttons and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) {
-                    if (! $mod->groupmodelink = $groupbuttonslink) {
-                        $mod->groupmode = $course->groupmode;
-                    }
-
-                } else {
-                    $mod->groupmode = false;
-                }
                 echo make_editing_buttons($mod, $absolute, true, $mod->indent, $sectionreturn);
                 echo $mod->get_after_edit_icons();
             }
@@ -3074,14 +3062,19 @@ function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) {
     }
 
     // groupmode
-    if ($hasmanageactivities and $mod->groupmode !== false) {
-        if ($mod->groupmode == SEPARATEGROUPS) {
+    if ($hasmanageactivities and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) {
+        if ($mod->coursegroupmodeforce) {
+            $modgroupmode = $mod->coursegroupmode;
+        } else {
+            $modgroupmode = $mod->groupmode;
+        }
+        if ($modgroupmode == SEPARATEGROUPS) {
             $groupmode = NOGROUPS;
             $grouptitle = $str->groupsseparate;
             $forcedgrouptitle = $str->forcedgroupsseparate;
             $actionname = 'groupsseparate';
             $groupimage = 't/groups';
-        } else if ($mod->groupmode == VISIBLEGROUPS) {
+        } else if ($modgroupmode == VISIBLEGROUPS) {
             $groupmode = SEPARATEGROUPS;
             $grouptitle = $str->groupsvisible;
             $forcedgrouptitle = $str->forcedgroupsvisible;
@@ -3094,7 +3087,7 @@ function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) {
             $actionname = 'groupsnone';
             $groupimage = 't/groupn';
         }
-        if ($mod->groupmodelink) {
+        if (!$mod->coursegroupmodeforce) {
             $actions[$actionname] = new action_link(
                 new moodle_url($baseurl, array('id' => $mod->id, 'groupmode' => $groupmode)),
                 new pix_icon($groupimage, $grouptitle, 'moodle', array('class' => 'iconsmall', 'title' => '')),
index 90fb1b5..c40efc7 100644 (file)
@@ -500,6 +500,22 @@ class cm_info extends stdClass {
      */
     public $groupmembersonly;
 
+    /**
+     * Indicates whether the course containing the module has forced the groupmode
+     * This means that cm_info::$groupmode should be ignored and cm_info::$coursegroupmode be
+     * used instead
+     * @var bool
+     */
+    public $coursegroupmodeforce;
+
+    /**
+     * Group mode (one of the constants NONE, SEPARATEGROUPS, or VISIBLEGROUPS) - from
+     * course table - as specified for the course containing the module
+     * Effective only if cm_info::$coursegroupmodeforce is set
+     * @var int
+     */
+    public $coursegroupmode;
+
     /**
      * Indent level on course page (0 = no indent) - from course_modules table
      * @var int
@@ -1063,6 +1079,8 @@ class cm_info extends stdClass {
         $this->groupmode        = isset($mod->groupmode) ? $mod->groupmode : 0;
         $this->groupingid       = isset($mod->groupingid) ? $mod->groupingid : 0;
         $this->groupmembersonly = isset($mod->groupmembersonly) ? $mod->groupmembersonly : 0;
+        $this->coursegroupmodeforce = $course->groupmodeforce;
+        $this->coursegroupmode  = $course->groupmode;
         $this->indent           = isset($mod->indent) ? $mod->indent : 0;
         $this->extra            = isset($mod->extra) ? $mod->extra : '';
         $this->extraclasses     = isset($mod->extraclasses) ? $mod->extraclasses : '';