MDL-10383 - groups/groupings refactoring and improvements - basic UI for groupings...
authorskodak <skodak>
Thu, 16 Aug 2007 09:28:18 +0000 (09:28 +0000)
committerskodak <skodak>
Thu, 16 Aug 2007 09:28:18 +0000 (09:28 +0000)
12 files changed:
course/lib.php
group/assign.php
group/group.php
group/grouping.php
group/groupings.php [new file with mode: 0644]
group/index.php
group/lib/basicgrouplib.php
group/members.php [new file with mode: 0644]
lang/en_utf8/group.php
lib/grouplib.php
mod/hotpot/report.php
theme/standard/styles_layout.css

index f0f198f..72f6ffe 100644 (file)
@@ -398,8 +398,8 @@ function build_logs_array($course, $user=0, $date=0, $order="l.time ASC", $limit
 
     /// Getting all members of a group.
     if ($groupid and !$user) {
-        $gusers = groups_get_members($groupid);
-        if (!empty($gusers)) {
+        if ($gusers = groups_get_members($groupid)) {
+            $gusers = array_keys($gusers);
             $joins[] = 'l.userid IN (' . implode(',', $gusers) . ')';
         } else {
             $joins[] = 'l.userid = 0'; // No users in groups, so we want something that will always by false.
index 0bd3d76..51f74c1 100644 (file)
 <?php
 /**
- * Add/remove members from group.
- *
- * @copyright &copy; 2006 The Open University
- * @author N.D.Freear AT open.ac.uk
- * @author J.White AT open.ac.uk
- * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * Add/remove group from grouping.
  * @package groups
  */
 require_once('../config.php');
 require_once('lib.php');
 
-define("MAX_USERS_PER_PAGE", 5000);
+$groupingid = required_param('id', PARAM_INT);
 
-$groupid    = required_param('group', PARAM_INT);
-$searchtext = optional_param('searchtext', '', PARAM_RAW); // search string
-$showall    = optional_param('showall', 0, PARAM_BOOL);
-
-if ($showall) {
-    $searchtext = '';
-}
-
-
-require_login();
-if (!$group = get_record('groups', 'id', $groupid)) {
+if (!$grouping = get_record('groupings', 'id', $groupingid)) {
     error('Incorrect group id');
 }
 
-if (! $course = get_record('course', 'id', $group->courseid)) {
+if (! $course = get_record('course', 'id', $grouping->courseid)) {
     print_error('invalidcourse');
 }
-
-require_login($course);
 $courseid = $course->id;
 
-$strsearch = get_string('search');
-$strshowall = get_string('showall');
-$returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid.'&group='.$groupid;
-
+require_login($course);
 $context = get_context_instance(CONTEXT_COURSE, $courseid);
 require_capability('moodle/course:managegroups', $context);
 
-    if ($frm = data_submitted() and confirm_sesskey()) {
+$returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$courseid;
 
-        if (isset($frm->cancel)) {
-            redirect($returnurl);
 
-        } else if (isset($frm->add) and !empty($frm->addselect)) {
+if ($frm = data_submitted() and confirm_sesskey()) {
 
-            foreach ($frm->addselect as $userid) {
-                if (! $userid = clean_param($userid, PARAM_INT)) {
-                    continue;
-                }
-                if (!groups_add_member($groupid, $userid)) {
-                    print_error('erroraddremoveuser', 'group', $returnurl);
-                }
-            }
+    if (isset($frm->cancel)) {
+        redirect($returnurl);
 
-        } else if (isset($frm->remove) and !empty($frm->removeselect)) {
-
-            foreach ($frm->removeselect as $userid) {
-                if (! $userid = clean_param($userid, PARAM_INT)) {
-                    continue;
-                }
-                if (!groups_remove_member($groupid, $userid)) {
-                    print_error('erroraddremoveuser', 'group', $returnurl);
-                }
-
-                // MDL-9983
-                $eventdata = new object();
-                $eventdata -> groupid = $groupid;
-                $eventdata -> userid = $userid;
-                events_trigger('group_user_removed', $eventdata);
+    } else if (isset($frm->add) and !empty($frm->addselect)) {
+        foreach ($frm->addselect as $groupid) {
+            $groupid = (int)$groupid;
+            if (record_exists('groupings_groups', 'groupingid', $grouping->id, 'groupid', $groupid)) {
+                continue;
             }
+            $assign = new object();
+            $assign->groupingid = $grouping->id;
+            $assign->groupid = $groupid;
+            $assign->timeadded = time();
+            insert_record('groupings_groups', $assign);
         }
-    }
 
-    $groupmembers = groups_get_members($groupid);
-    $groupmembersoptions = '';
-    $groupmemberscount = 0;
-    if ($groupmembers != false) {
-        // Put the groupings into a hash and sorts them
-        foreach ($groupmembers as $userid) {
-            $listmembers[$userid] = groups_get_user_displayname($userid, $courseid);
-            $groupmemberscount ++;
-        }
-        natcasesort($listmembers);
+    } else if (isset($frm->remove) and !empty($frm->removeselect)) {
 
-        // Print out the HTML
-        foreach($listmembers as $id => $name) {
-            $groupmembersoptions .= "<option value=\"$id\">$name</option>\n";
+        foreach ($frm->removeselect as $groupid) {
+            $groupid = (int)$groupid;
+            delete_records('groupings_groups', 'groupingid', $grouping->id, 'groupid', $groupid);
         }
-    } else {
-        $groupmembersoptions .= '<option>&nbsp;</option>';
     }
+}
 
-    $potentialmembers = array();
-    $potentialmembersoptions = '';
-    $potentialmemberscount = 0;
 
-    $potentialmembers = groups_get_users_not_in_group($courseid, $groupid, $searchtext);
-    if (!empty($potentialmembers)) {
-        $potentialmemberscount = count($potentialmembers);
-    } else {
-        $potentialmemberscount = 0;
+$currentmembers = array();
+$potentialmembers  = array();
+
+if ($groups = get_records('groups', 'courseid', $courseid, 'name')) {
+    if ($assignment = get_records('groupings_groups', 'groupingid', $grouping->id)) {
+        foreach ($assignment as $ass) {
+            $currentmembers[$ass->groupid] = $groups[$ass->groupid];
+            unset($groups[$ass->groupid]);
+        }
     }
-    if ($potentialmemberscount <=  MAX_USERS_PER_PAGE) {
+    $potentialmembers = $groups;
+}
 
-        if ($potentialmembers != false) {
-            // Put the groupings into a hash and sorts them
-            foreach ($potentialmembers as $userid => $user) {
-                $nonmembers[$userid] = fullname($user);
-                //$nonmembers[$userid] = groups_get_user_displayname($userid, $courseid);
-            }
-            natcasesort($nonmembers);
+$currentmembersoptions = '';
+$currentmemberscount = 0;
+if ($currentmembers) {
+    foreach($currentmembers as $group) {
+        $currentmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>';
+        $currentmemberscount ++;
+    }
+} else {
+    $currentmembersoptions .= '<option>&nbsp;</option>';
+}
 
-            // Print out the HTML
-            foreach($nonmembers as $id => $name) {
-                $potentialmembersoptions .= "<option value=\"$id\">$name</option>\n";
-            }
-        } else {
-            $potentialmembersoptions .= '<option>&nbsp;</option>';
-        }
+$potentialmembersoptions = '';
+$potentialmemberscount = 0;
+if ($potentialmembers) {
+    foreach($potentialmembers as $group) {
+        $potentialmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>';
+        $potentialmemberscount ++;
     }
+} else {
+    $potentialmembersoptions .= '<option>&nbsp;</option>';
+}
 
-    // Print the page and form
-    $strgroups = get_string('groups');
-    $strparticipants = get_string('participants');
+// Print the page and form
+$strgroups = get_string('groups');
+$strparticipants = get_string('participants');
 
-    $groupname = groups_get_group_displayname($groupid);
+$groupingname = format_string($grouping->name);
 
-    print_header("$course->shortname: $strgroups",
-                 $course->fullname,
-                 "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
-                 "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
-                 "-> <a href=\"$CFG->wwwroot/group/index.php?id=$courseid\">$strgroups</a>".
-                 '-> '. get_string('adduserstogroup', 'group'), '', '', true, '', user_login_string($course, $USER));
+print_header("$course->shortname: $strgroups",
+             $course->fullname,
+             "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
+             "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
+             "-> <a href=\"$CFG->wwwroot/group/index.php?id=$courseid\">$strgroups</a>".
+             '-> '. get_string('addgroupstogroupings', 'group'), '', '', true, '', user_login_string($course, $USER));
 
 ?>
 <div id="addmembersform">
-    <h3 class="main"><?php print_string('adduserstogroup', 'group'); echo " $groupname"; ?></h3>
+    <h3 class="main"><?php print_string('addgroupstogroupings', 'group'); echo ": $groupingname"; ?></h3>
 
     <form id="assignform" method="post" action="">
     <div>
@@ -149,13 +112,13 @@ require_capability('moodle/course:managegroups', $context);
     <table summary="" cellpadding="5" cellspacing="0">
     <tr>
       <td valign="top">
-          <label for="removeselect"><?php print_string('existingmembers', 'group', $groupmemberscount); //count($contextusers) ?></label>
+          <label for="removeselect"><?php print_string('existingmembers', 'group', $currentmemberscount); //count($contextusers) ?></label>
           <br />
           <select name="removeselect[]" size="20" id="removeselect" multiple="multiple"
                   onfocus="document.getElementById('assignform').add.disabled=true;
                            document.getElementById('assignform').remove.disabled=false;
                            document.getElementById('assignform').addselect.selectedIndex=-1;">
-          <?php echo $groupmembersoptions ?>
+          <?php echo $currentmembersoptions ?>
           </select></td>
       <td valign="top">
 <?php // Hidden assignment? ?>
@@ -174,37 +137,13 @@ require_capability('moodle/course:managegroups', $context);
                   onfocus="document.getElementById('assignform').add.disabled=false;
                            document.getElementById('assignform').remove.disabled=true;
                            document.getElementById('assignform').removeselect.selectedIndex=-1;">
-          <?php
-            if ($potentialmemberscount > MAX_USERS_PER_PAGE) {
-                echo '<optgroup label="'.get_string('toomanytoshow').'"><option></option></optgroup>'."\n"
-                        .'<optgroup label="'.get_string('trysearching').'"><option></option></optgroup>'."\n";
-            } else {                           
-                echo $potentialmembersoptions;
-            }              
-          ?>
+         <?php echo $potentialmembersoptions ?>
          </select>
          <br />
-         <label for="searchtext" class="accesshide"><?php p($strsearch) ?></label>
-         <input type="text" name="searchtext" id="searchtext" size="30" value="<?php p($searchtext, true) ?>"
-                  onfocus ="getElementById('assignform').add.disabled=true;
-                            getElementById('assignform').remove.disabled=true;
-                            getElementById('assignform').removeselect.selectedIndex=-1;
-                            getElementById('assignform').addselect.selectedIndex=-1;"
-                  onkeydown = "var keyCode = event.which ? event.which : event.keyCode;
-                               if (keyCode == 13) {
-                                    getElementById('assignform').previoussearch.value=1;
-                                    getElementById('assignform').submit();
-                               } " />
-         <input name="search" id="search" type="submit" value="<?php p($strsearch) ?>" />
-         <?php
-              if (!empty($searchtext)) {
-                  echo '<input name="showall" id="showall" type="submit" value="'.$strshowall.'" />'."\n";
-              }
-         ?>
        </td>
     </tr>
     <tr><td>
-        <input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" />
+        <input type="submit" name="cancel" value="<?php print_string('backtogroupings', 'group'); ?>" />
     </td></tr>
     </table>
     </div>
@@ -213,4 +152,6 @@ require_capability('moodle/course:managegroups', $context);
 
 <?php
     print_footer($course);
+
+
 ?>
index 7951d97..4a8a93a 100644 (file)
@@ -14,10 +14,10 @@ require_once('lib.php');
 require_once('group_form.php');
 
 /// get url variables
-$courseid    = optional_param('courseid', PARAM_INT);
-$id          = optional_param('id', 0, PARAM_INT);
-$delete      = optional_param('delete', 0, PARAM_BOOL);
-$confirm     = optional_param('confirm', 0, PARAM_BOOL);
+$courseid = optional_param('courseid', 0, PARAM_INT);
+$id       = optional_param('id', 0, PARAM_INT);
+$delete   = optional_param('delete', 0, PARAM_BOOL);
+$confirm  = optional_param('confirm', 0, PARAM_BOOL);
 
 if ($id) {
     if (!$group = get_record('groups', 'id', $id)) {
index de6d416..eb55a24 100644 (file)
@@ -13,19 +13,19 @@ require_once('lib.php');
 require_once('grouping_form.php');
 
 /// get url variables
-$courseid    = optional_param('courseid', PARAM_INT);
-$id          = optional_param('id', 0, PARAM_INT);
-$delete      = optional_param('delete', 0, PARAM_BOOL);
-$confirm     = optional_param('confirm', 0, PARAM_BOOL);
+$courseid = optional_param('courseid', 0, PARAM_INT);
+$id       = optional_param('id', 0, PARAM_INT);
+$delete   = optional_param('delete', 0, PARAM_BOOL);
+$confirm  = optional_param('confirm', 0, PARAM_BOOL);
 
 if ($id) {
     if (!$grouping = get_record('groupings', 'id', $id)) {
         error('Group ID was incorrect');
     }
     if (empty($courseid)) {
-        $courseid = $group->courseid;
+        $courseid = $grouping->courseid;
 
-    } else if ($courseid != $group->courseid) {
+    } else if ($courseid != $grouping->courseid) {
         error('Course ID was incorrect');
     }
 
@@ -45,7 +45,7 @@ require_login($course);
 $context = get_context_instance(CONTEXT_COURSE, $course->id);
 require_capability('moodle/course:managegroups', $context);
 
-$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id;
+$returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$course->id;
 
 
 if ($id and $delete) {
@@ -53,7 +53,7 @@ if ($id and $delete) {
         print_header(get_string('deleteselectedgrouping', 'group'), get_string('deleteselectedgroup', 'group'));
         $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
         $optionsno  = array('id'=>$courseid);
-        notice_yesno(get_string('deletegroupingconfirm', 'group', $group->name), 'grouping.php', 'index.php', $optionsyes, $optionsno, 'get', 'get');
+        notice_yesno(get_string('deletegroupingconfirm', 'group', $grouping->name), 'grouping.php', 'groupings.php', $optionsyes, $optionsno, 'get', 'get');
         print_footer();
         die;
 
@@ -64,7 +64,7 @@ if ($id and $delete) {
             $eventdata->group = $id;
             $eventdata->course = $courseid;
             events_trigger('grouping_deleted', $eventdata);
-            redirect('index.php?id='.$course->id);
+            redirect($returnurl);
         } else {
             print_error('erroreditgrouping', 'group', $returnurl);
         }
@@ -99,7 +99,8 @@ if ($editform->is_cancelled()) {
 
 }
 
-$strgroups = get_string('groups');
+$strgroups        = get_string('groups');
+$strgroupings     = get_string('groupings', 'group');
 $strparticipants = get_string('participants');
 
 if ($id) {
@@ -112,7 +113,7 @@ print_header("$course->shortname: ". $strheading,
              $course->fullname,
              "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
              "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
-             "-> <a href=\"$returnurl\">$strgroups</a>".
+             "-> <a href=\"$returnurl\">$strgroupings</a>".
              "-> $strheading", '', '', true, '', user_login_string($course, $USER));
 print_heading($strheading);
 $editform->display();
diff --git a/group/groupings.php b/group/groupings.php
new file mode 100644 (file)
index 0000000..7844e7c
--- /dev/null
@@ -0,0 +1,80 @@
+<?php // $Id$
+      // Allows a creator to edit groupings
+
+require_once '../config.php';
+require_once $CFG->dirroot.'/group/lib.php';
+
+$courseid = required_param('id', PARAM_INT);
+
+if (!$course = get_record('course', 'id', $courseid)) {
+    print_error('nocourseid');
+}
+
+require_login($course);
+$context = get_context_instance(CONTEXT_COURSE, $course->id);
+require_capability('moodle/course:managegroups', $context);
+
+$strgrouping     = get_string('grouping', 'group');
+$strgroups       = get_string('groups');
+$strname         = get_string('name');
+$strdelete       = get_string('delete');
+$stredit         = get_string('edit');
+$srtnewgrouping  = get_string('creategrouping', 'group');
+$strgroups       = get_string('groups');
+$strgroupings    = get_string('groupings', 'group');
+$struses         = get_string('activities');
+$strparticipants = get_string('participants');
+$strmanagegrping = get_String('addgroupstogrouping', 'group');
+
+$navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
+                  array('name'=>$strgroups, 'link'=>$CFG->wwwroot.'/group/index.php?id='.$courseid, 'type'=>'misc'),
+                  array('name'=>$strgroupings, 'link'=>'', 'type'=>'misc'));
+$navigation = build_navigation($navlinks);
+
+/// Print header
+print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course));
+
+print_heading($strgroupings);
+
+$data = array();
+if ($groupings = get_records('groupings', 'courseid', $course->id)) {
+    foreach($groupings as $grouping) {
+        $line = array();
+        $line[0] = format_string($grouping->name);
+
+        if ($groups = groups_get_all_groups($courseid, 0, $grouping->id)) {
+            $groupnames = array();
+            foreach ($groups as $group) {
+                $groupnames[] = format_string($group->name);
+            }
+            $line[1] = implode(', ', $groupnames);
+        } else {
+            $line[1] = get_string('none');
+        }
+        $line[2] = (int)count_records('course_modules', 'course', $course->id, 'groupingid', $grouping->id);
+
+        $buttons  = "<a title=\"$stredit\" href=\"grouping.php?id=$grouping->id\"><img".
+                    " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
+        $buttons .= "<a title=\"$strdelete\" href=\"grouping.php?id=$grouping->id&amp;delete=1\"><img".
+                    " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
+        $buttons .= "<a title=\"$strmanagegrping\" href=\"assign.php?id=$grouping->id\"><img".
+                    " src=\"$CFG->pixpath/i/group.gif\" class=\"iconsmall\" alt=\"$strmanagegrping\" /></a> ";
+
+        $line[3] = $buttons;
+        $data[] = $line;
+    }
+}
+$table->head  = array($strgrouping, $strgroups, $struses, $stredit);
+$table->size  = array('30%', '50%', '10%', '10%');
+$table->align = array('left', 'left', 'center', 'center');
+$table->width = '90%';
+$table->data  = $data;
+print_table($table);
+
+echo '<div class="buttons">';
+print_single_button('grouping.php', array('courseid'=>$courseid), $srtnewgrouping);
+echo '</div>';
+
+print_footer($course);
+
+?>
index 1025061..f819440 100644 (file)
@@ -47,9 +47,14 @@ if (!$course = get_record('course', 'id',$courseid)) {
 
         case 'ajax_getmembersingroup':
             $members = array();
-
-            if ($memberids = groups_get_members($groupid)) {
-                $member_names = groups_userids_to_user_names($memberids, $courseid);
+            if ($members = groups_get_members($groupid)) {
+                $member_names = array();
+                foreach($members as $member) {
+                    $user = new object();
+                    $user->id   = $member->id;
+                    $user->name = fullname($member, true);
+                    $member_names[] = $user;
+                }
                 $json = new Services_JSON();
                 echo $json->encode($member_names);
             }
@@ -74,7 +79,7 @@ if (!$course = get_record('course', 'id',$courseid)) {
             break;
 
         case 'showaddmembersform':
-            redirect('assign.php?group='.$groupid);
+            redirect('members.php?group='.$groupid);
             break;
 
         case 'updatemembers': //Currently reloading.
@@ -175,21 +180,22 @@ if (!$course = get_record('course', 'id',$courseid)) {
     echo '<select name="user" id="members" size="15" class="select"'."\n";
     echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
 
-    $userids = false;
+    $member_names = array();
+
     if ($sel_groupid) {
-        $userids = groups_get_members($sel_groupid);
+        if ($members = groups_get_members($groupid)) {
+            foreach($members as $member) {
+                $member_names[$member->id] = fullname($member, true);
+            }
+        }
     }
 
-    if ($userids) {
+    if ($member_names) {
         // Put the groupings into a hash and sort them
-        $user_names = groups_userids_to_user_names($userids, $courseid);
-        if(empty($user_names)) {
-            echo '<option>&nbsp;</option>';
-        } else {
-            foreach ($user_names as $user) {
-                echo "<option value=\"{$user->id}\" title=\"{$user->name}\">{$user->name}</option>\n";
-            }
+        foreach ($member_names as $userid=>$username) {
+            echo "<option value=\"{$userid}\" title=\"{$username}\">{$username}</option>\n";
         }
+
     } else {
         // Print an empty option to avoid the XHTML error of having an empty select element
         echo '<option>&nbsp;</option>';
index 9369b5b..3c7f07c 100644 (file)
@@ -27,21 +27,6 @@ require_once($CFG->dirroot.'/group/db/dbbasicgrouplib.php');
     List functions  
  *****************************/
 
-/**
- * Returns the ids of the users in the specified group.
- * @param int $groupid The groupid to get the users for
- * @param string $membertype Either 'student', 'teacher' or false. The function 
- * only returns these
- * types of group members. If set to false, returns all group members. 
- * @return array | false Returns an array of the user ids for the specified
- * group or false if no users or an error returned.
- */
-function groups_get_members($groupid, $membertype = false) {
-    $userids = groups_db_get_members($groupid);
-
-    return $userids;
-}
-
 /**
  * Get the user ID and time added for each member of a group, for backup4.
  * @return array An array of member records.
diff --git a/group/members.php b/group/members.php
new file mode 100644 (file)
index 0000000..947f4b8
--- /dev/null
@@ -0,0 +1,207 @@
+<?php
+/**
+ * Add/remove members from group.
+ *
+ * @copyright &copy; 2006 The Open University
+ * @author N.D.Freear AT open.ac.uk
+ * @author J.White AT open.ac.uk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package groups
+ */
+require_once('../config.php');
+require_once('lib.php');
+
+define("MAX_USERS_PER_PAGE", 5000);
+
+$groupid    = required_param('group', PARAM_INT);
+$searchtext = optional_param('searchtext', '', PARAM_RAW); // search string
+$showall    = optional_param('showall', 0, PARAM_BOOL);
+
+if ($showall) {
+    $searchtext = '';
+}
+
+if (!$group = get_record('groups', 'id', $groupid)) {
+    error('Incorrect group id');
+}
+
+if (!$course = get_record('course', 'id', $group->courseid)) {
+    print_error('invalidcourse');
+}
+$courseid = $course->id;
+
+require_login($course);
+$context = get_context_instance(CONTEXT_COURSE, $courseid);
+require_capability('moodle/course:managegroups', $context);
+
+$strsearch = get_string('search');
+$strshowall = get_string('showall');
+$returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid.'&group='.$group->id;
+
+
+if ($frm = data_submitted() and confirm_sesskey()) {
+
+    if (isset($frm->cancel)) {
+        redirect($returnurl);
+
+    } else if (isset($frm->add) and !empty($frm->addselect)) {
+
+        foreach ($frm->addselect as $userid) {
+            if (! $userid = clean_param($userid, PARAM_INT)) {
+                continue;
+            }
+            if (!groups_add_member($groupid, $userid)) {
+                print_error('erroraddremoveuser', 'group', $returnurl);
+            }
+        }
+
+    } else if (isset($frm->remove) and !empty($frm->removeselect)) {
+
+        foreach ($frm->removeselect as $userid) {
+            if (! $userid = clean_param($userid, PARAM_INT)) {
+                continue;
+            }
+            if (!groups_remove_member($groupid, $userid)) {
+                print_error('erroraddremoveuser', 'group', $returnurl);
+            }
+
+            // MDL-9983
+            $eventdata = new object();
+            $eventdata -> groupid = $groupid;
+            $eventdata -> userid = $userid;
+            events_trigger('group_user_removed', $eventdata);
+        }
+    }
+}
+
+$groupmembersoptions = '';
+$groupmemberscount = 0;
+
+if ($groupmembers = groups_get_members($groupid)) {
+    foreach($groupmembers as $member) {
+        $groupmembersoptions .= '<option value="'.$member->id.'">'.fullname($member, true).'</option>';
+        $groupmemberscount ++;
+    }
+
+} else {
+    $groupmembersoptions .= '<option>&nbsp;</option>';
+}
+
+$potentialmembers = array();
+$potentialmembersoptions = '';
+$potentialmemberscount = 0;
+
+$potentialmembers = groups_get_users_not_in_group($courseid, $groupid, $searchtext);
+if (!empty($potentialmembers)) {
+    $potentialmemberscount = count($potentialmembers);
+} else {
+    $potentialmemberscount = 0;
+}
+if ($potentialmemberscount <=  MAX_USERS_PER_PAGE) {
+
+    if ($potentialmembers != false) {
+        // Put the groupings into a hash and sorts them
+        foreach ($potentialmembers as $userid => $user) {
+            $nonmembers[$userid] = fullname($user);
+        }
+        natcasesort($nonmembers);
+
+        // Print out the HTML
+        foreach($nonmembers as $id => $name) {
+            $potentialmembersoptions .= "<option value=\"$id\">$name</option>\n";
+        }
+    } else {
+        $potentialmembersoptions .= '<option>&nbsp;</option>';
+    }
+}
+
+// Print the page and form
+$strgroups = get_string('groups');
+$strparticipants = get_string('participants');
+
+$groupname = format_string($group->name);
+
+print_header("$course->shortname: $strgroups",
+             $course->fullname,
+             "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
+             "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
+             "-> <a href=\"$CFG->wwwroot/group/index.php?id=$courseid\">$strgroups</a>".
+             '-> '. get_string('adduserstogroup', 'group'), '', '', true, '', user_login_string($course, $USER));
+
+?>
+<div id="addmembersform">
+    <h3 class="main"><?php print_string('adduserstogroup', 'group'); echo ": $groupname"; ?></h3>
+
+    <form id="assignform" method="post" action="members.php">
+    <div>
+    <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
+    <input type="hidden" name="group" value="<?php echo $groupid; ?>" />
+
+    <table summary="" cellpadding="5" cellspacing="0">
+    <tr>
+      <td valign="top">
+          <label for="removeselect"><?php print_string('existingmembers', 'group', $groupmemberscount); //count($contextusers) ?></label>
+          <br />
+          <select name="removeselect[]" size="20" id="removeselect" multiple="multiple"
+                  onfocus="document.getElementById('assignform').add.disabled=true;
+                           document.getElementById('assignform').remove.disabled=false;
+                           document.getElementById('assignform').addselect.selectedIndex=-1;">
+          <?php echo $groupmembersoptions ?>
+          </select></td>
+      <td valign="top">
+<?php // Hidden assignment? ?>
+
+        <?php check_theme_arrows(); ?>
+        <p class="arrow_button">
+            <input name="add" id="add" type="submit" value="<?php echo '&nbsp;'.$THEME->larrow.' &nbsp; &nbsp; '.get_string('add'); ?>" title="<?php print_string('add'); ?>" />
+            <br />
+            <input name="remove" id="remove" type="submit" value="<?php echo '&nbsp; '.$THEME->rarrow.' &nbsp; &nbsp; '.get_string('remove'); ?>" title="<?php print_string('remove'); ?>" />
+        </p>
+      </td>
+      <td valign="top">
+          <label for="addselect"><?php print_string('potentialmembers', 'group', $potentialmemberscount); //$usercount ?></label>
+          <br />
+          <select name="addselect[]" size="20" id="addselect" multiple="multiple"
+                  onfocus="document.getElementById('assignform').add.disabled=false;
+                           document.getElementById('assignform').remove.disabled=true;
+                           document.getElementById('assignform').removeselect.selectedIndex=-1;">
+          <?php
+            if ($potentialmemberscount > MAX_USERS_PER_PAGE) {
+                echo '<optgroup label="'.get_string('toomanytoshow').'"><option></option></optgroup>'."\n"
+                        .'<optgroup label="'.get_string('trysearching').'"><option></option></optgroup>'."\n";
+            } else {
+                echo $potentialmembersoptions;
+            }
+          ?>
+         </select>
+         <br />
+         <label for="searchtext" class="accesshide"><?php p($strsearch) ?></label>
+         <input type="text" name="searchtext" id="searchtext" size="30" value="<?php p($searchtext, true) ?>"
+                  onfocus ="getElementById('assignform').add.disabled=true;
+                            getElementById('assignform').remove.disabled=true;
+                            getElementById('assignform').removeselect.selectedIndex=-1;
+                            getElementById('assignform').addselect.selectedIndex=-1;"
+                  onkeydown = "var keyCode = event.which ? event.which : event.keyCode;
+                               if (keyCode == 13) {
+                                    getElementById('assignform').previoussearch.value=1;
+                                    getElementById('assignform').submit();
+                               } " />
+         <input name="search" id="search" type="submit" value="<?php p($strsearch) ?>" />
+         <?php
+              if (!empty($searchtext)) {
+                  echo '<input name="showall" id="showall" type="submit" value="'.$strshowall.'" />'."\n";
+              }
+         ?>
+       </td>
+    </tr>
+    <tr><td>
+        <input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" />
+    </td></tr>
+    </table>
+    </div>
+    </form>
+</div>
+
+<?php
+    print_footer($course);
+?>
index 76bb095..6396f4e 100644 (file)
@@ -38,7 +38,6 @@ $string['deletegroupingconfirm'] = 'Are you sure you want to delete grouping \'$
 $string['deletegroupconfirm'] = 'Are you sure you want to delete group \'$a\'?';
 
 $string['editgroupingsettings'] = 'Edit grouping settings';
-$string['editgroupingpermissions'] = 'Edit grouping permissions';
 $string['deletegrouping'] = 'Delete grouping';
 $string['creategrouping'] = 'Create grouping';
 $string['createautomaticgrouping'] = 'Create automatic grouping';
@@ -52,6 +51,7 @@ $string['addgroupstogrouping'] = 'Add group to grouping'; //'groupS'
 
 $string['removeselectedusers'] = 'Remove selected users';
 $string['adduserstogroup'] = 'Add/remove users';  //'from group'
+$string['addgroupstogroupings'] = 'Add/remove groups';  //'from group'
 
 $string['groupingname'] = 'Grouping name';
 $string['defaultgroupingname'] = 'Grouping';
@@ -87,9 +87,10 @@ $string['save'] = 'Save';
 $string['cancel'] = 'Cancel';
 $string['return'] = 'Return';
 $string['backtogroups'] = 'Back to groups';
+$string['backtogroupings'] = 'Back to groupings';
 $string['existingmembers'] = 'Existing members: $a'; 
 $string['potentialmembers'] = 'Potential members: $a';
-$string['groupfor'] = "for group";
+$string['groupfor'] = 'for group';
 $string['groupinfo'] = 'Info about selected group';
 $string['groupinfomembers'] = 'Info about selected members';
 $string['groupinfopeople'] = 'Info about selected people';
index 2657b38..243416b 100644 (file)
@@ -46,24 +46,33 @@ function groups_get_group($groupid) {
  * Gets array of all groups in a specified course.
  * @param int $courseid The id of the course.
  * @param int $userid optional user id, returns only groups of the user.
+ * @param int $groupingid optional returns only groups in the specified grouping.
  * @return array | false Returns an array of the group IDs or false if no records
  * or an error occurred.
  */
-function groups_get_all_groups($courseid, $userid=0) {
+function groups_get_all_groups($courseid, $userid=0, $groupingid=0) {
     global $CFG;
 
-    if (empty($userdi)) {
-        return get_records('groups', 'courseid', $courseid, 'name ASC');
+    if (!empty($userid)) {
+        $userfrom  = ", {$CFG->prefix}groups_members gm";
+        $userwhere = "AND g.id = gm.groupid AND gm.userid = '$userid'";
+    } else {
+        $userfrom  = "";
+        $userwhere = "";
+    }
 
+    if (!empty($groupingid)) {
+        $groupingfrom  = ", {$CFG->prefix}groupings_groups gg";
+        $groupingwhere = "AND g.id = gg.groupid AND gg.groupingid = '$groupingid'";
     } else {
-        return get_records_sql("SELECT g.*
-                                 FROM {$CFG->prefix}groups g,
-                                      {$CFG->prefix}groups_members m
-                                 WHERE g.courseid = '$courseid'
-                                   AND g.id = m.groupid
-                                   AND m.userid = '$userid'
-                                   ORDER BY name ASC");
+        $groupingfrom  = "";
+        $groupingwhere = "";
     }
+
+    return get_records_sql("SELECT g.*
+                              FROM {$CFG->prefix}groups g $userfrom $groupingfrom
+                             WHERE g.courseid = '$courseid' $userwhere $groupingwhere
+                          ORDER BY name ASC");
 }
 
 /**
@@ -84,5 +93,22 @@ function groups_is_member($groupid, $userid=null) {
     return record_exists('groups_members', 'groupid', $groupid, 'userid', $userid);
 }
 
+/**
+ * Returns the users in the specified group.
+ * @param int $groupid The groupid to get the users for
+ * @param int $sort optional sorting of returned users
+ * @return array | false Returns an array of the users for the specified
+ * group or false if no users or an error returned.
+ */
+function groups_get_members($groupid, $sort='lastname ASC') {
+    global $CFG;
+
+    return get_records_sql("SELECT u.*
+                              FROM {$CFG->prefix}user u, {$CFG->prefix}groups_members gm
+                             WHERE u.id = gm.userid AND gm.groupid = '$groupid'
+                          ORDER BY $sort");
+}
+
+
 
 ?>
index 7c54e34..3581353 100644 (file)
 
         case 'group':
             // group members
-            if ($memberids = groups_get_members($formdata['reportgroupid'])) { //TODO:check.
-                foreach ($memberids as $memberid) {
+            if ($members = groups_get_members($formdata['reportgroupid'])) {
+                foreach ($members as $memberid=>$unused) {
                     $users[$memberid] = 1; // "1" signifies currently recognized participant
                 }
             }
index 7814b27..c2e1cfe 100644 (file)
@@ -413,6 +413,17 @@ form.popupform label {
   width: 18em;
 }
 
+#group-groupings .buttons {
+  margin: 20px;
+  text-align:center;
+}
+
+#group-groupings .buttons .singlebutton {
+  display: inline;
+  padding: 5px;
+}
+
+
 img.icon {
   vertical-align:middle;
   margin-right:4px;