Fixing group list see #5608

skala
Julio Montoya 12 years ago
parent 8f683893ad
commit 67ab82a7e3
  1. 2
      main/announcements/announcements.inc.php
  2. 11
      main/inc/lib/course.lib.php
  3. 18
      main/inc/lib/groupmanager.lib.php

@ -754,7 +754,7 @@ class AnnouncementManager {
public static function get_course_groups() {
$session_id = api_get_session_id();
if ($session_id != 0) {
$new_group_list = CourseManager::get_group_list_of_course(api_get_course_id(), intval($session_id));
$new_group_list = CourseManager::get_group_list_of_course(api_get_course_id(), $session_id);
} else {
$new_group_list = CourseManager::get_group_list_of_course(api_get_course_id(), 0);
}

@ -1527,16 +1527,17 @@ class CourseManager {
$course_id = $course_info['real_id'];
$group_list = array();
$session_id != 0 ? $session_condition = ' WHERE g.session_id IN(1,'.intval($session_id).')' : $session_condition = ' WHERE g.session_id = 0';
$sql = "SELECT g.id, g.name, COUNT(gu.id) userNb
$sql = "SELECT g.id, g.name
FROM ".Database::get_course_table(TABLE_GROUP)." AS g
LEFT JOIN ".Database::get_course_table(TABLE_GROUP_USER)." gu
INNER JOIN ".Database::get_course_table(TABLE_GROUP_USER)." gu
ON (g.id = gu.group_id AND g.c_id = $course_id AND gu.c_id = $course_id)
$session_condition
GROUP BY g.id
$session_condition
ORDER BY g.name";
$result = Database::query($sql);
while ($group_data = Database::fetch_array($result)) {
$group_data[] = GroupManager::number_of_students($group_data['id'], $course_id);
$group_list[$group_data['id']] = $group_data;
}
return $group_list;

@ -7,7 +7,6 @@
/**
* Code
*/
//require_once 'tablesort.lib.php';moved to autoload
require_once 'fileManage.lib.php';
require_once 'fileUpload.lib.php';
require_once 'document.lib.php';
@ -832,7 +831,6 @@ class GroupManager {
while ($row = Database::fetch_array($rs)) {
$result[] = $row['user_id'];
}
return $result;
}
@ -966,10 +964,14 @@ class GroupManager {
* @param int $group_id
* @return int Number of students in the given group.
*/
public static function number_of_students ($group_id) {
public static function number_of_students ($group_id, $course_id = null) {
$table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
$group_id = Database::escape_string($group_id);
$course_id = api_get_course_int_id();
if (empty($course_id)) {
$course_id = api_get_course_int_id();
} else {
$course_id = intval($course_id);
}
$sql = "SELECT COUNT(*) AS number_of_students FROM $table_group_user WHERE c_id = $course_id AND group_id = $group_id";
$db_result = Database::query($sql);
$db_object = Database::fetch_object($db_result);
@ -1117,10 +1119,10 @@ class GroupManager {
$course_id = api_get_course_int_id();
$sql = "SELECT ug.id, u.user_id, u.lastname, u.firstname, u.email, u.username
FROM ".$table_user." u, ".$table_group_user." ug
WHERE ug.c_id = $course_id AND
ug.group_id='".$group_id."' AND
ug.user_id=u.user_id". $order_clause;
FROM $table_user u INNER JOIN $table_group_user ug ON (ug.user_id = u.user_id)
WHERE ug.c_id = $course_id AND
ug.group_id = $group_id
$order_clause";
$db_result = Database::query($sql);
$users = array ();
while ($user = Database::fetch_object($db_result)) {

Loading…
Cancel
Save