]> git.mjollnir.org Git - moodle.git/commitdiff
New function setup_and_print_groups() makes it much easier to set
authormoodler <moodler>
Sun, 15 Feb 2004 07:13:08 +0000 (07:13 +0000)
committermoodler <moodler>
Sun, 15 Feb 2004 07:13:08 +0000 (07:13 +0000)
up groups everywhere else.

lib/moodlelib.php
lib/weblib.php

index bb122e90cd46227b9093636f48d23b6369a91ee1..1b04f1afb2d8da5b9ee71947efcd5fcf2f75fccc 100644 (file)
@@ -1165,6 +1165,38 @@ function get_and_set_current_group($course, $groupmode, $groupid=0) {
 }
 
 
+/**
+* A big combination function to make it easier for modules
+* to set up groups.
+*
+* Terminates if the current user shouldn't be looking at this group
+* Otherwise returns the current group if there is one
+* Otherwise returns false if groups aren't relevant
+*
+* @param       type description
+*/
+function setup_and_print_groups($course, $groupmode, $urlroot) {
+
+    $currentgroup = get_and_set_current_group($course, $groupmode, $_GET['group']);
+
+    if ($currentgroup == false) {
+        return false;
+    }
+
+    if (!isteacheredit($course->id) and $groupmode and !$currentgroup) {
+        print_heading();
+        print_footer($course);
+        exit;
+    }
+
+    if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
+        if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
+            print_group_menu($groups, $groupmode, $currentgroup, $urlroot);
+        }
+    }
+
+    return $currentgroup;
+}
 
 
 
index 0447de49d640dcaa9152d3302cee68604038954e..0666ce84274b2551e4da0c8abe3edaa494d2b406 100644 (file)
@@ -1222,29 +1222,31 @@ function print_user($user, $course) {
 function print_group_picture($group, $courseid, $large=false, $returnstring=false, $link=true) {
     global $CFG;
 
-    if ($link) {
-        $output = "<a href=\"$CFG->wwwroot/course/groupphp?id=$courseid&amp;group=$group->id\">";
-    } else {
-        $output = "";
-    }
-    if ($large) {
-        $file = "f1";
-        $size = 100;
-    } else {
-        $file = "f2";
-        $size = 35;
-    }
-    if ($group->picture) {  // Print custom group picture
-        if ($CFG->slasharguments) {        // Use this method if possible for better caching
-            $output .= "<img align=\"absmiddle\" src=\"$CFG->wwwroot/user/pixgroup.php/$group->id/$file.jpg\"".
-                       " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
+    $output = '';
+
+    if ($group->showpicture) {
+        if ($link) {
+            $output = "<a href=\"$CFG->wwwroot/course/groupphp?id=$courseid&amp;group=$group->id\">";
+        }
+        if ($large) {
+            $file = "f1";
+            $size = 100;
         } else {
-            $output .= "<img align=\"absmiddle\" src=\"$CFG->wwwroot/user/pixgroup.php?file=/$group->id/$file.jpg\"".
-                       " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
+            $file = "f2";
+            $size = 35;
+        }
+        if ($group->picture) {  // Print custom group picture
+            if ($CFG->slasharguments) {        // Use this method if possible for better caching
+                $output .= "<img align=\"absmiddle\" src=\"$CFG->wwwroot/user/pixgroup.php/$group->id/$file.jpg\"".
+                           " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
+            } else {
+                $output .= "<img align=\"absmiddle\" src=\"$CFG->wwwroot/user/pixgroup.php?file=/$group->id/$file.jpg\"".
+                           " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
+            }
+        }
+        if ($link) {
+            $output .= "</a>";
         }
-    }
-    if ($link) {
-        $output .= "</a>";
     }
 
     if ($returnstring) {
@@ -1654,6 +1656,22 @@ function update_groups_button($courseid) {
     }
 }
 
+function print_group_menu($groups, $groupmode, $currentgroup, $urlroot) {
+/// Prints an appropriate group selection menu
+
+    echo '<table><tr><td>';
+    if ($groupmode == VISIBLEGROUPS) {
+        print_string('groupsvisible');
+    } else {
+        print_string('groupsseparate');
+    }
+    echo ':';
+    echo '</td><td nowrap="nowrap" align="left" width="50%">';
+    popup_form($urlroot.'&group=', $groups, 'selectgroup', $currentgroup, "", "", "", false, "self");
+    echo '</tr></table>';
+
+}
+
 
 function navmenu($course, $cm=NULL, $targetwindow="self") {
 // Given a course and a (current) coursemodule