From 3d575e6f08b07ac7c88f3b1ad0b188190cd920b4 Mon Sep 17 00:00:00 2001 From: moodler Date: Sat, 31 Jan 2004 08:40:38 +0000 Subject: [PATCH] Improvements to groups. - you can now actually turn group modes on and off for each activity. :-) "Turn Editing On" to see the new icons. - Link to Groups page is now smarter about when it does and doesn't appear --- course/format/social/format.php | 4 +- course/format/topics/format.php | 4 +- course/format/weeks/format.php | 4 +- course/lib.php | 123 ++++++++++++++++++++------------ course/mod.php | 22 ++++++ 5 files changed, 109 insertions(+), 48 deletions(-) diff --git a/course/format/social/format.php b/course/format/social/format.php index a7238aecc9..68c53c0469 100644 --- a/course/format/social/format.php +++ b/course/format/social/format.php @@ -18,9 +18,11 @@ $modicon[]="pixpath/i/users.gif\" height=16 width=16 alt=\"\">"; if ($course->groupmode or !$course->groupmodeforce) { - if (isteacheredit($course->id) or $course->groupmode == VISIBLEGROUPS) { + if ($course->groupmode == VISIBLEGROUPS or isteacheredit($course->id)) { $moddata[]="id\">$strgroups"; $modicon[]="pixpath/i/group.gif\" height=16 width=16 alt=\"\">"; + } else if ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce) { + // Show nothing } else if ($currentgroup = get_current_group($course->id)) { $moddata[]="id\">$strgroupmy"; $modicon[]="pixpath/i/group.gif\" height=16 width=16 alt=\"\">"; diff --git a/course/format/topics/format.php b/course/format/topics/format.php index 7b2eaf6fb3..83f7baacab 100644 --- a/course/format/topics/format.php +++ b/course/format/topics/format.php @@ -59,9 +59,11 @@ $modicon[]="pixpath/i/users.gif\" height=16 width=16 alt=\"\">"; if ($course->groupmode or !$course->groupmodeforce) { - if (isteacheredit($course->id) or $course->groupmode == VISIBLEGROUPS) { + if ($course->groupmode == VISIBLEGROUPS or isteacheredit($course->id)) { $moddata[]="id\">$strgroups"; $modicon[]="pixpath/i/group.gif\" height=16 width=16 alt=\"\">"; + } else if ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce) { + // Show nothing } else if ($currentgroup = get_current_group($course->id)) { $moddata[]="id\">$strgroupmy"; $modicon[]="pixpath/i/group.gif\" height=16 width=16 alt=\"\">"; diff --git a/course/format/weeks/format.php b/course/format/weeks/format.php index 83f68371df..64657906d0 100644 --- a/course/format/weeks/format.php +++ b/course/format/weeks/format.php @@ -47,9 +47,11 @@ $modicon[]="pixpath/i/users.gif\" height=16 width=16 alt=\"\">"; if ($course->groupmode or !$course->groupmodeforce) { - if (isteacheredit($course->id) or $course->groupmode == VISIBLEGROUPS) { + if ($course->groupmode == VISIBLEGROUPS or isteacheredit($course->id)) { $moddata[]="id\">$strgroups"; $modicon[]="pixpath/i/group.gif\" height=16 width=16 alt=\"\">"; + } else if ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce) { + // Show nothing } else if ($currentgroup = get_current_group($course->id)) { $moddata[]="id\">$strgroupmy"; $modicon[]="pixpath/i/group.gif\" height=16 width=16 alt=\"\">"; diff --git a/course/lib.php b/course/lib.php index d4c3645cc0..72db63848b 100644 --- a/course/lib.php +++ b/course/lib.php @@ -543,20 +543,26 @@ function print_section_block($heading, $course, $section, $mods, $modnames, $mod $absolute=true, $width="100%") { global $CFG, $USER, $THEME; + static $groupbuttons; static $isteacher; static $isediting; static $ismoving; static $strmovehere; static $strmovefull; + static $strcancel; + static $stractivityclipboard; if (!isset($isteacher)) { + $groupbuttons = $course->groupmode and !$course->groupmodeforce; $isteacher = isteacher($course->id); - } - if (!isset($isediting)) { $isediting = isediting($course->id); - } - if (!isset($ismoving)) { $ismoving = ismoving($course->id); + if ($ismoving) { + $strmovehere = get_string("movehere"); + $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); + $strcancel= get_string("cancel"); + $stractivityclipboard = $USER->activitycopyname; + } } $modinfo = unserialize($course->modinfo); @@ -564,18 +570,15 @@ function print_section_block($heading, $course, $section, $mods, $modnames, $mod $modicon = array(); $editbuttons = ""; + if ($ismoving) { + $modicon[] = " pixpath/t/move.gif\" height=\"11\" width=\"11\">"; + $moddata[] = "$USER->activitycopyname (wwwroot/course/mod.php?cancelcopy=true\">$strcancel)"; + } + if (!empty($section->sequence)) { $sectionmods = explode(",", $section->sequence); - if ($ismoving) { - $strmovehere = get_string("movehere"); - $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); - $stractivityclipboard = $USER->activitycopyname; - $strcancel= get_string("cancel"); - $modicon[] = " pixpath/t/move.gif\" height=\"11\" width=\"11\">"; - $moddata[] = "$USER->activitycopyname (wwwroot/course/mod.php?cancelcopy=true\">$strcancel)"; - } foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { @@ -583,7 +586,10 @@ function print_section_block($heading, $course, $section, $mods, $modnames, $mod } $mod = $mods[$modnumber]; if ($isediting and !$ismoving) { - $editbuttons = "
".make_editing_buttons($mod->id, $absolute, $mod->visible, true); + if (!$groupbuttons) { + $mod->groupmode = false; + } + $editbuttons = "
".make_editing_buttons($mod, $absolute, true); } else { $editbuttons = ""; } @@ -642,6 +648,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, /// Prints a section full of activity modules global $CFG, $USER; + static $groupbuttons; static $isteacher; static $isediting; static $ismoving; @@ -649,17 +656,14 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, static $strmovefull; if (!isset($isteacher)) { + $groupbuttons = $course->groupmode and !$course->groupmodeforce; $isteacher = isteacher($course->id); - } - if (!isset($isediting)) { $isediting = isediting($course->id); - } - if (!isset($ismoving)) { $ismoving = ismoving($course->id); - } - if ($ismoving) { - $strmovehere = get_string("movehere"); - $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); + if ($ismoving) { + $strmovehere = get_string("movehere"); + $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); + } } $modinfo = unserialize($course->modinfo); @@ -715,8 +719,11 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, " href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename"; } if ($isediting) { + if (!$groupbuttons) { + $mod->groupmode = false; + } echo "  "; - echo make_editing_buttons($mod->id, $absolute, $mod->visible, true, $mod->indent); + echo make_editing_buttons($mod, $absolute, true, $mod->indent); } echo ""; echo ""; @@ -1373,6 +1380,10 @@ function add_mod_to_section($mod, $beforemod=NULL) { } } +function set_groupmode_for_module($id, $groupmode) { + return set_field("course_modules", "groupmode", $groupmode, "id", $id); +} + function hide_course_module($mod) { return set_field("course_modules", "visible", 0, "id", $mod); } @@ -1595,20 +1606,25 @@ function move_module($cm, $move) { } } -function make_editing_buttons($moduleid, $absolute=false, $visible=true, $moveselect=true, $indent=-1) { +function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=-1) { global $CFG, $THEME; - static $str = ''; - if (empty($str)) { - $str->delete = get_string("delete"); - $str->move = get_string("move"); - $str->moveup = get_string("moveup"); - $str->movedown = get_string("movedown"); - $str->moveright = get_string("moveright"); - $str->moveleft = get_string("moveleft"); - $str->update = get_string("update"); - $str->hide = get_string("hide"); - $str->show = get_string("show"); + static $str; + + if (!isset($str)) { + $str->delete = get_string("delete"); + $str->move = get_string("move"); + $str->moveup = get_string("moveup"); + $str->movedown = get_string("movedown"); + $str->moveright = get_string("moveright"); + $str->moveleft = get_string("moveleft"); + $str->update = get_string("update"); + $str->hide = get_string("hide"); + $str->show = get_string("show"); + $str->clicktochange = get_string("clicktochange"); + $str->groupsnone = get_string("groupsnone"); + $str->groupsseparate = get_string("groupsseparate"); + $str->groupsvisible = get_string("groupsvisible"); } if ($absolute) { @@ -1623,39 +1639,56 @@ function make_editing_buttons($moduleid, $absolute=false, $visible=true, $movese $pixpath = "$path/../theme/$CFG->theme/pix"; } - if ($visible) { - $hideshow = "hide\" href=\"$path/mod.php?hide=$moduleid\">visible) { + $hideshow = "hide\" href=\"$path/mod.php?hide=$mod->id\"> "; } else { - $hideshow = "show\" href=\"$path/mod.php?show=$moduleid\">show\" href=\"$path/mod.php?show=$mod->id\"> "; } + if ($mod->groupmode !== false) { + if ($mod->groupmode == SEPARATEGROUPS) { + $groupmode = "groupsseparate ($str->clicktochange)\" ". + " href=\"$path/mod.php?id=$mod->id&groupmode=0\"> "; + } else if ($mod->groupmode == VISIBLEGROUPS) { + $groupmode = "groupsvisible ($str->clicktochange)\" ". + " href=\"$path/mod.php?id=$mod->id&groupmode=1\"> "; + } else { + $groupmode = "groupsnone ($str->clicktochange)\" ". + " href=\"$path/mod.php?id=$mod->id&groupmode=2\"> "; + } + } else { + $groupmode = ""; + } if ($moveselect) { - $move = "move\" href=\"$path/mod.php?copy=$moduleid\">move\" href=\"$path/mod.php?copy=$mod->id\">"; } else { - $move = "moveup\" href=\"$path/mod.php?id=$moduleid&move=-1\">moveup\" href=\"$path/mod.php?id=$mod->id&move=-1\">". - "movedown\" href=\"$path/mod.php?id=$moduleid&move=1\">movedown\" href=\"$path/mod.php?id=$mod->id&move=1\">"; } $leftright = ""; if ($indent > 0) { - $leftright .= "moveleft\" href=\"$path/mod.php?id=$moduleid&indent=-1\">moveleft\" href=\"$path/mod.php?id=$mod->id&indent=-1\">"; } if ($indent >= 0) { - $leftright .= "moveright\" href=\"$path/mod.php?id=$moduleid&indent=1\">moveright\" href=\"$path/mod.php?id=$mod->id&indent=1\">"; } return "$leftright$move". - "update\" href=\"$path/mod.php?update=$moduleid\">update\" href=\"$path/mod.php?update=$mod->id\">". - "delete\" href=\"$path/mod.php?delete=$moduleid\">$hideshow"; + "delete\" href=\"$path/mod.php?delete=$mod->id\">$hideshow$groupmode"; } ?> diff --git a/course/mod.php b/course/mod.php index 9dd6023a50..c32be8d66f 100644 --- a/course/mod.php +++ b/course/mod.php @@ -278,6 +278,28 @@ } exit; + } else if (isset($_GET['groupmode'])) { + + if (! $cm = get_record("course_modules", "id", $_GET['id'])) { + error("This course module doesn't exist"); + } + + if (!isteacheredit($cm->course)) { + error("You can't modify this course!"); + } + + set_groupmode_for_module($cm->id, $_GET['groupmode']); + + rebuild_course_cache($cm->course); + + $site = get_site(); + if ($site->id == $cm->course) { + redirect($CFG->wwwroot); + } else { + redirect("view.php?id=$cm->course"); + } + exit; + } else if (isset($_GET['copy'])) { // value = course module if (! $cm = get_record("course_modules", "id", $_GET['copy'])) { -- 2.39.5