From: poltawski Date: Wed, 9 May 2007 00:06:29 +0000 (+0000) Subject: MDL-9742 - Converting tabs to spaces in groups code X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=dd87bde7742f7e7f22fa95bd758dfc5e00ef801b;p=moodle.git MDL-9742 - Converting tabs to spaces in groups code --- diff --git a/group/db/dbbasicgrouplib.php b/group/db/dbbasicgrouplib.php index 30faeade51..735a531489 100644 --- a/group/db/dbbasicgrouplib.php +++ b/group/db/dbbasicgrouplib.php @@ -25,8 +25,8 @@ require_once($CFG->dirroot.'/group/lib.php'); * @return object The user record */ function groups_db_get_user($userid) { - $query = get_record('user', 'id', $userid); - return $query; + $query = get_record('user', 'id', $userid); + return $query; } @@ -74,12 +74,12 @@ function groups_db_get_members($groupid) { $users = get_records('groups_members', 'groupid ', $groupid, '', $fields='id, userid'); if (!$users) { - $userids = false; + $userids = false; } else { - $userids = array(); - foreach ($users as $user) { - array_push($userids, $user->userid); - } + $userids = array(); + foreach ($users as $user) { + array_push($userids, $user->userid); + } } } return $userids; @@ -110,7 +110,7 @@ function groups_db_get_groups_for_user($userid, $courseid) { $groups = get_records_sql($sql); $groupids = groups_groups_to_groupids($groups); } - + return $groupids; } @@ -138,7 +138,7 @@ function groups_db_get_group_settings($groupid, $courseid=false, $alldata=false) } } - return $groupsettings; + return $groupsettings; } @@ -150,15 +150,15 @@ function groups_db_get_group_settings($groupid, $courseid=false, $alldata=false) * if an error occurred. */ function groups_db_users_in_common_group($userid1, $userid2) { - global $CFG; + global $CFG; $havecommongroup = false; - $sql = "SELECT gm1.groupid, 1 FROM {$CFG->prefix}groups_members gm1 " . - "INNER JOIN {$CFG->prefix}groups_members gm2 " . - "ON gm1.groupid = gm2.groupid" . - "WHERE gm1.userid = '$userid1' AND gm2.userid = '$userid2'"; + $sql = "SELECT gm1.groupid, 1 FROM {$CFG->prefix}groups_members gm1 " . + "INNER JOIN {$CFG->prefix}groups_members gm2 " . + "ON gm1.groupid = gm2.groupid" . + "WHERE gm1.userid = '$userid1' AND gm2.userid = '$userid2'"; $commongroups = get_record_sql($sql); if ($commongroups) { - $havecommongroup = true; + $havecommongroup = true; } return $havecommongroup; @@ -277,13 +277,13 @@ function groups_db_group_belongs_to_course($groupid, $courseid) { * @return int The id of the group created or false if the create failed. */ function groups_db_create_group($courseid, $groupsettings=false, $copytime=false) { - // Check we have a valid course id + // Check we have a valid course id if (!$courseid) { $groupid = false; } else { - $groupsettings = groups_set_default_group_settings($groupsettings); + $groupsettings = groups_set_default_group_settings($groupsettings); - $record = $groupsettings; + $record = $groupsettings; if (! $copytime) { $now = time(); $record->timecreated = $now; @@ -294,17 +294,17 @@ function groups_db_create_group($courseid, $groupsettings=false, $copytime=false if ($groupid != false) { $record2 = new Object(); - $record2->courseid = $courseid; - $record2->groupid = $groupid; + $record2->courseid = $courseid; + $record2->groupid = $groupid; if ($copytime) { $record2->timeadded = $record->timemodified; } else { $record2->timeadded = $now; } - $groupadded = insert_record('groups_courses_groups', $record2); - if (!$groupadded) { - $groupid = false; - } + $groupadded = insert_record('groups_courses_groups', $record2); + if (!$groupadded) { + $groupid = false; + } } } return $groupid; @@ -350,26 +350,26 @@ function groups_db_upgrade_group($courseid, $group) { * @return boolean True if user added successfully, false otherwise. */ function groups_db_add_member($groupid, $userid, $copytime=false) { - // Check that the user and group are valid + // Check that the user and group are valid if (!$userid or !$groupid or !groups_db_group_exists($groupid)) { $useradded = false; - // If the user is already a member of the group, just return success + // If the user is already a member of the group, just return success } elseif (groups_is_member($groupid, $userid)) { - $useradded = true; - } else { + $useradded = true; + } else { // Add the user to the group $record = new Object(); - $record->groupid = $groupid; - $record->userid = $userid; + $record->groupid = $groupid; + $record->userid = $userid; if ($copytime) { $record->timeadded = $copytime; } else { - $record->timeadded = time(); + $record->timeadded = time(); } - $useradded = insert_record($table = 'groups_members', $record); - } + $useradded = insert_record($table = 'groups_members', $record); + } - return $useradded; + return $useradded; } @@ -381,11 +381,11 @@ function groups_db_add_member($groupid, $userid, $copytime=false) { * @return boolean True if info was added successfully, false otherwise. */ function groups_db_set_group_settings($groupid, $groupsettings) { - $success = true; + $success = true; if (!$groupid or !$groupsettings or !groups_db_group_exists($groupid)) { $success = false; } else { - $record = $groupsettings; + $record = $groupsettings; $record->id = $groupid; $record->timemodified = time(); $result = update_record('groups', $record); @@ -395,7 +395,6 @@ function groups_db_set_group_settings($groupid, $groupsettings) { } return $success; - } /******************************************************************************* @@ -442,36 +441,36 @@ function groups_db_delete_group($groupid) { $userids = groups_db_get_members($groupid); if ($userids != false) { - foreach($userids as $userid) { - $userdeleted = groups_db_remove_member($userid, $groupid); - if (!$userdeleted) { - $success = false; - } - } + foreach($userids as $userid) { + $userdeleted = groups_db_remove_member($userid, $groupid); + if (!$userdeleted) { + $success = false; + } + } } // Remove any links with groupings to which the group belongs. //TODO: dbgroupinglib also seems to delete these links - duplication? - $groupingids = groups_get_groupings_for_group($groupid); - if ($groupingids != false) { - foreach($groupingids as $groupingid) { - $groupremoved = groups_remove_group_from_grouping($groupid, - $groupingid); - if(!$groupremoved) { - $success = false; - } - } - } + $groupingids = groups_get_groupings_for_group($groupid); + if ($groupingids != false) { + foreach($groupingids as $groupingid) { + $groupremoved = groups_remove_group_from_grouping($groupid, + $groupingid); + if(!$groupremoved) { + $success = false; + } + } + } // Remove links with courses. - $results = delete_records('groups_courses_groups', 'groupid', $groupid); - if ($results == false) { - $success = false; - } + $results = delete_records('groups_courses_groups', 'groupid', $groupid); + if ($results == false) { + $success = false; + } // Delete the group itself $results = delete_records($table = 'groups', $field1 = 'id', - $value1 = $groupid); + $value1 = $groupid); // delete_records returns an array of the results from the sql call, // not a boolean, so we have to set our return variable if ($results == false) { diff --git a/group/db/dbgroupinglib.php b/group/db/dbgroupinglib.php index 9971ba23a9..361c0e691d 100644 --- a/group/db/dbgroupinglib.php +++ b/group/db/dbgroupinglib.php @@ -28,15 +28,15 @@ function groups_db_get_groupings($courseid) { } else { $groupings = get_records('groups_courses_groupings', 'courseid ', $courseid, '', $fields='id, groupingid'); - if (!$groupings) { - $groupingids = false; - } else { - // Put the results into an array - $groupingids = array(); - foreach ($groupings as $grouping) { - array_push($groupingids, $grouping->groupingid); - } - } + if (!$groupings) { + $groupingids = false; + } else { + // Put the results into an array + $groupingids = array(); + foreach ($groupings as $grouping) { + array_push($groupingids, $grouping->groupingid); + } + } } return $groupingids; @@ -57,14 +57,14 @@ function groups_db_get_groups_in_grouping($groupingid) { $groups = get_records('groups_groupings_groups', 'groupingid ', $groupingid, '', $fields='id, groupid'); if (!$groups) { - $groupids = false; - } else { - // Put the results into an array - $groupids = array(); - foreach ($groups as $group) { - array_push($groupids, $group->groupid); - } - } + $groupids = false; + } else { + // Put the results into an array + $groupids = array(); + foreach ($groups as $group) { + array_push($groupids, $group->groupid); + } + } } return $groupids; @@ -78,23 +78,23 @@ function groups_db_get_groups_in_grouping($groupingid) { * or false if there are none or if an error occurred. */ function groups_db_get_groupings_for_group($groupid) { - if (!$groupid) { - $groupingids = false; - } else { - $groupings = get_records('groups_groupings_groups', 'groupid ', - $groupid, '', $fields='id, groupingid'); - if (!$groupings) { - $groupingids = false; - } else { - // Put the results into an array - $groupingids = array(); - foreach ($groupings as $grouping) { - array_push($groupingids, $grouping->groupingid); - } - } - } - - return $groupingids; + if (!$groupid) { + $groupingids = false; + } else { + $groupings = get_records('groups_groupings_groups', 'groupid ', + $groupid, '', $fields='id, groupingid'); + if (!$groupings) { + $groupingids = false; + } else { + // Put the results into an array + $groupingids = array(); + foreach ($groupings as $grouping) { + array_push($groupingids, $grouping->groupingid); + } + } + } + + return $groupingids; } @@ -125,7 +125,7 @@ function groups_db_get_grouping_settings($groupingid) { * or if an error occurred. */ function groups_db_get_grouping_for_coursemodule($cm) { - if (is_object($cm) and isset($cm->course) and isset($cm->groupingid)) { + if (is_object($cm) and isset($cm->course) and isset($cm->groupingid)) { //Do NOT rely on cm->module! return $cm->groupingid; } elseif (is_numeric($cm)) { @@ -265,7 +265,7 @@ function groups_db_create_grouping($courseid, $groupingsettings = false) { if (!$courseid or !groups_get_course_info($courseid)) { $groupingid = false; } else { - // Replace any empty groupsettings + // Replace any empty groupsettings $groupingsettings = groups_set_default_grouping_settings($groupingsettings); $record = $groupingsettings; $record->timecreated = time(); @@ -273,13 +273,13 @@ function groups_db_create_grouping($courseid, $groupingsettings = false) { $groupingid = insert_record('groups_groupings', $record); if ($groupingid != false) { $record2 = new Object(); - $record2->courseid = $courseid; - $record2->groupingid = $groupingid; - $record2->timeadded = time(); - $id= insert_record('groups_courses_groupings', $record2); - if (!$id) { - $groupingid = false; - } + $record2->courseid = $courseid; + $record2->groupingid = $groupingid; + $record2->timeadded = time(); + $id= insert_record('groups_courses_groupings', $record2); + if (!$id) { + $groupingid = false; + } } } @@ -320,13 +320,13 @@ function groups_db_add_group_to_grouping($groupid, $groupingid) { * @param object $groupingsettings */ function groups_db_set_grouping_settings($groupingid, $groupingsettings) { - $success = true; + $success = true; if (!$groupingid or !$groupingsettings or !groups_db_grouping_exists($groupingid)) { $success = false; } else { - // Replace any empty group settings. - $record = $groupingsettings; + // Replace any empty group settings. + $record = $groupingsettings; $record->id = $groupingid; $record->timemodified = time(); $result = update_record('groups_groupings', $record); @@ -346,19 +346,19 @@ function groups_db_set_grouping_settings($groupingid, $groupingsettings) { * @return boolean True if the operation was successful, false otherwise */ function groups_db_set_grouping_for_coursemodule($groupingid, $coursemoduleid) { - $success = true; - if (!$groupingid or !$coursemoduleid) { - $success = false; - } else { + $success = true; + if (!$groupingid or !$coursemoduleid) { + $success = false; + } else { $record = new Object(); - $record->id = $coursemoduleid; - $record->groupingid = $groupingid; - $result = update_record('course_modules', $record); - if (!$result) { - $success = false; - } - } - return $success; + $record->id = $coursemoduleid; + $record->groupingid = $groupingid; + $result = update_record('course_modules', $record); + if (!$result) { + $success = false; + } + } + return $success; } @@ -375,12 +375,12 @@ function groups_db_set_grouping_for_coursemodule($groupingid, $coursemoduleid) { * @return boolean True if the deletion was successful, false otherwise. */ function groups_db_remove_group_from_grouping($groupid, $groupingid) { - $success = true; + $success = true; if (!$groupingid or !$groupid) { $success = false; } else { $results = delete_records('groups_groupings_groups', 'groupid', - $groupid, 'groupingid', $groupingid); + $groupid, 'groupingid', $groupingid); // delete_records returns an array of the results from the sql call, // not a boolean, so we have to set our return variable if ($results == false) { @@ -399,7 +399,7 @@ function groups_db_remove_group_from_grouping($groupid, $groupingid) { * @return boolean True if the deletion was successful, false otherwise. */ function groups_db_delete_grouping($groupingid) { - $success = true; + $success = true; if (!$groupingid) { $success = false; } else { @@ -426,4 +426,4 @@ function groups_db_delete_grouping($groupingid) { } -?> \ No newline at end of file +?> diff --git a/group/db/dbsetup.php b/group/db/dbsetup.php index 973f799b8e..8c536720fe 100644 --- a/group/db/dbsetup.php +++ b/group/db/dbsetup.php @@ -46,7 +46,7 @@ require_once($CFG->libdir.'/datalib.php'); * Creates the database tables required */ function groups_create_database_tables() { - global $CFG; + global $CFG; if ('mysql' == $CFG->dbfamily) { @@ -202,57 +202,57 @@ function groups_create_database_tables() { * @param boolean True if the operation was successful, false otherwise. */ function groups_db_copy_moodle_group_to_imsgroup($groupid, $courseid) { - - $success = true; - - $groupsettings = get_record('groups', 'id ', $groupid, ''); - - // Only copy the group if the group exists. - if ($groupsettings != false) { + + $success = true; + + $groupsettings = get_record('groups', 'id ', $groupid, ''); + + // Only copy the group if the group exists. + if ($groupsettings != false) { $record = new Object(); - $record->name = $groupsettings->name; - $record->description = $groupsettings->description; - $record->password = $groupsettings->password; - $record->lang = $groupsettings->lang; - $record->theme = $groupsettings->theme; - $record->picture = $groupsettings->picture; - $record->hidepicture = $groupsettings->hidepicture; - $record->timecreated = $groupsettings->timecreated; - $record->timemodified = $groupsettings->timemodified; - - $newgroupid = insert_record('groups_groups', $record); - if (!$newgroupid) { - $success = false; - } + $record->name = $groupsettings->name; + $record->description = $groupsettings->description; + $record->password = $groupsettings->password; + $record->lang = $groupsettings->lang; + $record->theme = $groupsettings->theme; + $record->picture = $groupsettings->picture; + $record->hidepicture = $groupsettings->hidepicture; + $record->timecreated = $groupsettings->timecreated; + $record->timemodified = $groupsettings->timemodified; + + $newgroupid = insert_record('groups_groups', $record); + if (!$newgroupid) { + $success = false; + } $courserecord = new Object(); - $courserecord->courseid = $groupsettings->courseid; - $courserecord->groupid = $newgroupid; - - $added = insert_record('groups_courses_groups', $courserecord); - - if (!$added) { - $success = false; - } - - // Copy over the group members - $groupmembers = get_records('groups_users', 'groupid', $groupid); - if ($groupmembers != false) { - foreach($groupmembers as $member) { + $courserecord->courseid = $groupsettings->courseid; + $courserecord->groupid = $newgroupid; + + $added = insert_record('groups_courses_groups', $courserecord); + + if (!$added) { + $success = false; + } + + // Copy over the group members + $groupmembers = get_records('groups_users', 'groupid', $groupid); + if ($groupmembers != false) { + foreach($groupmembers as $member) { $record = new Object(); $record->groupid = $newgroupid; - $record->userid = $member->userid; - $useradded = insert_record('groups_groups_users', $record); - if (!$useradded) { - $success = false; - } - } - } - } - - if (!$success) { - notify('Copy operations from Moodle groups to IMS Groups failed'); - } + $record->userid = $member->userid; + $useradded = insert_record('groups_groups_users', $record); + if (!$useradded) { + $success = false; + } + } + } + } + + if (!$success) { + notify('Copy operations from Moodle groups to IMS Groups failed'); + } return $success; } diff --git a/group/groupui/createautomaticgrouping-form.html b/group/groupui/createautomaticgrouping-form.html index 2b0d071ead..282fe1c7ac 100644 --- a/group/groupui/createautomaticgrouping-form.html +++ b/group/groupui/createautomaticgrouping-form.html @@ -4,50 +4,50 @@ - - + +
-

-

-

-

-

-

-

-

-
-

- - - - - - - - - -
- -
  -

-

-
- - - - - - - - - - -
  -

-
- -

  -

-
+

+

+

+

+

+

+

+

+
+

+ + + + + + + + + +
+ +
  +

+

+
+ + + + + + + + + + +
  +

+
+ +

  +

+
diff --git a/group/groupui/creategroup-xml.php b/group/groupui/creategroup-xml.php index 95b3c86522..e69ed69f63 100644 --- a/group/groupui/creategroup-xml.php +++ b/group/groupui/creategroup-xml.php @@ -20,35 +20,35 @@ $groupsettings->hidepicture = optional_param('hidepicture', PARAM_INT); require_login($courseid); - + if (confirm_sesskey() and isteacheredit($courseid)) { - $groupid = groups_create_group($courseid, $groupsettings); - - if (!$groupid) { - echo 'Failed to create group'; - } else { - $groupadded = groups_add_group_to_grouping($groupid, $groupingid); - - if (!$groupadded) { - echo 'Failed to add group to grouping'; - } else { - // Upload a picture file if there was one - note that we don't remove any previous icons - require_once($CFG->libdir.'/uploadlib.php'); - $um = new upload_manager('newgroupicon', false, false, null, false, 0, true, true); - if ($um->preprocess_files()) { - require_once("$CFG->libdir/gdlib.php"); - if (save_profile_image($groupid, $um, 'groups')) { - $groupsettings->picture = 1; - $infoset = groups_set_group_settings($groupid, $groupsettings); - if (!$infoset) { - echo 'Failed to save the fact that the group image was uploaded'; - } - } - } - - echo ''.$groupid.''; - } - } + $groupid = groups_create_group($courseid, $groupsettings); + + if (!$groupid) { + echo 'Failed to create group'; + } else { + $groupadded = groups_add_group_to_grouping($groupid, $groupingid); + + if (!$groupadded) { + echo 'Failed to add group to grouping'; + } else { + // Upload a picture file if there was one - note that we don't remove any previous icons + require_once($CFG->libdir.'/uploadlib.php'); + $um = new upload_manager('newgroupicon', false, false, null, false, 0, true, true); + if ($um->preprocess_files()) { + require_once("$CFG->libdir/gdlib.php"); + if (save_profile_image($groupid, $um, 'groups')) { + $groupsettings->picture = 1; + $infoset = groups_set_group_settings($groupid, $groupsettings); + if (!$infoset) { + echo 'Failed to save the fact that the group image was uploaded'; + } + } + } + + echo ''.$groupid.''; + } + } } echo ''; diff --git a/group/groupui/editgroupsettings-xml.php b/group/groupui/editgroupsettings-xml.php index dff506c302..b4fcb70abe 100644 --- a/group/groupui/editgroupsettings-xml.php +++ b/group/groupui/editgroupsettings-xml.php @@ -18,32 +18,32 @@ $hidepicture = required_param('hidepicture', PARAM_INT); //TODO: PARAM_BOOL ?? $courseid = required_param('courseid', PARAM_INT); require_login($courseid); - + if (confirm_sesskey() and isteacheredit($courseid)) { - $groupsettings->name = $groupname; - $groupsettings->description = $description; - $groupsettings->enrolmentkey = $enrolmentkey; - $groupsettings->hidepicture = $hidepicture; - - // Upload the group icon if there is one - note that we don't remove any previous icons - require_once($CFG->libdir.'/uploadlib.php'); + $groupsettings->name = $groupname; + $groupsettings->description = $description; + $groupsettings->enrolmentkey = $enrolmentkey; + $groupsettings->hidepicture = $hidepicture; + + // Upload the group icon if there is one - note that we don't remove any previous icons + require_once($CFG->libdir.'/uploadlib.php'); $um = new upload_manager('groupicon', false, false, null, false, 0, true, true); if ($um->preprocess_files()) { - require_once("$CFG->libdir/gdlib.php"); + require_once("$CFG->libdir/gdlib.php"); if (save_profile_image($groupid, $um, 'groups')) { - $groupsettings->picture = 1; + $groupsettings->picture = 1; } else { - echo 'Failed to save group image'; + echo 'Failed to save group image'; } } else { - $groupsettings->picture = 0; + $groupsettings->picture = 0; } - - $infoset = groups_set_group_settings($groupid, $groupsettings); - if (!$infoset) { - echo "Failed to set new group settings"; - } + + $infoset = groups_set_group_settings($groupid, $groupsettings); + if (!$infoset) { + echo "Failed to set new group settings"; + } } echo ''; -?> \ No newline at end of file +?> diff --git a/group/groupui/getgroupingpermissions-xml.php b/group/groupui/getgroupingpermissions-xml.php index 4320343c5d..c2335b76c1 100644 --- a/group/groupui/getgroupingpermissions-xml.php +++ b/group/groupui/getgroupingpermissions-xml.php @@ -3,7 +3,7 @@ * Fetches the settings of a grouping and returns * them in an XML format **********************************************/ - + require_once('../../config.php'); require_once('../lib/lib.php'); @@ -15,48 +15,48 @@ $courseid = required_param('courseid', PARAM_INT); $groupingid = required_param('groupingid', PARAM_INT); require_login($courseid); - + if (confirm_sesskey() and isteacheredit($courseid)) { - $groupingsettings = groups_get_grouping_settings($groupingid); - echo ''.$groupingsettings->name.''; - - if ($groupingsettings->viewowngroup) { - echo 'true'; - } else { - echo 'false'; - } - - if ($groupingsettings->viewallgroupsmembers) { - echo 'true'; - } else { - echo 'false'; - } - - if ($groupingsettings->viewallgroupsactivities) { - echo 'true'; - } else { - echo 'false'; - } - - if ($groupingsettings->teachersgroupmark) { - echo 'true'; - } else { - echo 'false'; - } - - if ($groupingsettings->teachersgroupview) { - echo 'true'; - } else { - echo 'false'; - } - - if ($groupingsettings->teachersoverride) { - echo 'true'; - } else { - echo 'false'; - } - + $groupingsettings = groups_get_grouping_settings($groupingid); + echo ''.$groupingsettings->name.''; + + if ($groupingsettings->viewowngroup) { + echo 'true'; + } else { + echo 'false'; + } + + if ($groupingsettings->viewallgroupsmembers) { + echo 'true'; + } else { + echo 'false'; + } + + if ($groupingsettings->viewallgroupsactivities) { + echo 'true'; + } else { + echo 'false'; + } + + if ($groupingsettings->teachersgroupmark) { + echo 'true'; + } else { + echo 'false'; + } + + if ($groupingsettings->teachersgroupview) { + echo 'true'; + } else { + echo 'false'; + } + + if ($groupingsettings->teachersoverride) { + echo 'true'; + } else { + echo 'false'; + } + } echo ''; -?> \ No newline at end of file +?> diff --git a/group/groupui/getgroupings-xml.php b/group/groupui/getgroupings-xml.php index 8a993026bd..44821aa621 100644 --- a/group/groupui/getgroupings-xml.php +++ b/group/groupui/getgroupings-xml.php @@ -14,24 +14,24 @@ echo ''; $courseid = required_param('courseid', PARAM_INT); require_login($courseid); - + if (confirm_sesskey() and isteacheredit($courseid)) { - $groupingids = groups_get_groupings($courseid); - if ($groupingids != false) { - // Put the groupings into a hash and sort them - foreach($groupingids as $groupingid) { - $listgroupings[$groupingid] = groups_get_grouping_displayname($groupingid); - } - natcasesort($listgroupings); - - // Print out the XML - echo ''; - } + $groupingids = groups_get_groupings($courseid); + if ($groupingids != false) { + // Put the groupings into a hash and sort them + foreach($groupingids as $groupingid) { + $listgroupings[$groupingid] = groups_get_grouping_displayname($groupingid); + } + natcasesort($listgroupings); + + // Print out the XML + echo ''; + } } echo ''; diff --git a/group/groupui/getgroupsingrouping-xml.php b/group/groupui/getgroupsingrouping-xml.php index 60cd230718..bcec280273 100644 --- a/group/groupui/getgroupsingrouping-xml.php +++ b/group/groupui/getgroupsingrouping-xml.php @@ -14,26 +14,26 @@ $groupingid = required_param('groupingid', PARAM_INT); $courseid = required_param('courseid', PARAM_INT); require_login($courseid); - + if (confirm_sesskey() and isteacheredit($courseid)) { - $groupids = groups_get_groups_in_grouping($groupingid); - - if ($groupids != false) { - // Put the groupings into a hash and sort them - foreach($groupids as $groupid) { - $listgroups[$groupid] = groups_get_group_displayname($groupid); - } - - natcasesort($listgroups); - - // Print out the XML - echo ""; - } + $groupids = groups_get_groups_in_grouping($groupingid); + + if ($groupids != false) { + // Put the groupings into a hash and sort them + foreach($groupids as $groupid) { + $listgroups[$groupid] = groups_get_group_displayname($groupid); + } + + natcasesort($listgroups); + + // Print out the XML + echo ""; + } } echo ''; diff --git a/group/groupui/getgroupsnotingrouping-xml.php b/group/groupui/getgroupsnotingrouping-xml.php index de4c390c75..48531f610a 100644 --- a/group/groupui/getgroupsnotingrouping-xml.php +++ b/group/groupui/getgroupsnotingrouping-xml.php @@ -15,25 +15,25 @@ $groupingid = required_param('groupingid', PARAM_INT); $courseid = required_param('courseid', PARAM_INT); require_login($courseid); - + if (confirm_sesskey() and isteacheredit($courseid)) { - $groupids = groups_get_groups_not_in_grouping($groupingid, $courseid); - if ($groupids != false) { - // Put the groupings into a hash and sort them - foreach($groupids as $groupid) { - $listgroups[$groupid] = groups_get_group_displayname($groupid); - } - - natcasesort($listgroups); - - // Print out the XML - echo ""; - } + $groupids = groups_get_groups_not_in_grouping($groupingid, $courseid); + if ($groupids != false) { + // Put the groupings into a hash and sort them + foreach($groupids as $groupid) { + $listgroups[$groupid] = groups_get_group_displayname($groupid); + } + + natcasesort($listgroups); + + // Print out the XML + echo ""; + } } echo ''; diff --git a/group/groupui/getmembers-xml.php b/group/groupui/getmembers-xml.php index 7681d232fe..d738037d3c 100644 --- a/group/groupui/getmembers-xml.php +++ b/group/groupui/getmembers-xml.php @@ -15,28 +15,28 @@ $groupid = required_param('groupid', PARAM_INT); $courseid = required_param('courseid', PARAM_INT); require_login($courseid); - + if (confirm_sesskey() and isteacheredit($courseid)) { - $userids = groups_get_members($groupid); - - if ($userids != false) { - // Put the groupings into a hash and sort them - foreach($userids as $userid) { - $listmembers[$userid] = groups_get_user_displayname($userid, $courseid); - } - natcasesort($listmembers); - - - // Print out the XML - - echo ""; - } + $userids = groups_get_members($groupid); + + if ($userids != false) { + // Put the groupings into a hash and sort them + foreach($userids as $userid) { + $listmembers[$userid] = groups_get_user_displayname($userid, $courseid); + } + natcasesort($listmembers); + + + // Print out the XML + + echo ""; + } } echo ''; diff --git a/group/groupui/getnonmembers-xml.php b/group/groupui/getnonmembers-xml.php index ac00e3f399..3fc6d24113 100644 --- a/group/groupui/getnonmembers-xml.php +++ b/group/groupui/getnonmembers-xml.php @@ -18,32 +18,32 @@ $courseid = required_param('courseid', PARAM_INT); $showall = required_param('showall', PARAM_INT); require_login($courseid); - + if (confirm_sesskey() and isteacheredit($courseid)) { - echo "$groupingid $groupid"; - if ($showall == 0) { - $userids = groups_get_users_not_in_any_group_in_grouping($courseid,$groupingid, $groupid); - } else { - $userids = groups_get_users_not_in_group($courseid, $groupid); - } - - if ($userids != false) { - // Put the groupings into a hash and sorts them - foreach($userids as $userid) { - $listmembers[$userid] = groups_get_user_displayname($userid, $courseid); - } - natcasesort($listmembers); - - - // Print out the XML - echo ""; - } - } + echo "$groupingid $groupid"; + if ($showall == 0) { + $userids = groups_get_users_not_in_any_group_in_grouping($courseid,$groupingid, $groupid); + } else { + $userids = groups_get_users_not_in_group($courseid, $groupid); + } + + if ($userids != false) { + // Put the groupings into a hash and sorts them + foreach($userids as $userid) { + $listmembers[$userid] = groups_get_user_displayname($userid, $courseid); + } + natcasesort($listmembers); + + + // Print out the XML + echo ""; + } +} echo ''; ?> diff --git a/group/groupui/index.php b/group/groupui/index.php index 48f3181cd8..1210e779c3 100644 --- a/group/groupui/index.php +++ b/group/groupui/index.php @@ -27,38 +27,38 @@ if (!$course) { if (!$error) { - // Make sure that the user is a teacher with edit permission for this course - require_login($courseid); - if (!isteacheredit($courseid)) { - redirect(); - } + // Make sure that the user is a teacher with edit permission for this course + require_login($courseid); + if (!isteacheredit($courseid)) { + redirect(); + } - // Set the session key so we can check this later - $sesskey = !empty($USER->id) ? $USER->sesskey : ''; + // Set the session key so we can check this later + $sesskey = !empty($USER->id) ? $USER->sesskey : ''; - if (!empty($CFG->gdversion)) { //TODO: and $maxbytes) - $printuploadpicture = true; - } else { - $printuploadpicture = false; - } + if (!empty($CFG->gdversion)) { //TODO: and $maxbytes) + $printuploadpicture = true; + } else { + $printuploadpicture = false; + } - $maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes); - $strgroups = get_string('groups'); - $strparticipants = get_string('participants'); - // Print the page and form - print_header("$course->shortname: $strgroups", - $course->fullname, - "wwwroot/course/view.php?id=$courseid\">$course->shortname ". - "-> wwwroot/user/index.php?id=$courseid\">$strparticipants ". - "-> $strgroups", "", "", true, '', user_login_string($course, $USER)); + $maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes); + $strgroups = get_string('groups'); + $strparticipants = get_string('participants'); + // Print the page and form + print_header("$course->shortname: $strgroups", + $course->fullname, + "wwwroot/course/view.php?id=$courseid\">$course->shortname ". + "-> wwwroot/user/index.php?id=$courseid\">$strparticipants ". + "-> $strgroups", "", "", true, '', user_login_string($course, $USER)); //TODO: set to false in /course/group.php $usehtmleditor = false; - require_once('form.html'); + require_once('form.html'); - print_footer($course); + print_footer($course); } -?> \ No newline at end of file +?> diff --git a/group/groupui/printgrouping.php b/group/groupui/printgrouping.php index 726f60a4ed..010585c9ea 100644 --- a/group/groupui/printgrouping.php +++ b/group/groupui/printgrouping.php @@ -33,56 +33,56 @@ if ($success) { redirect(); } - //( confirm_sesskey checks that this is a POST request.) + //( confirm_sesskey checks that this is a POST request.) - // Print the page and form - $strgroups = get_string('groups'); - $strparticipants = get_string('participants'); - print_header("$course->shortname: $strgroups", $course->fullname, - "wwwroot/course/view.php?id=$courseid\">$course->shortname ". - "-> wwwroot/user/index.php?id=$courseid\">$strparticipants ". - "-> wwwroot/group/groupui/index.php?id=$courseid\">$strgroups". - "-> Display grouping", "", "", true, '', user_login_string($course, $USER)); + // Print the page and form + $strgroups = get_string('groups'); + $strparticipants = get_string('participants'); + print_header("$course->shortname: $strgroups", $course->fullname, + "wwwroot/course/view.php?id=$courseid\">$course->shortname ". + "-> wwwroot/user/index.php?id=$courseid\">$strparticipants ". + "-> wwwroot/group/groupui/index.php?id=$courseid\">$strgroups". + "-> Display grouping", "", "", true, '', user_login_string($course, $USER)); $groupingname = groups_get_grouping_name($groupingid); if (! $groupingname) { print_error('errorinvalidgrouping', 'group', groups_home_url($courseid)); } else { // Print the name of the grouping - echo "

$groupingname

\n"; + echo "

$groupingname

\n"; } - // Get the groups and group members for the grouping. + // Get the groups and group members for the grouping. if (GROUP_NOT_IN_GROUPING == $groupingid) { $groupids = groups_get_groups_not_in_any_grouping($courseid); } else { $groupids = groups_get_groups_in_grouping($groupingid); } - if ($groupids) { - // Make sure the groups are in the right order - $group_names = groups_groupids_to_group_names($groupids); - + if ($groupids) { + // Make sure the groups are in the right order + $group_names = groups_groupids_to_group_names($groupids); + // Go through each group in turn and print the group name and then the members foreach ($group_names as $group) { - echo "

{$group->name}

\n"; - $userids = groups_get_members($group->id); - if ($userids != false) { - // Make sure the users are in the right order - $user_names = groups_userids_to_user_names($userids, $courseid); + echo "

{$group->name}

\n"; + $userids = groups_get_members($group->id); + if ($userids != false) { + // Make sure the users are in the right order + $user_names = groups_userids_to_user_names($userids, $courseid); echo "
    \n"; foreach ($user_names as $user) { - echo "
  1. {$user->name}
  2. \n"; - } + echo "
  3. {$user->name}
  4. \n"; + } echo "
\n"; - } - } - } + } + } + } print_footer($course); } -?> \ No newline at end of file +?> diff --git a/group/lib/automaticgroupinglib.php b/group/lib/automaticgroupinglib.php index f648b8be28..602a402f4d 100644 --- a/group/lib/automaticgroupinglib.php +++ b/group/lib/automaticgroupinglib.php @@ -14,8 +14,8 @@ * groups_create_automatic_grouping more than once. */ function groups_seed_random_number_generator() { - $seed = (double)microtime()*1234567 ; - srand($seed); + $seed = (double)microtime()*1234567 ; + srand($seed); } @@ -57,68 +57,68 @@ function groups_create_automatic_grouping($courseid, $nostudentspergroup, $groupingsettings, $groupid = false, $alphabetical = false) { - - if (!$nostudentspergroup and !$noteacherspergroup and !$nogroups) { - $groupingid = false; - } else { - // Set $userids to the list of students that we want to put into groups - // in the grouping - if (!$groupid) { - $users = get_course_students($courseid); - $userids = groups_users_to_userids($users); - } else { - $userids = groups_get_members($groupid); - } - - // Distribute the users into sets according to the parameters specified - $userarrays = groups_distribute_in_random_sets($userids, - $nostudentspergroup, $nogroups, $distribevenly, !$alphabetical); - - if (!$userarrays) { - $groupingid = false; - } else { - // Create the grouping that the groups we create will go into - $groupingid = groups_create_grouping($courseid, $groupingsettings); - - // Get the prefix for the names of each group and default group - // description to give each group - if (!$groupingsettings->prefix) { - $prefix = get_string('defaultgroupprefix', 'groups'); - } else { - $prefix = $groupingsettings->prefix; - } - - if (!$groupingsettings->defaultgroupdescription) { - $defaultgroupdescription = ''; - } else { - $defaultgroupdescription = $groupingsettings->defaultgroupdescription; - } - - // Now create a group for each set of students, add the group to the - // grouping and then add the students - $i = 1; - foreach ($userarrays as $userids) { - $groupsettings->name = $prefix.' '.$i; - $groupsettings->description = $defaultgroupdescription; - $i++; - $groupid = groups_create_group($courseid, $groupsettings); - $groupadded = groups_add_group_to_grouping($groupid, - $groupingid); - if (!$groupid or !$groupadded) { - $groupingid = false; - } else { - if ($userids) { - foreach($userids as $userid) { - $usersadded = groups_add_member($groupid, $userid); - // If unsuccessful just carry on I guess - } - } - } - } - } - } + + if (!$nostudentspergroup and !$noteacherspergroup and !$nogroups) { + $groupingid = false; + } else { + // Set $userids to the list of students that we want to put into groups + // in the grouping + if (!$groupid) { + $users = get_course_students($courseid); + $userids = groups_users_to_userids($users); + } else { + $userids = groups_get_members($groupid); + } + + // Distribute the users into sets according to the parameters specified + $userarrays = groups_distribute_in_random_sets($userids, + $nostudentspergroup, $nogroups, $distribevenly, !$alphabetical); + + if (!$userarrays) { + $groupingid = false; + } else { + // Create the grouping that the groups we create will go into + $groupingid = groups_create_grouping($courseid, $groupingsettings); + + // Get the prefix for the names of each group and default group + // description to give each group + if (!$groupingsettings->prefix) { + $prefix = get_string('defaultgroupprefix', 'groups'); + } else { + $prefix = $groupingsettings->prefix; + } + + if (!$groupingsettings->defaultgroupdescription) { + $defaultgroupdescription = ''; + } else { + $defaultgroupdescription = $groupingsettings->defaultgroupdescription; + } + + // Now create a group for each set of students, add the group to the + // grouping and then add the students + $i = 1; + foreach ($userarrays as $userids) { + $groupsettings->name = $prefix.' '.$i; + $groupsettings->description = $defaultgroupdescription; + $i++; + $groupid = groups_create_group($courseid, $groupsettings); + $groupadded = groups_add_group_to_grouping($groupid, + $groupingid); + if (!$groupid or !$groupadded) { + $groupingid = false; + } else { + if ($userids) { + foreach($userids as $userid) { + $usersadded = groups_add_member($groupid, $userid); + // If unsuccessful just carry on I guess + } + } + } + } + } + } return $groupingid; -} + } /** @@ -145,35 +145,35 @@ function groups_distribute_in_random_sets($array, $setsize, $nosets, $distribevenly = true, $randomise = true) { $noelements = count($array); - - // Create a list of the numbers 1,..., $noelements, in either random order - // or in numerical order depending on whether $randomise has been set. + + // Create a list of the numbers 1,..., $noelements, in either random order + // or in numerical order depending on whether $randomise has been set. if ($randomise) { - $orderarray = groups_random_list($noelements); + $orderarray = groups_random_list($noelements); } else { - // Just create the array (1,2,3,....) - $orderarray = array(); - for($i = 0; $i < $noelements; $i++) { - array_push($orderarray, $i); - } + // Just create the array (1,2,3,....) + $orderarray = array(); + for($i = 0; $i < $noelements; $i++) { + array_push($orderarray, $i); + } } - + // Now use the ordering in $orderarray to generate the new arrays $arrayofrandomsets = array(); // for ($i = 0; $i < $noelements; $i++) { - $arrayofrandomsets[$arrayno][$i] = $array[$orderarray[$i]]; + $arrayofrandomsets[$arrayno][$i] = $array[$orderarray[$i]]; if (groups_last_element_in_set($noelements, $setsize, $nosets, - $distribevenly, $i) - and $i != $noelements - 1) { - $arrayno++; - $arrayofrandomsets[$arrayno] = array(); - } - + $distribevenly, $i) + and $i != $noelements - 1) { + $arrayno++; + $arrayofrandomsets[$arrayno] = array(); + } + } - + return $arrayofrandomsets; -} + } /** * Returns an array of the numbers 0,..,$size - 1 in random order @@ -181,7 +181,7 @@ function groups_distribute_in_random_sets($array, $setsize, $nosets, * @return array The array of numbers in a random order */ function groups_random_list($size) { - $orderarray = array(); + $orderarray = array(); $noelementsset = 0; while($noelementsset != $size) { $newelement = rand() % $size; @@ -210,42 +210,42 @@ function groups_random_list($size) { */ function groups_last_element_in_set($totalnoelements, $setsize, $nosets, $distribevenly, $elementno) { - $lastelement = false; - $elementno = $elementno + 1; // Counting from zero is just too confusing! - - // If $nosets has been specified, make sure $setsize is set to the right - // value, so that we can treat the two cases identically. Then work out how - // many extra elements will be left over. - if (!$setsize) { - $setsize = floor($totalnoelements / $nosets); - $noextra = $totalnoelements % $nosets; - } else { - $noextra = $totalnoelements % $setsize; - } - + $lastelement = false; + $elementno = $elementno + 1; // Counting from zero is just too confusing! + + // If $nosets has been specified, make sure $setsize is set to the right + // value, so that we can treat the two cases identically. Then work out how + // many extra elements will be left over. + if (!$setsize) { + $setsize = floor($totalnoelements / $nosets); + $noextra = $totalnoelements % $nosets; + } else { + $noextra = $totalnoelements % $setsize; + } + if (!$distribevenly) { - // If we're putting our extra elements in a set at the end, everything - // is easy! - if ($elementno % $setsize == 0) { - $lastelement = true; - } + // If we're putting our extra elements in a set at the end, everything + // is easy! + if ($elementno % $setsize == 0) { + $lastelement = true; + } } else { - // Work out the number of elements that will be in the bigger sets that - // have the leftover elements in - // them. - $noinbiggersets = $noextra * ($setsize + 1); - // Work out if this element is a last element in a set or not - we need - // to separate the case where the element is one of the ones that goes - // into the bigger sets at the beginning - // and the case where it's one of the elements in the normal sized sets. - if (($elementno <= $noinbiggersets and $elementno % ($setsize + 1) == 0) - or ($elementno > $noinbiggersets and - ($elementno - $noinbiggersets ) % $setsize == 0) ) { - $lastelement = true; - } - } + // Work out the number of elements that will be in the bigger sets that + // have the leftover elements in + // them. + $noinbiggersets = $noextra * ($setsize + 1); + // Work out if this element is a last element in a set or not - we need + // to separate the case where the element is one of the ones that goes + // into the bigger sets at the beginning + // and the case where it's one of the elements in the normal sized sets. + if (($elementno <= $noinbiggersets and $elementno % ($setsize + 1) == 0) + or ($elementno > $noinbiggersets and + ($elementno - $noinbiggersets ) % $setsize == 0) ) { + $lastelement = true; + } + } return $lastelement; -} + } -?> \ No newline at end of file +?> diff --git a/group/lib/basicgrouplib.php b/group/lib/basicgrouplib.php index d9874eb3e3..2f3c6d81b7 100644 --- a/group/lib/basicgrouplib.php +++ b/group/lib/basicgrouplib.php @@ -34,7 +34,7 @@ require_once($CFG->dirroot.'/group/db/dbbasicgrouplib.php'); * or an error occurred. */ function groups_get_groups($courseid) { - $groupids = groups_db_get_groups($courseid); + $groupids = groups_db_get_groups($courseid); return $groupids; } @@ -49,7 +49,7 @@ function groups_get_groups($courseid) { * group or false if no users or an error returned. */ function groups_get_members($groupid, $membertype = false) { - $userids = groups_db_get_members($groupid); + $userids = groups_db_get_members($groupid); return $userids; } @@ -108,9 +108,9 @@ function groups_get_all_groups_for_user($userid) { * @return array An array of the groupids. */ function groups_get_groups_for_current_user($courseid) { - global $USER; - $groupids = groups_get_groups_for_user($USER->id, $courseid); - return $groupids; + global $USER; + $groupids = groups_get_groups_for_user($USER->id, $courseid); + return $groupids; } @@ -122,7 +122,7 @@ function groups_get_groups_for_current_user($courseid) { * @return object The group settings object */ function groups_get_group_settings($groupid, $courseid=false, $alldata=false) { - return groups_db_get_group_settings($groupid, $courseid, $alldata); + return groups_db_get_group_settings($groupid, $courseid, $alldata); } /** @@ -133,7 +133,7 @@ function groups_get_group_settings($groupid, $courseid=false, $alldata=false) { */ function groups_get_group_image_path($groupid) { //TODO: groupid=1, /user/pixgroup.php/1/f1.jpg ?? - return $CFG->wwwroot.'/pixgroup.php/'.$groupid.'/f1.jpg'; + return $CFG->wwwroot.'/pixgroup.php/'.$groupid.'/f1.jpg'; } /** @@ -142,8 +142,8 @@ function groups_get_group_image_path($groupid) { * @return string The name of the group */ function groups_get_group_name($groupid) { - $settings = groups_get_group_settings($groupid); - if ($settings) { + $settings = groups_get_group_settings($groupid); + if ($settings) { return $settings->name; } return false; @@ -156,14 +156,14 @@ function groups_get_group_name($groupid) { * an error occurred. */ function groups_get_users_not_in_group($courseid, $groupid) { - $users = get_course_users($courseid); + $users = get_course_users($courseid); $userids = groups_users_to_userids($users); $nongroupmembers = array(); - foreach($userids as $userid) { - if (!groups_is_member($groupid, $userid)) { - array_push($nongroupmembers, $userid); - } + foreach($userids as $userid) { + if (!groups_is_member($groupid, $userid)) { + array_push($nongroupmembers, $userid); + } } return $nongroupmembers; @@ -177,7 +177,7 @@ function groups_get_users_not_in_group($courseid, $groupid) { * if an error occurred. */ function groups_users_in_common_group($userid1, $userid2) { - return groups_db_users_in_common_group($userid1, $userid2); + return groups_db_users_in_common_group($userid1, $userid2); } @@ -193,7 +193,7 @@ function groups_users_in_common_group($userid1, $userid2) { * occurred. */ function groups_group_exists($groupid) { - return groups_db_group_exists($groupid); + return groups_db_group_exists($groupid); } @@ -277,12 +277,12 @@ function groups_set_default_group_settings($groupinfo = null) { } if (isset($groupinfo->hidepicture)) { - if ($groupinfo->hidepicture != 0 and $groupinfo->hidepicture != 1) { - $groupinfo->hidepicture = 1; - } + if ($groupinfo->hidepicture != 0 and $groupinfo->hidepicture != 1) { + $groupinfo->hidepicture = 1; + } } - return $groupinfo; + return $groupinfo; } /***************************** @@ -301,8 +301,8 @@ function groups_set_default_group_settings($groupinfo = null) { * not created successfully. * See comment above on web service autoupdating. */ -function groups_create_group($courseid, $groupsettings = false) { - return groups_db_create_group($courseid, $groupsettings); +function groups_create_group($courseid, $groupsettings = false) { + return groups_db_create_group($courseid, $groupsettings); } /** @@ -321,8 +321,8 @@ function groups_restore_group($courseid, $groupsettings) { * following properties: name, description, lang, theme, picture, hidepicture * @return boolean True if info was added successfully, false otherwise. */ -function groups_set_group_settings($groupid, $groupsettings) { - return groups_db_set_group_settings($groupid, $groupsettings); +function groups_set_group_settings($groupid, $groupsettings) { + return groups_db_set_group_settings($groupid, $groupsettings); } @@ -335,20 +335,20 @@ function groups_set_group_settings($groupid, $groupsettings) { * See comment above on web service autoupdating. */ function groups_add_member($groupid, $userid) { - $useradded = false; - + $useradded = false; + $alreadymember = groups_is_member($groupid, $userid); if (!groups_group_exists($groupid)) { - $useradded = false; + $useradded = false; } elseif ($alreadymember) { - $useradded = true; + $useradded = true; } else { - $useradded = groups_db_add_member($groupid, $userid); + $useradded = groups_db_add_member($groupid, $userid); } if ($useradded) { $useradded = groups_db_set_group_modified($groupid); } - return $useradded; + return $useradded; } /** @@ -395,7 +395,7 @@ function groups_delete_group($groupid) { * See comment above on web service autoupdating. */ function groups_remove_member($groupid, $userid) { - $success = groups_db_remove_member($groupid, $userid); + $success = groups_db_remove_member($groupid, $userid); if ($success) { $success = groups_db_set_group_modified($groupid); } diff --git a/group/lib/groupinglib.php b/group/lib/groupinglib.php index c882a8a95f..42416926a2 100644 --- a/group/lib/groupinglib.php +++ b/group/lib/groupinglib.php @@ -77,7 +77,7 @@ function groups_get_groups_in_grouping_records($groupingid) { * or false if there are none or if an error occurred. */ function groups_get_groupings_for_group($groupid) { - return groups_db_get_groupings_for_group($groupid); + return groups_db_get_groupings_for_group($groupid); } /** @@ -87,7 +87,7 @@ function groups_get_groupings_for_group($groupid) { * description. */ function groups_get_grouping_settings($groupingid) { - return groups_db_get_grouping_settings($groupingid); + return groups_db_get_grouping_settings($groupingid); } /** @@ -96,7 +96,7 @@ function groups_get_grouping_settings($groupingid) { * @param object $groupingsettings */ function groups_set_grouping_settings($groupingid, $groupingsettings) { - return groups_db_set_grouping_settings($groupingid, $groupingsettings); + return groups_db_set_grouping_settings($groupingid, $groupingsettings); } @@ -192,25 +192,25 @@ function groups_get_groups_not_in_any_grouping($courseid) { * the grouping or false if an error occurred. */ function groups_get_users_not_in_any_group_in_grouping($courseid, $groupingid, - $groupid = false) { - $users = get_course_users($courseid); - $userids = groups_users_to_userids($users); - $nongroupmembers = array(); - if (! $userids) { - return $nongroupmembers; - } - foreach($userids as $userid) { - if (!groups_is_member_of_some_group_in_grouping($userid, $groupingid)) { - // If a group has been specified don't include members of that group - if ($groupid and !groups_is_member($userid, $groupid)) { - array_push($nongroupmembers, $userid); - } else { - ///array_push($nongroupmembers, $userid); - } + $groupid = false) { + $users = get_course_users($courseid); + $userids = groups_users_to_userids($users); + $nongroupmembers = array(); + if (! $userids) { + return $nongroupmembers; } + foreach($userids as $userid) { + if (!groups_is_member_of_some_group_in_grouping($userid, $groupingid)) { + // If a group has been specified don't include members of that group + if ($groupid and !groups_is_member($userid, $groupid)) { + array_push($nongroupmembers, $userid); + } else { + ///array_push($nongroupmembers, $userid); + } + } + } + return $nongroupmembers; } - return $nongroupmembers; -} /** @@ -221,21 +221,21 @@ function groups_get_users_not_in_any_group_in_grouping($courseid, $groupingid, * or if an error occurred. */ function groups_user_is_in_multiple_groups($userid, $groupingid) { - $inmultiplegroups = false; + $inmultiplegroups = false; //TODO: $courseid? - $groupids = groups_get_groups_for_user($courseid); - if ($groupids != false) { - $groupinggroupids = array(); - foreach($groupids as $groupid) { - if (groups_belongs_to_grouping($groupid, $groupingid)) { - array_push($groupinggroupids, $groupid); - } - } - if (count($groupinggroupids) > 1) { - $inmultiplegroups = true; - } - } - return $inmultiplegroups; + $groupids = groups_get_groups_for_user($courseid); + if ($groupids != false) { + $groupinggroupids = array(); + foreach($groupids as $groupid) { + if (groups_belongs_to_grouping($groupid, $groupingid)) { + array_push($groupinggroupids, $groupid); + } + } + if (count($groupinggroupids) > 1) { + $inmultiplegroups = true; + } + } + return $inmultiplegroups; } @@ -256,30 +256,30 @@ function groups_set_default_grouping_settings($groupingsettings = null) { } if (!isset($groupingsettings->viewowngroup)) { - $groupingsettings->viewowngroup = 1; + $groupingsettings->viewowngroup = 1; } if (!isset($groupingsettings->viewallgroupsmembers)) { - $groupingsettings->viewallgroupsmembers = 0; + $groupingsettings->viewallgroupsmembers = 0; } if (!isset($groupingsettings->viewallgroupsactivities)) { - $groupingsettings->viewallgroupsactivities = 0; + $groupingsettings->viewallgroupsactivities = 0; } if (!isset($groupingsettings->teachersgroupmark)) { - $groupingsettings->teachersgroupmark = 0; + $groupingsettings->teachersgroupmark = 0; } if (!isset($groupingsettings->teachersgroupview)) { - $groupingsettings->teachersgroupview = 0; + $groupingsettings->teachersgroupview = 0; } if (!isset($groupingsettings->teachersoverride)) { - $groupingsettings->teachersoverride = 1; + $groupingsettings->teachersoverride = 1; } - return $groupingsettings; + return $groupingsettings; } @@ -290,7 +290,7 @@ function groups_set_default_grouping_settings($groupingsettings = null) { * or if an error occurred. */ function groups_get_grouping_for_coursemodule($coursemodule) { - return groups_db_get_grouping_for_coursemodule($coursemodule); + return groups_db_get_grouping_for_coursemodule($coursemodule); } /***************************** @@ -304,7 +304,7 @@ function groups_get_grouping_for_coursemodule($coursemodule) { * @return True if the grouping exists, false otherwise or if an error occurred. */ function groups_grouping_exists($groupingid) { - return groups_db_grouping_exists($groupingid); + return groups_db_grouping_exists($groupingid); } /** @@ -329,43 +329,43 @@ function groups_grouping_matches($courseid, $gg_name, $gg_description) { } /** - * Determines if a group belongs to a specified grouping - * @param int $groupid The id of the group - * @param int $groupingid The id of the grouping - * @return boolean. True if the group belongs to a grouping, false otherwise or - * if an error has occurred. - */ - function groups_belongs_to_grouping($groupid, $groupingid) { - return groups_db_belongs_to_grouping($groupid, $groupingid); - } - - - /** - * Detemines if a specified user belongs to any group of a specified grouping. - * @param int $userid The id of the user - * @param int $groupingid The id of the grouping - * @return boolean True if the user belongs to some group in the grouping, - * false otherwise or if an error occurred. - */ - function groups_is_member_of_some_group_in_grouping($userid, $groupingid) { - return groups_db_is_member_of_some_group_in_grouping($userid, $groupingid); - } - - /** - * Determines if a grouping belongs to a specified course - * @param int $groupingid The id of the grouping - * @param int $courseid The id of the course - * @return boolean True if the grouping belongs to the course, false otherwise, - * or if an error occurred. - */ - function groups_grouping_belongs_to_course($groupingid, $courseid) { - return groups_db_grouping_belongs_to_course($groupingid, $courseid); - } + * Determines if a group belongs to a specified grouping + * @param int $groupid The id of the group + * @param int $groupingid The id of the grouping + * @return boolean. True if the group belongs to a grouping, false otherwise or + * if an error has occurred. + */ +function groups_belongs_to_grouping($groupid, $groupingid) { + return groups_db_belongs_to_grouping($groupid, $groupingid); +} + + +/** + * Detemines if a specified user belongs to any group of a specified grouping. + * @param int $userid The id of the user + * @param int $groupingid The id of the grouping + * @return boolean True if the user belongs to some group in the grouping, + * false otherwise or if an error occurred. + */ +function groups_is_member_of_some_group_in_grouping($userid, $groupingid) { + return groups_db_is_member_of_some_group_in_grouping($userid, $groupingid); +} + +/** + * Determines if a grouping belongs to a specified course + * @param int $groupingid The id of the grouping + * @param int $courseid The id of the course + * @return boolean True if the grouping belongs to the course, false otherwise, + * or if an error occurred. + */ +function groups_grouping_belongs_to_course($groupingid, $courseid) { + return groups_db_grouping_belongs_to_course($groupingid, $courseid); +} /***************************** Creation functions - *****************************/ +*****************************/ /** @@ -396,19 +396,19 @@ function groups_create_grouping($courseid, $groupingsettings = false) { * doesn't belong to the same course as the grouping. */ function groups_add_group_to_grouping($groupid, $groupingid) { - if (GROUP_NOT_IN_GROUPING == $groupingid) { + if (GROUP_NOT_IN_GROUPING == $groupingid) { return true; } $belongstogrouping = groups_belongs_to_grouping($groupid, $groupingid); - + if (!groups_grouping_exists($groupingid)) { - $groupadded = false; - } elseif (!$belongstogrouping) { - $groupadded = groups_db_add_group_to_grouping($groupid, $groupingid); - } else { - $groupadded = true; - } - + $groupadded = false; + } elseif (!$belongstogrouping) { + $groupadded = groups_db_add_group_to_grouping($groupid, $groupingid); + } else { + $groupadded = true; + } + return $groupadded; } @@ -433,8 +433,8 @@ function groups_set_grouping_name($groupingid, $name) { * @return boolean True if the operation was successful, false otherwise */ function groups_set_grouping_for_coursemodule($groupingid, $coursemoduleid) { - return groups_db_set_grouping_for_coursemodule($groupingid, - $coursemoduleid); + return groups_db_set_grouping_for_coursemodule($groupingid, + $coursemoduleid); } diff --git a/group/lib/legacylib.php b/group/lib/legacylib.php index ddaa9f3b1b..0959aa65e6 100644 --- a/group/lib/legacylib.php +++ b/group/lib/legacylib.php @@ -25,7 +25,7 @@ * @return int $groupid */ function groups_get_group_by_name($courseid, $groupname) { - //uploaduser.php, get_record("groups","courseid",$course[$i]->id,"name",$addgroup[$i]) + //uploaduser.php, get_record("groups","courseid",$course[$i]->id,"name",$addgroup[$i]) $groupids = groups_db_get_groups($courseid); if (! $groupids) { return false; @@ -50,13 +50,13 @@ function groups_get_group_by_name($courseid, $groupname) { * @return object */ function get_groups($courseid, $userid=0) { - if ($userid) { - $groupids = groups_get_groups_for_user($userid, $courseid); - } else { - $groupids = groups_get_groups($courseid); - } + if ($userid) { + $groupids = groups_get_groups_for_user($userid, $courseid); + } else { + $groupids = groups_get_groups($courseid); + } - return groups_groupids_to_groups($groupids, $courseid, $alldata=true); + return groups_groupids_to_groups($groupids, $courseid, $alldata=true); } @@ -84,7 +84,7 @@ function user_group($courseid, $userid) { * @return boolean True if the user is a member, false otherwise. */ function ismember($groupid, $userid = null) { - return groups_is_member($groupid, $userid); + return groups_is_member($groupid, $userid); } /** @@ -146,8 +146,8 @@ function add_user_to_group($groupid, $userid) { */ function mygroupid($courseid) { global $USER; - $groupids = groups_get_groups_for_user($USER->id, $courseid); - return $groupids; + $groupids = groups_get_groups_for_user($USER->id, $courseid); + return $groupids; } /** @@ -161,12 +161,12 @@ function groupmode($course, $cm=null) { return $cm->groupmode; } return $course->groupmode; - + /*if ($cm and !$course->groupingid) { //TODO: was $coursemodule return groups_has_groups_setup_for_instance($cm); } else { - return groups_has_groups_setup($course->id); + return groups_has_groups_setup($course->id); }*/ } @@ -207,13 +207,13 @@ function get_current_group($courseid, $full = false) { } if (isset($SESSION->currentgroup[$courseid])) { - $currentgroup = $SESSION->currentgroup[$courseid]; + $currentgroup = $SESSION->currentgroup[$courseid]; } else { - $currentgroup = $mygroupid; + $currentgroup = $mygroupid; } - + if ($currentgroup) { - $SESSION->currentgroup[$courseid] = $mygroupid; + $SESSION->currentgroup[$courseid] = $mygroupid; } if ($full) { @@ -239,9 +239,9 @@ function get_current_group($courseid, $full = false) { * @return int|false Returns the current group id or false if error. */ function get_and_set_current_group($course, $groupmode, $groupid=-1) { - //TODO: ?? groups_has_permission($userid, $groupingid, $courseid, $groupid, $permissiontype); + //TODO: ?? groups_has_permission($userid, $groupingid, $courseid, $groupid, $permissiontype); - // Sets to the specified group, provided the current user has view permission + // Sets to the specified group, provided the current user has view permission if (!$groupmode) { // Groups don't even apply return false; } @@ -339,9 +339,9 @@ function groups_instance_print_group_selector() { function oldgroups_print_user_group_info($currentgroup, $isseparategroups, $courseid) { - global $CFG; - $context = get_context_instance(CONTEXT_COURSE, $courseid); - + global $CFG; + $context = get_context_instance(CONTEXT_COURSE, $courseid); + if ($currentgroup and (!$isseparategroups or has_capability('moodle/site:accessallgroups', $context))) { /// Display info about the group if ($group = get_record('groups', 'id', $currentgroup)) { if (!empty($group->description) or (!empty($group->picture) and empty($group->hidepicture))) { diff --git a/group/lib/modulelib.php b/group/lib/modulelib.php index 1458e73f73..136ae3c140 100644 --- a/group/lib/modulelib.php +++ b/group/lib/modulelib.php @@ -72,13 +72,13 @@ define('GROUPS_TEACHER_CONTRIBUTE', 10); * @return boolean True if the instance is set up to use groups, false otherwise */ function groups_m_uses_groups($cmid) { - $usesgroups = false; - $groupingid = groups_db_get_groupingid($cmid); - if (!$groupingid) { - $usesgroups = true; - } - - return $usesgroups; + $usesgroups = false; + $groupingid = groups_db_get_groupingid($cmid); + if (!$groupingid) { + $usesgroups = true; + } + + return $usesgroups; } /** @@ -95,24 +95,24 @@ function groups_m_uses_groups($cmid) { * use groups in which case returns false. */ function groups_m_print_group_selector($cmid, $urlroot, $permissiontype) { - // Get the groups for the cmid - // Produce an array to put into the $groupsmenu array. - // Add an all option if necessary. - $groupids = groups_module_get_groups_for_current_user($cmid, $permissiontype); - - // Need a line to check if current group selected. - if ($groupids) { - $currentgroup = groups_module_get_current_group($cmid); - if ($allgroupsoption) { - $groupsmenu[0] = get_string('allparticipants'); - } - - foreach ($groupids as $groupid) { - $groupsmenu[$groupid] = groups_get_group_name($groupid); - popup_form($urlroot.'&group=', $groupsmenu, 'selectgroup', - $currentgroup, '', '', '', false, 'self'); - } - } + // Get the groups for the cmid + // Produce an array to put into the $groupsmenu array. + // Add an all option if necessary. + $groupids = groups_module_get_groups_for_current_user($cmid, $permissiontype); + + // Need a line to check if current group selected. + if ($groupids) { + $currentgroup = groups_module_get_current_group($cmid); + if ($allgroupsoption) { + $groupsmenu[0] = get_string('allparticipants'); + } + + foreach ($groupids as $groupid) { + $groupsmenu[$groupid] = groups_get_group_name($groupid); + popup_form($urlroot.'&group=', $groupsmenu, 'selectgroup', + $currentgroup, '', '', '', false, 'self'); + } + } } /** @@ -138,15 +138,15 @@ function groups_m_print_group_selector($cmid, $urlroot, $permissiontype) { * TO DO - make this and other functions default to current user */ function groups_m_get_selected_group($cmid, $permissiontype, $userid) { - $currentgroup = optional_param('group'); - if (!$currentgroup) { - $groupids = groups_get_groups_for_user(); - } - // Get it from the session variable, otherwise get it from the form, otherwise - // Get it from the database as the first group. - // Then set the group in the session variable to make it easier to get next time. + $currentgroup = optional_param('group'); + if (!$currentgroup) { + $groupids = groups_get_groups_for_user(); + } + // Get it from the session variable, otherwise get it from the form, otherwise + // Get it from the database as the first group. + // Then set the group in the session variable to make it easier to get next time. } - + /** * Gets an array of the group IDs of all groups for the user in this course module. * @uses $USER @@ -201,71 +201,71 @@ function groups_m_get_my_group($cm) { * @return boolean True if the user has the specified permission type, false * otherwise or if an error occurred. */ - function groups_m_has_permission($cm, $groupid, $permissiontype, $userid = null) { +function groups_m_has_permission($cm, $groupid, $permissiontype, $userid = null) { if (!$userid) { global $USER; $userid = $USER->id; } - $groupingid = groups_get_grouping_for_coursemodule($cm); - if (!$groupingid || !is_object($cm) || !isset($cm->course)) { + $groupingid = groups_get_grouping_for_coursemodule($cm); + if (!$groupingid || !is_object($cm) || !isset($cm->course)) { return false; } $courseid = $cm->course; $isstudent = isstudent($courseid, $userid); - $isteacher = isteacher($courseid, $userid); - $groupmember = groups_is_member($groupid, $userid); - $memberofsomegroup = groups_is_member_of_some_group_in_grouping($userid, $groupingid); - - $groupingsettings = groups_get_grouping_settings($groupingid); - $viewowngroup = $groupingsettings->viewowngroup; - $viewallgroupsmembers = $groupingsettings->viewallgroupmembers; - $viewallgroupsactivities = $groupingsettings->viewallgroupsactivities; - $teachersgroupsmark = $groupingsettings->teachersgroupsmark; - $teachersgroupsview = $groupingsettings->teachersgroupsview; - $teachersgroupmark = $groupingsettings->teachersgroupmark; - $teachersgroupview = $groupingsettings->teachersgroupview; - $teachersoverride = $groupingsettings->teachersoverride; - - $permission = false; - - switch ($permissiontype) { - case 'view': - if (($isstudent and $groupmember) or - ($isteacher and $groupmember) or - ($isstudent and $viewallgroupsactivities) or - ($isteacher and !$teachersgroupview) or - ($isteacher and !$memberofsomegroup and $teachersoverride)) { - $permission = true; - } - break; - - case 'studentcontribute': - if (($isstudent and $groupmember) or - ($isteacher and $groupmember) or - ($isteacher and !$memberofsomegroup and $teachersoverride)) { - $permission = true; - } - break; - case 'teachermark': - if (($isteacher and $groupmember) or - ($isteacher and !$teachersgroupmark) or - ($isteacher and !$memberofsomegroup and $teachersoverride)) { - $permission = true; - } - break; - - case 'viewmembers': - if (($isstudent and $groupmember and $viewowngroup) or - ($isstudent and $viewallgroupsmembers) or - ($isteacher and $groupmember) or - ($isteacher and !$teachersgroupview) or - ($isteacher and !$memberofsomegroup and $teachersoverride) or - $isteacheredit) { - $permission = true; - } - break; - } - return $permission; + $isteacher = isteacher($courseid, $userid); + $groupmember = groups_is_member($groupid, $userid); + $memberofsomegroup = groups_is_member_of_some_group_in_grouping($userid, $groupingid); + + $groupingsettings = groups_get_grouping_settings($groupingid); + $viewowngroup = $groupingsettings->viewowngroup; + $viewallgroupsmembers = $groupingsettings->viewallgroupmembers; + $viewallgroupsactivities = $groupingsettings->viewallgroupsactivities; + $teachersgroupsmark = $groupingsettings->teachersgroupsmark; + $teachersgroupsview = $groupingsettings->teachersgroupsview; + $teachersgroupmark = $groupingsettings->teachersgroupmark; + $teachersgroupview = $groupingsettings->teachersgroupview; + $teachersoverride = $groupingsettings->teachersoverride; + + $permission = false; + + switch ($permissiontype) { + case 'view': + if (($isstudent and $groupmember) or + ($isteacher and $groupmember) or + ($isstudent and $viewallgroupsactivities) or + ($isteacher and !$teachersgroupview) or + ($isteacher and !$memberofsomegroup and $teachersoverride)) { + $permission = true; + } + break; + + case 'studentcontribute': + if (($isstudent and $groupmember) or + ($isteacher and $groupmember) or + ($isteacher and !$memberofsomegroup and $teachersoverride)) { + $permission = true; + } + break; + case 'teachermark': + if (($isteacher and $groupmember) or + ($isteacher and !$teachersgroupmark) or + ($isteacher and !$memberofsomegroup and $teachersoverride)) { + $permission = true; + } + break; + + case 'viewmembers': + if (($isstudent and $groupmember and $viewowngroup) or + ($isstudent and $viewallgroupsmembers) or + ($isteacher and $groupmember) or + ($isteacher and !$teachersgroupview) or + ($isteacher and !$memberofsomegroup and $teachersoverride) or + $isteacheredit) { + $permission = true; + } + break; + } + return $permission; } /** @@ -284,17 +284,17 @@ function groups_m_get_my_group($cm) { */ function groups_m_get_members_with_permission($cmid, $groupid, $permissiontype) { - // Get all the users as $userid - $validuserids = array(); - foreach($validuserids as $userid) { - $haspermission = groups_m_has_permission($cmid, $groupid, - $permissiontype, $userid); - if ($haspermission) { - array_push($validuserids, $userid); - } - } - return $validuserids; -} + // Get all the users as $userid + $validuserids = array(); + foreach($validuserids as $userid) { + $haspermission = groups_m_has_permission($cmid, $groupid, + $permissiontype, $userid); + if ($haspermission) { + array_push($validuserids, $userid); + } + } + return $validuserids; + } /** * Gets the group object associated with a group id. This group object can be @@ -305,7 +305,7 @@ function groups_m_get_members_with_permission($cmid, $groupid, * @return group The group object */ function groups_m_get_group($groupid) { - return groups_db_m_get_group($groupid); + return groups_db_m_get_group($groupid); } /** @@ -316,9 +316,9 @@ function groups_m_get_group($groupid) { * @return array An array of the ids of the groups for the module instance */ function groups_m_get_groups($cmid) { - $groupingid = groups_db_get_groupingid($cmid); - $groupids = groups_get_groups_in_grouping($groupingid); - return $groupids; + $groupingid = groups_db_get_groupingid($cmid); + $groupids = groups_get_groups_in_grouping($groupingid); + return $groupids; } /** @@ -329,12 +329,12 @@ function groups_m_get_groups($cmid) { * @return array An array of the userids of the members. */ function groups_m_get_members($cmid, $groupid) { - $userids = groups_get_members($groupid, $membertype); - if (!$userids) { - $memberids = false; - } else { - // Check if each user is enrolled on the course @@@ TO DO - } + $userids = groups_get_members($groupid, $membertype); + if (!$userids) { + $memberids = false; + } else { + // Check if each user is enrolled on the course @@@ TO DO + } return $memberids; } @@ -426,4 +426,4 @@ function groups_m_get_current($cm, $full=false) { } } -?> \ No newline at end of file +?> diff --git a/group/lib/utillib.php b/group/lib/utillib.php index e2a612e11f..bf4cb8a5ed 100644 --- a/group/lib/utillib.php +++ b/group/lib/utillib.php @@ -61,21 +61,21 @@ function groups_count_groups_in_grouping($groupingid, $courseid) { * @return string The display name of the user. */ function groups_get_user_displayname($userid, $courseid) { - if ($courseid == false) { - $fullname = false; - } else { - $user = groups_get_user($userid); - $fullname = fullname($user, true); + if ($courseid == false) { + $fullname = false; + } else { + $user = groups_get_user($userid); + $fullname = fullname($user, true); //TODO: isteacher, isteacheredit. - if (isteacher($courseid, $userid)) { - if (isteacheredit($courseid, $userid)) { - $prefix = '# '; - } else { - $prefix = '- '; - } - $fullname = $prefix.$fullname; - } - } + if (isteacher($courseid, $userid)) { + if (isteacheredit($courseid, $userid)) { + $prefix = '# '; + } else { + $prefix = '- '; + } + $fullname = $prefix.$fullname; + } + } return $fullname; } @@ -87,11 +87,11 @@ function groups_get_user_displayname($userid, $courseid) { * @return string The display name of the group */ function groups_get_group_displayname($groupid) { - if ($groupname = groups_get_group_name($groupid)) { + if ($groupname = groups_get_group_name($groupid)) { $count = groups_count_group_members($groupid); return "$groupname ($count)"; } - return false; + return false; } @@ -156,19 +156,19 @@ function groups_userids_to_user_names($userids, $courseid) { * @return array The array of group IDs, or false if an error occurred */ function groups_groups_to_groupids($groups) { - if (! $groups) { + if (! $groups) { return false; } $groupids = array(); - foreach ($groups as $group) { + foreach ($groups as $group) { if (isset($group->id)) { - array_push($groupids, $group->id); + array_push($groupids, $group->id); } else { //Warn if there's no "groupid" member. array_push($groupids, $group->groupid); } - } - return $groupids; + } + return $groupids; } @@ -271,7 +271,7 @@ function groups_groupingids_to_groupings($groupingids) { * @return object The corresponding user object, or false if an error occurred */ function groups_get_user($userid) { - return groups_db_get_user($userid); + return groups_db_get_user($userid); } @@ -282,11 +282,11 @@ function groups_get_user($userid) { * TODO: need to put the database bit into a db file */ function groups_get_course_info($courseid){ - if (!$courseid) { - $courseinfo = false; - } else { - $courseinfo = get_record('course', 'id', $courseid); - } + if (!$courseid) { + $courseinfo = false; + } else { + $courseinfo = get_record('course', 'id', $courseid); + } return $courseinfo; }