/** * Gets a list of the groups not in any grouping, but in this course. * TODO: move to dbgroupinglib.php * @param $courseid If null or false, returns groupids 'not in a grouping sitewide'. * @return array An array of group IDs. */ function groups_get_groups_not_in_any_grouping($courseid) { global $CFG; $join = ''; $where = ''; if ($courseid) { $join = "INNER JOIN {$CFG->prefix}groups_courses_groups cg ON g.id = cg.groupid"; $where = "AND cg.courseid = '{$courseid}'"; } $sql = "SELECT g.id\n FROM {$CFG->prefix}groups g\n {$join}\n WHERE g.id NOT IN \n (SELECT groupid FROM {$CFG->prefix}groups_groupings_groups)\n {$where}"; $records = get_records_sql($sql); $groupids = groups_groups_to_groupids($records, $courseid); return $groupids; }
/** * Gets the groups to which a user belongs for a specified course. * @uses $CFG * @param int $userid The id of the specified user * @param int $courseid The id of the course. * @return array | false An array of the group ids of the groups to which the * user belongs or false if there are no groups or an error occurred. */ function groups_db_get_groups_for_user($userid, $courseid) { if (!$userid or !$courseid) { $groupids = false; } else { global $CFG; $sql = "SELECT g.id, gm.userid \n FROM {$CFG->prefix}groups_members gm \n INNER JOIN {$CFG->prefix}groups g\n ON gm.groupid = g.id\n INNER JOIN {$CFG->prefix}groups_courses_groups cg\n ON g.id = cg.groupid\n WHERE cg.courseid = '{$courseid}' AND gm.userid = '{$userid}'"; $groups = get_records_sql($sql); $groupids = groups_groups_to_groupids($groups); } return $groupids; }