|
|
@ -86,7 +86,9 @@ class GroupManager |
|
|
|
$course_id = $course_info['real_id']; |
|
|
|
$course_id = $course_info['real_id']; |
|
|
|
$table_group = Database :: get_course_table(TABLE_GROUP); |
|
|
|
$table_group = Database :: get_course_table(TABLE_GROUP); |
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT g.id, |
|
|
|
$sql = "SELECT |
|
|
|
|
|
|
|
g.id, |
|
|
|
|
|
|
|
g.iid, |
|
|
|
g.name, |
|
|
|
g.name, |
|
|
|
g.description, |
|
|
|
g.description, |
|
|
|
g.category_id, |
|
|
|
g.category_id, |
|
|
@ -124,7 +126,7 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
|
|
$groups = array(); |
|
|
|
$groups = array(); |
|
|
|
while ($thisGroup = Database::fetch_array($groupList)) { |
|
|
|
while ($thisGroup = Database::fetch_array($groupList)) { |
|
|
|
$thisGroup['number_of_members'] = count(self::get_subscribed_users($thisGroup['id'])); |
|
|
|
$thisGroup['number_of_members'] = count(self::get_subscribed_users($thisGroup['iid'])); |
|
|
|
if ($thisGroup['session_id'] != 0) { |
|
|
|
if ($thisGroup['session_id'] != 0) { |
|
|
|
$sql = 'SELECT name FROM '.Database::get_main_table(TABLE_MAIN_SESSION).' |
|
|
|
$sql = 'SELECT name FROM '.Database::get_main_table(TABLE_MAIN_SESSION).' |
|
|
|
WHERE id='.$thisGroup['session_id']; |
|
|
|
WHERE id='.$thisGroup['session_id']; |
|
|
@ -153,7 +155,6 @@ class GroupManager |
|
|
|
$course_id = $_course['real_id']; |
|
|
|
$course_id = $_course['real_id']; |
|
|
|
$currentCourseRepository = $_course['path']; |
|
|
|
$currentCourseRepository = $_course['path']; |
|
|
|
$category = self :: get_category($category_id); |
|
|
|
$category = self :: get_category($category_id); |
|
|
|
|
|
|
|
|
|
|
|
$places = intval($places); |
|
|
|
$places = intval($places); |
|
|
|
|
|
|
|
|
|
|
|
if ($category) { |
|
|
|
if ($category) { |
|
|
@ -188,7 +189,7 @@ class GroupManager |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$table_group = Database :: get_course_table(TABLE_GROUP); |
|
|
|
$table_group = Database :: get_course_table(TABLE_GROUP); |
|
|
|
$sql = "INSERT INTO ".$table_group." SET |
|
|
|
$sql = "INSERT INTO $table_group SET |
|
|
|
c_id = $course_id, |
|
|
|
c_id = $course_id, |
|
|
|
status = 1, |
|
|
|
status = 1, |
|
|
|
category_id='".Database::escape_string($category_id)."', |
|
|
|
category_id='".Database::escape_string($category_id)."', |
|
|
@ -398,9 +399,6 @@ class GroupManager |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Unsubscribe all users |
|
|
|
|
|
|
|
self::unsubscribe_all_users($group_ids); |
|
|
|
|
|
|
|
self::unsubscribe_all_tutors($group_ids); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT id, iid, secret_directory, session_id |
|
|
|
$sql = "SELECT id, iid, secret_directory, session_id |
|
|
|
FROM $group_table |
|
|
|
FROM $group_table |
|
|
@ -409,6 +407,10 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
|
|
while ($group = Database::fetch_object($db_result)) { |
|
|
|
while ($group = Database::fetch_object($db_result)) { |
|
|
|
$groupId = $group->iid; |
|
|
|
$groupId = $group->iid; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Unsubscribe all users |
|
|
|
|
|
|
|
self::unsubscribe_all_users($groupId); |
|
|
|
|
|
|
|
self::unsubscribe_all_tutors($groupId); |
|
|
|
// move group-documents to garbage |
|
|
|
// move group-documents to garbage |
|
|
|
$source_directory = api_get_path(SYS_COURSE_PATH).$course_info['path']."/document".$group->secret_directory; |
|
|
|
$source_directory = api_get_path(SYS_COURSE_PATH).$course_info['path']."/document".$group->secret_directory; |
|
|
|
// File to renamed |
|
|
|
// File to renamed |
|
|
@ -472,6 +474,7 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
|
|
if ($db_object) { |
|
|
|
if ($db_object) { |
|
|
|
$result['id'] = $db_object->id; |
|
|
|
$result['id'] = $db_object->id; |
|
|
|
|
|
|
|
$result['iid'] = $db_object->iid; |
|
|
|
$result['name'] = $db_object->name; |
|
|
|
$result['name'] = $db_object->name; |
|
|
|
$result['status'] = $db_object->status; |
|
|
|
$result['status'] = $db_object->status; |
|
|
|
$result['description'] = $db_object->description; |
|
|
|
$result['description'] = $db_object->description; |
|
|
@ -488,10 +491,10 @@ class GroupManager |
|
|
|
$result['self_registration_allowed'] = $db_object->self_registration_allowed; |
|
|
|
$result['self_registration_allowed'] = $db_object->self_registration_allowed; |
|
|
|
$result['self_unregistration_allowed'] = $db_object->self_unregistration_allowed; |
|
|
|
$result['self_unregistration_allowed'] = $db_object->self_unregistration_allowed; |
|
|
|
$result['count_users'] = count( |
|
|
|
$result['count_users'] = count( |
|
|
|
self::get_subscribed_users($group_id) |
|
|
|
self::get_subscribed_users($db_object->iid) |
|
|
|
); |
|
|
|
); |
|
|
|
$result['count_tutor'] = count( |
|
|
|
$result['count_tutor'] = count( |
|
|
|
self::get_subscribed_tutors($group_id) |
|
|
|
self::get_subscribed_tutors($db_object->iid) |
|
|
|
); |
|
|
|
); |
|
|
|
$result['count_all'] = $result['count_users'] + $result['count_tutor']; |
|
|
|
$result['count_all'] = $result['count_users'] + $result['count_tutor']; |
|
|
|
} |
|
|
|
} |
|
|
@ -723,7 +726,7 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get the unique category of a given group |
|
|
|
* Get the unique category of a given group |
|
|
|
* @param int $group_id The id of the group |
|
|
|
* @param int $group_id The iid of the group |
|
|
|
* @param string $course_code The course in which the group is (default = |
|
|
|
* @param string $course_code The course in which the group is (default = |
|
|
|
* current course) |
|
|
|
* current course) |
|
|
|
* @return array The category |
|
|
|
* @return array The category |
|
|
@ -750,7 +753,7 @@ class GroupManager |
|
|
|
gc.c_id = $course_id AND |
|
|
|
gc.c_id = $course_id AND |
|
|
|
g.c_id = $course_id AND |
|
|
|
g.c_id = $course_id AND |
|
|
|
gc.id = g.category_id AND |
|
|
|
gc.id = g.category_id AND |
|
|
|
g.id= $group_id |
|
|
|
g.iid = $group_id |
|
|
|
LIMIT 1"; |
|
|
|
LIMIT 1"; |
|
|
|
$res = Database::query($sql); |
|
|
|
$res = Database::query($sql); |
|
|
|
$cat = array(); |
|
|
|
$cat = array(); |
|
|
@ -1093,7 +1096,7 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get only tutors from a group |
|
|
|
* Get only tutors from a group |
|
|
|
* @param int $group_id |
|
|
|
* @param int $group_id iid |
|
|
|
* @return array |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function getTutors($group_id) |
|
|
|
public static function getTutors($group_id) |
|
|
@ -1179,32 +1182,19 @@ class GroupManager |
|
|
|
* ywarnier:> Now the course_id has been removed (25/1/2005) |
|
|
|
* ywarnier:> Now the course_id has been removed (25/1/2005) |
|
|
|
* The databases are als very inconsistent in this. |
|
|
|
* The databases are als very inconsistent in this. |
|
|
|
* |
|
|
|
* |
|
|
|
|
|
|
|
* @param int $groupId iid |
|
|
|
* @author Chrisptophe Gesche <christophe.geshe@claroline.net>, |
|
|
|
* @author Chrisptophe Gesche <christophe.geshe@claroline.net>, |
|
|
|
* Hugues Peeters <hugues.peeters@claroline.net> - original version |
|
|
|
* Hugues Peeters <hugues.peeters@claroline.net> - original version |
|
|
|
* @author Roan Embrechts - virtual course support, code cleaning |
|
|
|
* @author Roan Embrechts - virtual course support, code cleaning |
|
|
|
* @author Bart Mollet - code cleaning, use other GroupManager-functions |
|
|
|
* @author Bart Mollet - code cleaning, use other GroupManager-functions |
|
|
|
* @return void |
|
|
|
* @return void |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function fill_groups($group_ids) |
|
|
|
public static function fill_groups($groupId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$_course = api_get_course_info(); |
|
|
|
$_course = api_get_course_info(); |
|
|
|
|
|
|
|
$groupId = (int) $groupId; |
|
|
|
|
|
|
|
|
|
|
|
$group_ids = is_array($group_ids) ? $group_ids : array ($group_ids); |
|
|
|
$category = self::get_category_from_group($groupId); |
|
|
|
$group_ids = array_map('intval', $group_ids); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (api_is_course_coach()) { |
|
|
|
|
|
|
|
for ($i=0 ; $i < count($group_ids) ; $i++) { |
|
|
|
|
|
|
|
if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])){ |
|
|
|
|
|
|
|
array_splice($group_ids,$i,1); |
|
|
|
|
|
|
|
$i--; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (count($group_ids)==0) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$category = self::get_category_from_group($group_ids[0]); |
|
|
|
|
|
|
|
$groups_per_user = (isset($category['groups_per_user']) ? $category['groups_per_user'] : self::GROUP_PER_MEMBER_NO_LIMIT); |
|
|
|
$groups_per_user = (isset($category['groups_per_user']) ? $category['groups_per_user'] : self::GROUP_PER_MEMBER_NO_LIMIT); |
|
|
|
$group_table = Database:: get_course_table(TABLE_GROUP); |
|
|
|
$group_table = Database:: get_course_table(TABLE_GROUP); |
|
|
|
$group_user_table = Database:: get_course_table(TABLE_GROUP_USER); |
|
|
|
$group_user_table = Database:: get_course_table(TABLE_GROUP_USER); |
|
|
@ -1219,19 +1209,21 @@ class GroupManager |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$sql = "SELECT g.id gid, g.max_student-count(ug.user_id) nbPlaces, g.max_student |
|
|
|
$sql = "SELECT g.id gid, g.iid g.max_student-count(ug.user_id) nbPlaces, g.max_student |
|
|
|
FROM ".$group_table." g |
|
|
|
FROM $group_table g |
|
|
|
LEFT JOIN ".$group_user_table." ug ON |
|
|
|
LEFT JOIN $group_user_table ug ON |
|
|
|
g.c_id = $course_id AND ug.c_id = $course_id AND g.id = ug.group_id |
|
|
|
g.c_id = $course_id AND |
|
|
|
|
|
|
|
ug.c_id = $course_id AND |
|
|
|
|
|
|
|
g.iid = ug.group_id |
|
|
|
WHERE |
|
|
|
WHERE |
|
|
|
g.id IN (".implode(',', $group_ids).") |
|
|
|
g.iid = $groupId |
|
|
|
GROUP BY (g.id) |
|
|
|
GROUP BY (g.iid) |
|
|
|
HAVING (nbPlaces > 0 OR g.max_student = ".self::MEMBER_PER_GROUP_NO_LIMIT.") |
|
|
|
HAVING (nbPlaces > 0 OR g.max_student = ".self::MEMBER_PER_GROUP_NO_LIMIT.") |
|
|
|
ORDER BY nbPlaces DESC"; |
|
|
|
ORDER BY nbPlaces DESC"; |
|
|
|
$sql_result = Database::query($sql); |
|
|
|
$sql_result = Database::query($sql); |
|
|
|
$group_available_place = array(); |
|
|
|
$group_available_place = array(); |
|
|
|
while ($group = Database::fetch_array($sql_result, 'ASSOC')) { |
|
|
|
while ($group = Database::fetch_array($sql_result, 'ASSOC')) { |
|
|
|
$group_available_place[$group['gid']] = $group['nbPlaces']; |
|
|
|
$group_available_place[$group['iid']] = $group['nbPlaces']; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
@ -1240,7 +1232,10 @@ class GroupManager |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
for ($i = 0; $i < count($complete_user_list); $i ++) { |
|
|
|
for ($i = 0; $i < count($complete_user_list); $i ++) { |
|
|
|
//find # of groups the user is enrolled in |
|
|
|
//find # of groups the user is enrolled in |
|
|
|
$number_of_groups = self :: user_in_number_of_groups($complete_user_list[$i]["user_id"], (isset($category['id'])?$category['id']:null)); |
|
|
|
$number_of_groups = self :: user_in_number_of_groups( |
|
|
|
|
|
|
|
$complete_user_list[$i]["user_id"], |
|
|
|
|
|
|
|
isset($category['id']) ? $category['id'] : null |
|
|
|
|
|
|
|
); |
|
|
|
//add # of groups to user list |
|
|
|
//add # of groups to user list |
|
|
|
$complete_user_list[$i]['number_groups_left'] = $number_groups_per_user - $number_of_groups; |
|
|
|
$complete_user_list[$i]['number_groups_left'] = $number_groups_per_user - $number_of_groups; |
|
|
|
} |
|
|
|
} |
|
|
@ -1286,7 +1281,7 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get the number of students in a group. |
|
|
|
* Get the number of students in a group. |
|
|
|
* @param int $group_id |
|
|
|
* @param int $group_id iid |
|
|
|
* @return int Number of students in the given group. |
|
|
|
* @return int Number of students in the given group. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function number_of_students($group_id, $course_id = null) |
|
|
|
public static function number_of_students($group_id, $course_id = null) |
|
|
@ -1309,7 +1304,7 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Maximum number of students in a group |
|
|
|
* Maximum number of students in a group |
|
|
|
* @param int $group_id |
|
|
|
* @param int $group_id iid |
|
|
|
* @return int Maximum number of students in the given group. |
|
|
|
* @return int Maximum number of students in the given group. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function maximum_number_of_students($group_id) |
|
|
|
public static function maximum_number_of_students($group_id) |
|
|
@ -1317,7 +1312,8 @@ class GroupManager |
|
|
|
$table_group = Database :: get_course_table(TABLE_GROUP); |
|
|
|
$table_group = Database :: get_course_table(TABLE_GROUP); |
|
|
|
$group_id = intval($group_id); |
|
|
|
$group_id = intval($group_id); |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$db_result = Database::query("SELECT max_student FROM $table_group WHERE c_id = $course_id AND id = $group_id"); |
|
|
|
$sql = "SELECT max_student FROM $table_group WHERE c_id = $course_id AND iid = $group_id"; |
|
|
|
|
|
|
|
$db_result = Database::query($sql); |
|
|
|
$db_object = Database::fetch_object($db_result); |
|
|
|
$db_object = Database::fetch_object($db_result); |
|
|
|
if ($db_object->max_student == 0) { |
|
|
|
if ($db_object->max_student == 0) { |
|
|
|
return self::INFINITE; |
|
|
|
return self::INFINITE; |
|
|
@ -1359,7 +1355,7 @@ class GroupManager |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Is sef-registration allowed? |
|
|
|
* Is sef-registration allowed? |
|
|
|
* @param int $user_id |
|
|
|
* @param int $user_id |
|
|
|
* @param int $group_id |
|
|
|
* @param int $group_id iid |
|
|
|
* @return bool TRUE if self-registration is allowed in the given group. |
|
|
|
* @return bool TRUE if self-registration is allowed in the given group. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function is_self_registration_allowed($user_id, $group_id) |
|
|
|
public static function is_self_registration_allowed($user_id, $group_id) |
|
|
@ -1373,7 +1369,7 @@ class GroupManager |
|
|
|
if (isset($group_id)) { |
|
|
|
if (isset($group_id)) { |
|
|
|
$sql = "SELECT self_registration_allowed |
|
|
|
$sql = "SELECT self_registration_allowed |
|
|
|
FROM $table_group |
|
|
|
FROM $table_group |
|
|
|
WHERE c_id = $course_id AND id = $group_id"; |
|
|
|
WHERE c_id = $course_id AND iid = $group_id"; |
|
|
|
$db_result = Database::query($sql); |
|
|
|
$db_result = Database::query($sql); |
|
|
|
$db_object = Database::fetch_object($db_result); |
|
|
|
$db_object = Database::fetch_object($db_result); |
|
|
|
|
|
|
|
|
|
|
@ -1386,7 +1382,7 @@ class GroupManager |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Is sef-unregistration allowed? |
|
|
|
* Is sef-unregistration allowed? |
|
|
|
* @param int $user_id |
|
|
|
* @param int $user_id |
|
|
|
* @param int $group_id |
|
|
|
* @param int $group_id iid |
|
|
|
* @return bool TRUE if self-unregistration is allowed in the given group. |
|
|
|
* @return bool TRUE if self-unregistration is allowed in the given group. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function is_self_unregistration_allowed($user_id, $group_id) |
|
|
|
public static function is_self_unregistration_allowed($user_id, $group_id) |
|
|
@ -1398,9 +1394,9 @@ class GroupManager |
|
|
|
$group_id = intval($group_id); |
|
|
|
$group_id = intval($group_id); |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$db_result = Database::query( |
|
|
|
$db_result = Database::query( |
|
|
|
'SELECT self_unregistration_allowed |
|
|
|
'SELECT self_unregistration_allowed |
|
|
|
FROM '.$table_group.' |
|
|
|
FROM '.$table_group.' |
|
|
|
WHERE c_id = '.$course_id.' AND id = '.$group_id |
|
|
|
WHERE c_id = '.$course_id.' AND iid = '.$group_id |
|
|
|
); |
|
|
|
); |
|
|
|
$db_object = Database::fetch_object($db_result); |
|
|
|
$db_object = Database::fetch_object($db_result); |
|
|
|
|
|
|
|
|
|
|
@ -1410,7 +1406,7 @@ class GroupManager |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Is user subscribed in group? |
|
|
|
* Is user subscribed in group? |
|
|
|
* @param int $user_id |
|
|
|
* @param int $user_id |
|
|
|
* @param int $group_id |
|
|
|
* @param int $group_id iid |
|
|
|
* @return bool TRUE if given user is subscribed in given group |
|
|
|
* @return bool TRUE if given user is subscribed in given group |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function is_subscribed($user_id, $group_id) |
|
|
|
public static function is_subscribed($user_id, $group_id) |
|
|
@ -1422,11 +1418,12 @@ class GroupManager |
|
|
|
$group_id = intval($group_id); |
|
|
|
$group_id = intval($group_id); |
|
|
|
$user_id = intval($user_id); |
|
|
|
$user_id = intval($user_id); |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$sql = 'SELECT 1 FROM '.$table_group_user.' |
|
|
|
$sql = "SELECT 1 FROM $table_group_user |
|
|
|
WHERE |
|
|
|
WHERE |
|
|
|
c_id = '.$course_id.' AND |
|
|
|
c_id = $course_id AND |
|
|
|
group_id = '.$group_id.' AND |
|
|
|
group_id = $group_id AND |
|
|
|
user_id = '.$user_id; |
|
|
|
user_id = $user_id |
|
|
|
|
|
|
|
"; |
|
|
|
$result = Database::query($sql); |
|
|
|
$result = Database::query($sql); |
|
|
|
|
|
|
|
|
|
|
|
return Database::num_rows($result) > 0; |
|
|
|
return Database::num_rows($result) > 0; |
|
|
@ -1435,7 +1432,7 @@ class GroupManager |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Can a user subscribe to a specified group in a course |
|
|
|
* Can a user subscribe to a specified group in a course |
|
|
|
* @param int $user_id |
|
|
|
* @param int $user_id |
|
|
|
* @param int $group_id |
|
|
|
* @param int $group_id iid |
|
|
|
* @param bool $checkMaxNumberStudents |
|
|
|
* @param bool $checkMaxNumberStudents |
|
|
|
* |
|
|
|
* |
|
|
|
* @return bool TRUE if given user can be subscribed in given group |
|
|
|
* @return bool TRUE if given user can be subscribed in given group |
|
|
@ -1461,12 +1458,14 @@ class GroupManager |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$result = self :: is_tutor_of_group($user_id, $group_id); |
|
|
|
$result = self::is_tutor_of_group($user_id, $group_id); |
|
|
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
if ($result) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$result = self :: is_subscribed($user_id, $group_id); |
|
|
|
$result = self::is_subscribed($user_id, $group_id); |
|
|
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
if ($result) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -1477,7 +1476,7 @@ class GroupManager |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Can a user unsubscribe to a specified group in a course |
|
|
|
* Can a user unsubscribe to a specified group in a course |
|
|
|
* @param int $user_id |
|
|
|
* @param int $user_id |
|
|
|
* @param int $group_id |
|
|
|
* @param int $group_id iid |
|
|
|
* @return bool TRUE if given user can be unsubscribed from given group |
|
|
|
* @return bool TRUE if given user can be unsubscribed from given group |
|
|
|
* @internal for now, same as GroupManager::is_subscribed($user_id,$group_id) |
|
|
|
* @internal for now, same as GroupManager::is_subscribed($user_id,$group_id) |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -1490,7 +1489,7 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get all subscribed users (members) from a group |
|
|
|
* Get all subscribed users (members) from a group |
|
|
|
* @param int $group_id |
|
|
|
* @param int $group_id (iid) |
|
|
|
* @return array An array with information of all users from the given group. |
|
|
|
* @return array An array with information of all users from the given group. |
|
|
|
* (user_id, firstname, lastname, email) |
|
|
|
* (user_id, firstname, lastname, email) |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -1534,7 +1533,7 @@ class GroupManager |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
* Get all subscribed tutors of a group |
|
|
|
* Get all subscribed tutors of a group |
|
|
|
* @param int $group_id |
|
|
|
* @param int $group_id (iid) |
|
|
|
* @return array An array with information of all users from the given group. |
|
|
|
* @return array An array with information of all users from the given group. |
|
|
|
* (user_id, firstname, lastname, email) |
|
|
|
* (user_id, firstname, lastname, email) |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -1553,11 +1552,13 @@ class GroupManager |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT tg.id, u.user_id, u.lastname, u.firstname, u.email |
|
|
|
$sql = "SELECT tg.id, u.user_id, u.lastname, u.firstname, u.email |
|
|
|
FROM ".$table_user." u, ".$table_group_tutor." tg |
|
|
|
FROM $table_user u, $table_group_tutor tg |
|
|
|
WHERE |
|
|
|
WHERE |
|
|
|
tg.c_id = $course_id AND |
|
|
|
tg.c_id = $course_id AND |
|
|
|
tg.group_id='".$group_id."' AND |
|
|
|
tg.group_id = $group_id AND |
|
|
|
tg.user_id=u.user_id".$order_clause; |
|
|
|
tg.user_id = u.user_id |
|
|
|
|
|
|
|
$order_clause |
|
|
|
|
|
|
|
"; |
|
|
|
$db_result = Database::query($sql); |
|
|
|
$db_result = Database::query($sql); |
|
|
|
$users = array (); |
|
|
|
$users = array (); |
|
|
|
while ($user = Database::fetch_object($db_result)) { |
|
|
|
while ($user = Database::fetch_object($db_result)) { |
|
|
@ -1578,7 +1579,7 @@ class GroupManager |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Subscribe user(s) to a specified group in current course (as a student) |
|
|
|
* Subscribe user(s) to a specified group in current course (as a student) |
|
|
|
* @param mixed $user_ids Can be an array with user-id's or a single user-id |
|
|
|
* @param mixed $user_ids Can be an array with user-id's or a single user-id |
|
|
|
* @param int $group_id |
|
|
|
* @param int $group_id iid |
|
|
|
* @param int $course_id |
|
|
|
* @param int $course_id |
|
|
|
* @return bool TRUE if successful |
|
|
|
* @return bool TRUE if successful |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -1606,26 +1607,26 @@ class GroupManager |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Subscribe tutor(s) to a specified group in current course |
|
|
|
* Subscribe tutor(s) to a specified group in current course |
|
|
|
* @param mixed $user_ids Can be an array with user-id's or a single user-id |
|
|
|
* @param mixed $user_ids Can be an array with user-id's or a single user-id |
|
|
|
* @param int $group_id |
|
|
|
* @param int $group_id iid |
|
|
|
* @param int $course_id |
|
|
|
* @param int $course_id |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
* @see subscribe_users. This function is almost an exact copy of that function. |
|
|
|
* @see subscribe_users. This function is almost an exact copy of that function. |
|
|
|
* @return bool TRUE if successful |
|
|
|
* @return bool TRUE if successful |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function subscribe_tutors($user_ids, $group_id, $course_id = null) |
|
|
|
public static function subscribe_tutors($user_ids, $groupId, $course_id = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$user_ids = is_array($user_ids) ? $user_ids : array($user_ids); |
|
|
|
$user_ids = is_array($user_ids) ? $user_ids : array($user_ids); |
|
|
|
$result = true; |
|
|
|
$result = true; |
|
|
|
$course_id = isset($course_id) && !empty($course_id) ? intval($course_id) : api_get_course_int_id(); |
|
|
|
$course_id = isset($course_id) && !empty($course_id) ? intval($course_id) : api_get_course_int_id(); |
|
|
|
$table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR); |
|
|
|
$table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR); |
|
|
|
$group_id = intval($group_id); |
|
|
|
$groupId = (int) $groupId; |
|
|
|
|
|
|
|
|
|
|
|
foreach ($user_ids as $user_id) { |
|
|
|
foreach ($user_ids as $user_id) { |
|
|
|
$user_id = intval($user_id); |
|
|
|
$user_id = intval($user_id); |
|
|
|
if (self::can_user_subscribe($user_id, $group_id, false)) { |
|
|
|
if (self::can_user_subscribe($user_id, $groupId, false)) { |
|
|
|
$sql = "INSERT INTO " . $table_group_tutor . " (c_id, user_id, group_id) |
|
|
|
$sql = "INSERT INTO " . $table_group_tutor . " (c_id, user_id, group_id) |
|
|
|
VALUES ('$course_id', '" . $user_id . "', '" . $group_id . "')"; |
|
|
|
VALUES ('$course_id', '" . $user_id . "', '" . $groupId . "')"; |
|
|
|
$result = Database::query($sql); |
|
|
|
$result = Database::query($sql); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1636,7 +1637,7 @@ class GroupManager |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Unsubscribe user(s) from a specified group in current course |
|
|
|
* Unsubscribe user(s) from a specified group in current course |
|
|
|
* @param mixed $user_ids Can be an array with user-id's or a single user-id |
|
|
|
* @param mixed $user_ids Can be an array with user-id's or a single user-id |
|
|
|
* @param int $group_id |
|
|
|
* @param int $group_id iid |
|
|
|
* @return bool TRUE if successful |
|
|
|
* @return bool TRUE if successful |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function unsubscribe_users($user_ids, $group_id) |
|
|
|
public static function unsubscribe_users($user_ids, $group_id) |
|
|
@ -1656,52 +1657,40 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Unsubscribe all users from one or more groups |
|
|
|
* Unsubscribe all users from one or more groups |
|
|
|
* @param mixed $group_id Can be an array with group-id's or a single group-id |
|
|
|
* @param int $group_id iid |
|
|
|
* @return bool TRUE if successful |
|
|
|
* @return bool TRUE if successful |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function unsubscribe_all_users($group_ids) |
|
|
|
public static function unsubscribe_all_users($groupId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
|
|
|
//api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i]) |
|
|
|
|
|
|
|
|
|
|
|
$group_ids = is_array($group_ids) ? $group_ids : array($group_ids); |
|
|
|
$table_group_user = Database :: get_course_table(TABLE_GROUP_USER); |
|
|
|
$group_ids = array_map('intval', $group_ids); |
|
|
|
$sql = "DELETE FROM $table_group_user |
|
|
|
if (count($group_ids) > 0) { |
|
|
|
WHERE |
|
|
|
if (api_is_course_coach()) { |
|
|
|
group_id = $groupId AND |
|
|
|
for ($i = 0; $i < count($group_ids); $i++) { |
|
|
|
c_id = $course_id"; |
|
|
|
if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])) { |
|
|
|
$result = Database::query($sql); |
|
|
|
array_splice($group_ids, $i, 1); |
|
|
|
|
|
|
|
$i--; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (count($group_ids) == 0) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$table_group_user = Database :: get_course_table(TABLE_GROUP_USER); |
|
|
|
|
|
|
|
$sql = 'DELETE FROM '.$table_group_user.' |
|
|
|
|
|
|
|
WHERE group_id IN ('.implode(',', $group_ids).') AND c_id = '.$course_id; |
|
|
|
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
return $result; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Unsubscribe all tutors from one or more groups |
|
|
|
* Unsubscribe all tutors from one or more groups |
|
|
|
* @param mixed $group_id Can be an array with group-id's or a single group-id |
|
|
|
* @param int $groupId iid |
|
|
|
* @see unsubscribe_all_users. This function is almost an exact copy of that function. |
|
|
|
* @see unsubscribe_all_users. This function is almost an exact copy of that function. |
|
|
|
* @return bool TRUE if successful |
|
|
|
* @return bool TRUE if successful |
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function unsubscribe_all_tutors($group_ids) |
|
|
|
public static function unsubscribe_all_tutors($groupId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$group_ids = is_array($group_ids) ? $group_ids : array($group_ids); |
|
|
|
$groupId = (int) $groupId; |
|
|
|
if (count($group_ids) > 0) { |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($groupId) > 0) { |
|
|
|
$table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR); |
|
|
|
$table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR); |
|
|
|
$sql = 'DELETE FROM '.$table_group_tutor.' |
|
|
|
$sql = "DELETE FROM $table_group_tutor |
|
|
|
WHERE group_id IN ('.implode(',', $group_ids).') AND c_id = '.$course_id; |
|
|
|
WHERE group_id = $groupId AND c_id = $course_id"; |
|
|
|
$result = Database::query($sql); |
|
|
|
$result = Database::query($sql); |
|
|
|
return $result; |
|
|
|
return $result; |
|
|
|
} |
|
|
|
} |
|
|
@ -1711,7 +1700,7 @@ class GroupManager |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Is the user a tutor of this group? |
|
|
|
* Is the user a tutor of this group? |
|
|
|
* @param int $user_id the id of the user |
|
|
|
* @param int $user_id the id of the user |
|
|
|
* @param int $group_id the id of the group |
|
|
|
* @param int $group_id the iid of the group |
|
|
|
* @return boolean true/false |
|
|
|
* @return boolean true/false |
|
|
|
* @todo use the function user_has_access that includes this function |
|
|
|
* @todo use the function user_has_access that includes this function |
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
@ -1723,8 +1712,11 @@ class GroupManager |
|
|
|
$group_id = intval($group_id); |
|
|
|
$group_id = intval($group_id); |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM ".$table_group_tutor." |
|
|
|
$sql = "SELECT * FROM $table_group_tutor |
|
|
|
WHERE c_id = $course_id AND user_id='".$user_id."' AND group_id='".$group_id."'"; |
|
|
|
WHERE |
|
|
|
|
|
|
|
c_id = $course_id AND |
|
|
|
|
|
|
|
user_id = $user_id AND |
|
|
|
|
|
|
|
group_id = $group_id"; |
|
|
|
$result = Database::query($sql); |
|
|
|
$result = Database::query($sql); |
|
|
|
if (Database::num_rows($result) > 0) { |
|
|
|
if (Database::num_rows($result) > 0) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -1741,7 +1733,7 @@ class GroupManager |
|
|
|
* 1. a member of the group OR |
|
|
|
* 1. a member of the group OR |
|
|
|
* 2. a tutor of the group. This function combines both |
|
|
|
* 2. a tutor of the group. This function combines both |
|
|
|
* @param int $user_id the id of the user |
|
|
|
* @param int $user_id the id of the user |
|
|
|
* @param int $group_id the id of the group |
|
|
|
* @param int $group_id the iid of the group |
|
|
|
* @return boolean true/false |
|
|
|
* @return boolean true/false |
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -1749,7 +1741,7 @@ class GroupManager |
|
|
|
{ |
|
|
|
{ |
|
|
|
$member = self :: is_subscribed($user_id, $group_id); |
|
|
|
$member = self :: is_subscribed($user_id, $group_id); |
|
|
|
$tutor = self :: is_tutor_of_group($user_id, $group_id); |
|
|
|
$tutor = self :: is_tutor_of_group($user_id, $group_id); |
|
|
|
if ($member OR $tutor) { |
|
|
|
if ($member || $tutor) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -1798,76 +1790,6 @@ class GroupManager |
|
|
|
return $groups; |
|
|
|
return $groups; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Get a combined list of all users of the real course $course_code |
|
|
|
|
|
|
|
* and all users in virtual courses linked to this course $course_code |
|
|
|
|
|
|
|
* Filter user list: remove duplicate users; plus |
|
|
|
|
|
|
|
* remove users that |
|
|
|
|
|
|
|
* - are already in the current group $group_id; |
|
|
|
|
|
|
|
* - do not have student status in these courses; |
|
|
|
|
|
|
|
* - are not appointed as tutor (group assistent) for this group; |
|
|
|
|
|
|
|
* - have already reached their maximum # of groups in this course. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Originally to get the correct list of users a big SQL statement was used, |
|
|
|
|
|
|
|
* but this has become more complicated now there is not just one real course but many virtual courses. |
|
|
|
|
|
|
|
* Still, that could have worked as well. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @version 1.1.3 |
|
|
|
|
|
|
|
* @author Roan Embrechts |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static function get_complete_list_of_users_that_can_be_added_to_group($course_code, $group_id) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$_course = api_get_course_info(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$category = self :: get_category_from_group($group_id, $course_code); |
|
|
|
|
|
|
|
$number_of_groups_limit = $category['groups_per_user'] == self::GROUP_PER_MEMBER_NO_LIMIT ? self::INFINITE : $category['groups_per_user']; |
|
|
|
|
|
|
|
$real_course_code = $_course['sysCode']; |
|
|
|
|
|
|
|
$real_course_info = api_get_course_info($real_course_code); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add real course to the list |
|
|
|
|
|
|
|
$user_subscribed_course_list = array($real_course_info); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// for all courses... |
|
|
|
|
|
|
|
foreach ($user_subscribed_course_list as $this_course) { |
|
|
|
|
|
|
|
$this_course_code = $this_course['code']; |
|
|
|
|
|
|
|
$course_user_list = CourseManager :: get_user_list_from_course_code($this_course_code); |
|
|
|
|
|
|
|
//for all users in the course |
|
|
|
|
|
|
|
foreach ($course_user_list as $this_user) { |
|
|
|
|
|
|
|
$user_id = $this_user['user_id']; |
|
|
|
|
|
|
|
$loginname = $this_user['username']; |
|
|
|
|
|
|
|
$lastname = $this_user['lastname']; |
|
|
|
|
|
|
|
$firstname = $this_user['firstname']; |
|
|
|
|
|
|
|
$status = $this_user['status']; |
|
|
|
|
|
|
|
//$role = $this_user['role']; |
|
|
|
|
|
|
|
$isTutor = $this_user['is_tutor']; |
|
|
|
|
|
|
|
$full_name = api_get_person_name($firstname, $lastname); |
|
|
|
|
|
|
|
if ($lastname == "" || $firstname == '') { |
|
|
|
|
|
|
|
$full_name = $loginname; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$complete_user['user_id'] = $user_id; |
|
|
|
|
|
|
|
$complete_user['full_name'] = $full_name; |
|
|
|
|
|
|
|
$complete_user['firstname'] = $firstname; |
|
|
|
|
|
|
|
$complete_user['lastname'] = $lastname; |
|
|
|
|
|
|
|
$complete_user['status'] = $status; |
|
|
|
|
|
|
|
$complete_user['is_tutor'] = $isTutor; |
|
|
|
|
|
|
|
$student_number_of_groups = self :: user_in_number_of_groups($user_id, $category['id']); |
|
|
|
|
|
|
|
//filter: only add users that have not exceeded their maximum amount of groups |
|
|
|
|
|
|
|
if ($student_number_of_groups < $number_of_groups_limit) { |
|
|
|
|
|
|
|
$complete_user_list[] = $complete_user; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (is_array($complete_user_list)) { |
|
|
|
|
|
|
|
//sort once, on array field "full_name" |
|
|
|
|
|
|
|
$complete_user_list = TableSort :: sort_table($complete_user_list, "full_name"); |
|
|
|
|
|
|
|
//filter out duplicates, based on field "user_id" |
|
|
|
|
|
|
|
$complete_user_list = self :: filter_duplicates($complete_user_list, "user_id"); |
|
|
|
|
|
|
|
$complete_user_list = self :: filter_users_already_in_group($complete_user_list, $group_id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $complete_user_list; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Filter out duplicates in a multidimensional array |
|
|
|
* Filter out duplicates in a multidimensional array |
|
|
|
* by comparing field $compare_field. |
|
|
|
* by comparing field $compare_field. |
|
|
@ -1888,18 +1810,6 @@ class GroupManager |
|
|
|
} |
|
|
|
} |
|
|
|
return $user_array_out; |
|
|
|
return $user_array_out; |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
|
|
|
|
|
|
* Filters from the array $user_array_in the users already in the group $group_id. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static function filter_users_already_in_group($user_array_in, $group_id) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach ($user_array_in as $this_user) { |
|
|
|
|
|
|
|
if (!self :: is_subscribed($this_user['user_id'], $group_id)) { |
|
|
|
|
|
|
|
$user_array_out[] = $this_user; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $user_array_out; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Remove all users that are not students and all users who have tutor status |
|
|
|
* Remove all users that are not students and all users who have tutor status |
|
|
@ -1998,7 +1908,7 @@ class GroupManager |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case self::TOOL_PRIVATE: |
|
|
|
case self::TOOL_PRIVATE: |
|
|
|
$userIsInGroup = self::is_user_in_group($user_id, $group_id); |
|
|
|
$userIsInGroup = self::is_user_in_group($user_id, $groupInfo['iid']); |
|
|
|
if ($userIsInGroup) { |
|
|
|
if ($userIsInGroup) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -2030,7 +1940,7 @@ class GroupManager |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$groupId = $groupInfo['id']; |
|
|
|
$groupId = $groupInfo['id']; |
|
|
|
$tutors = self::get_subscribed_tutors($groupId, true); |
|
|
|
$tutors = self::get_subscribed_tutors($groupInfo['iid'], true); |
|
|
|
|
|
|
|
|
|
|
|
if (in_array($userId, $tutors)) { |
|
|
|
if (in_array($userId, $tutors)) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -2123,29 +2033,19 @@ class GroupManager |
|
|
|
* Fill the groups with students. |
|
|
|
* Fill the groups with students. |
|
|
|
* |
|
|
|
* |
|
|
|
* note : optimize fill_groups_list <--> fill_groups |
|
|
|
* note : optimize fill_groups_list <--> fill_groups |
|
|
|
* @param array $group_ids |
|
|
|
* @param int $groupId (group iid) |
|
|
|
* @return array|bool |
|
|
|
* @return array|bool |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function fill_groups_list($group_ids) |
|
|
|
public static function fill_groups_list($groupId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$group_ids = is_array($group_ids) ? $group_ids : array($group_ids); |
|
|
|
$groupId = (int) $groupId; |
|
|
|
$group_ids = array_map('intval', $group_ids); |
|
|
|
$_course = api_get_course_info(); |
|
|
|
|
|
|
|
|
|
|
|
if (api_is_course_coach()) { |
|
|
|
if (empty($_course) || empty($groupId)) { |
|
|
|
for ($i = 0; $i < count($group_ids); $i++) { |
|
|
|
return []; |
|
|
|
if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])) { |
|
|
|
|
|
|
|
array_splice($group_ids, $i, 1); |
|
|
|
|
|
|
|
$i--; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (count($group_ids) == 0) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$_course = api_get_course_info(); |
|
|
|
$category = self::get_category_from_group($groupId); |
|
|
|
|
|
|
|
|
|
|
|
$category = self :: get_category_from_group($group_ids[0]); |
|
|
|
|
|
|
|
$number_groups_per_user = self::GROUP_PER_MEMBER_NO_LIMIT; |
|
|
|
$number_groups_per_user = self::GROUP_PER_MEMBER_NO_LIMIT; |
|
|
|
$categoryId = 0; |
|
|
|
$categoryId = 0; |
|
|
|
if ($category) { |
|
|
|
if ($category) { |
|
|
@ -2165,13 +2065,13 @@ class GroupManager |
|
|
|
* (reverse) ordered by the number of place available |
|
|
|
* (reverse) ordered by the number of place available |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
$sql = "SELECT g.id gid, count(ug.user_id) count_users, g.max_student |
|
|
|
$sql = "SELECT g.id gid, count(ug.user_id) count_users, g.max_student |
|
|
|
FROM ".$group_table." g |
|
|
|
FROM $group_table g |
|
|
|
LEFT JOIN ".$group_user_table." ug |
|
|
|
LEFT JOIN $group_user_table ug |
|
|
|
ON g.id = ug.group_id |
|
|
|
ON g.iid = ug.group_id |
|
|
|
WHERE g.c_id = $course_id AND |
|
|
|
WHERE g.c_id = $course_id AND |
|
|
|
ug.c_id = $course_id AND |
|
|
|
ug.c_id = $course_id AND |
|
|
|
g.id IN (".implode(',', $group_ids).") |
|
|
|
g.iid = $groupId |
|
|
|
GROUP BY (g.id)"; |
|
|
|
GROUP BY (g.iid)"; |
|
|
|
|
|
|
|
|
|
|
|
$sql_result = Database::query($sql); |
|
|
|
$sql_result = Database::query($sql); |
|
|
|
$group_available_place = array(); |
|
|
|
$group_available_place = array(); |
|
|
@ -2223,9 +2123,7 @@ class GroupManager |
|
|
|
$user_info = api_get_user_info(); |
|
|
|
$user_info = api_get_user_info(); |
|
|
|
$session_id = api_get_session_id(); |
|
|
|
$session_id = api_get_session_id(); |
|
|
|
$user_id = $user_info['user_id']; |
|
|
|
$user_id = $user_info['user_id']; |
|
|
|
|
|
|
|
|
|
|
|
$orig = isset($origin) ? $origin : null; |
|
|
|
$orig = isset($origin) ? $origin : null; |
|
|
|
|
|
|
|
|
|
|
|
$hideGroup = api_get_setting('hide_course_group_if_no_tools_available'); |
|
|
|
$hideGroup = api_get_setting('hide_course_group_if_no_tools_available'); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($group_list as $this_group) { |
|
|
|
foreach ($group_list as $this_group) { |
|
|
@ -2234,8 +2132,8 @@ class GroupManager |
|
|
|
$session_img = api_get_session_image($this_group['session_id'], $user_info['status']); |
|
|
|
$session_img = api_get_session_image($this_group['session_id'], $user_info['status']); |
|
|
|
|
|
|
|
|
|
|
|
// All the tutors of this group |
|
|
|
// All the tutors of this group |
|
|
|
$tutorsids_of_group = self::get_subscribed_tutors($this_group['id'], true); |
|
|
|
$tutorsids_of_group = self::get_subscribed_tutors($this_group['iid'], true); |
|
|
|
$isMember = self::is_subscribed($user_id, $this_group['id']); |
|
|
|
$isMember = self::is_subscribed($user_id, $this_group['iid']); |
|
|
|
|
|
|
|
|
|
|
|
// Create a new table-row |
|
|
|
// Create a new table-row |
|
|
|
$row = array(); |
|
|
|
$row = array(); |
|
|
@ -2306,9 +2204,9 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
|
|
// Self-registration / unregistration |
|
|
|
// Self-registration / unregistration |
|
|
|
if (!api_is_allowed_to_edit(false, true)) { |
|
|
|
if (!api_is_allowed_to_edit(false, true)) { |
|
|
|
if (self :: is_self_registration_allowed($user_id, $this_group['id'])) { |
|
|
|
if (self :: is_self_registration_allowed($user_id, $this_group['iid'])) { |
|
|
|
$row[] = '<a class = "btn btn-default" href="group.php?'.api_get_cidreq().'&category='.$category_id.'&action=self_reg&group_id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;">'.get_lang('GroupSelfRegInf').'</a>'; |
|
|
|
$row[] = '<a class = "btn btn-default" href="group.php?'.api_get_cidreq().'&category='.$category_id.'&action=self_reg&group_id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;">'.get_lang('GroupSelfRegInf').'</a>'; |
|
|
|
} elseif (self :: is_self_unregistration_allowed($user_id, $this_group['id'])) { |
|
|
|
} elseif (self :: is_self_unregistration_allowed($user_id, $this_group['iid'])) { |
|
|
|
$row[] = '<a class = "btn btn-default" href="group.php?'.api_get_cidreq().'&category='.$category_id.'&action=self_unreg&group_id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;">'.get_lang('GroupSelfUnRegInf').'</a>'; |
|
|
|
$row[] = '<a class = "btn btn-default" href="group.php?'.api_get_cidreq().'&category='.$category_id.'&action=self_unreg&group_id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;">'.get_lang('GroupSelfUnRegInf').'</a>'; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$row[] = '-'; |
|
|
|
$row[] = '-'; |
|
|
|