|
|
|
|
@ -131,7 +131,7 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
$groups = array(); |
|
|
|
|
while ($thisGroup = Database::fetch_array($groupList)) { |
|
|
|
|
$thisGroup['number_of_members'] = count(self::get_subscribed_users($thisGroup['iid'])); |
|
|
|
|
$thisGroup['number_of_members'] = count(self::get_subscribed_users($thisGroup)); |
|
|
|
|
if ($thisGroup['session_id'] != 0) { |
|
|
|
|
$sql = 'SELECT name FROM '.Database::get_main_table(TABLE_MAIN_SESSION).' |
|
|
|
|
WHERE id='.$thisGroup['session_id']; |
|
|
|
|
@ -330,11 +330,13 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
$members = array(); |
|
|
|
|
foreach ($users as $index => $user_id) { |
|
|
|
|
$groupId = $group_ids[$index % $number_of_groups]; |
|
|
|
|
$groupInfo = self::get_group_properties($groupId); |
|
|
|
|
self::subscribe_users( |
|
|
|
|
$user_id, |
|
|
|
|
$group_ids[$index % $number_of_groups] |
|
|
|
|
$groupInfo |
|
|
|
|
); |
|
|
|
|
$members[$group_ids[$index % $number_of_groups]]++; |
|
|
|
|
$members[$group_ids[$groupId]]++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach ($members as $group_id => $places) { |
|
|
|
|
@ -363,7 +365,8 @@ class GroupManager |
|
|
|
|
0, |
|
|
|
|
count($users_ids) |
|
|
|
|
); |
|
|
|
|
self::subscribe_users($users_ids, $group_id); |
|
|
|
|
$groupInfo = self::get_group_properties($group_id); |
|
|
|
|
self::subscribe_users($users_ids, $groupInfo); |
|
|
|
|
$group_ids[] = $group_id; |
|
|
|
|
} |
|
|
|
|
return $group_ids; |
|
|
|
|
@ -374,11 +377,11 @@ class GroupManager |
|
|
|
|
* @author Christophe Gesche <christophe.gesche@claroline.net> |
|
|
|
|
* @author Hugues Peeters <hugues.peeters@claroline.net> |
|
|
|
|
* @author Bart Mollet |
|
|
|
|
* @param int $groupId iid |
|
|
|
|
* @param array $groupInfo iid |
|
|
|
|
* @param string $course_code Default is current course |
|
|
|
|
* @return integer - number of groups deleted. |
|
|
|
|
*/ |
|
|
|
|
public static function delete_groups($groupId, $course_code = null) |
|
|
|
|
public static function delete_groups($groupInfo, $course_code = null) |
|
|
|
|
{ |
|
|
|
|
$course_info = api_get_course_info($course_code); |
|
|
|
|
$course_id = $course_info['real_id']; |
|
|
|
|
@ -386,26 +389,26 @@ class GroupManager |
|
|
|
|
// Database table definitions |
|
|
|
|
$group_table = Database:: get_course_table(TABLE_GROUP); |
|
|
|
|
$forum_table = Database:: get_course_table(TABLE_FORUM); |
|
|
|
|
$groupId = (int) $groupId; |
|
|
|
|
|
|
|
|
|
$sql = "SELECT id, iid, secret_directory, session_id |
|
|
|
|
FROM $group_table |
|
|
|
|
WHERE c_id = $course_id AND iid = $groupId"; |
|
|
|
|
$db_result = Database::query($sql); |
|
|
|
|
|
|
|
|
|
$group = Database::fetch_object($db_result); |
|
|
|
|
if ($group) { |
|
|
|
|
$groupInfo = self::get_group_properties($groupInfo['iid'], true); |
|
|
|
|
if ($groupInfo) { |
|
|
|
|
$groupIid = $groupInfo['iid']; |
|
|
|
|
$groupId = $groupInfo['id']; |
|
|
|
|
$directory = $groupInfo['secret_directory']; |
|
|
|
|
// Unsubscribe all users |
|
|
|
|
self::unsubscribe_all_users($groupId); |
|
|
|
|
self::unsubscribe_all_tutors($groupId); |
|
|
|
|
self::unsubscribe_all_users($groupInfo); |
|
|
|
|
self::unsubscribe_all_tutors($groupInfo); |
|
|
|
|
// 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".$directory; |
|
|
|
|
// File to renamed |
|
|
|
|
$destination_dir = api_get_path(SYS_COURSE_PATH).$course_info['path']."/document".$group->secret_directory.'_DELETED_'.$group->id; |
|
|
|
|
$destination_dir = api_get_path(SYS_COURSE_PATH).$course_info['path']."/document".$directory.'_DELETED_'.$groupInfo['id']; |
|
|
|
|
|
|
|
|
|
if (!empty($group->secret_directory)) { |
|
|
|
|
if (!empty($directory)) { |
|
|
|
|
//Deleting from document tool |
|
|
|
|
DocumentManager::delete_document($course_info, $group->secret_directory, $source_directory); |
|
|
|
|
DocumentManager::delete_document( |
|
|
|
|
$course_info, |
|
|
|
|
$directory, |
|
|
|
|
$source_directory |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (file_exists($source_directory)) { |
|
|
|
|
if (api_get_setting('permanently_remove_deleted_files') === 'true') { |
|
|
|
|
@ -430,7 +433,7 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
// delete the groups |
|
|
|
|
$sql = "DELETE FROM $group_table |
|
|
|
|
WHERE c_id = $course_id AND iid = $groupId "; |
|
|
|
|
WHERE c_id = $course_id AND iid = $groupIid "; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -440,6 +443,7 @@ class GroupManager |
|
|
|
|
/** |
|
|
|
|
* Get group properties |
|
|
|
|
* @param int $group_id The group from which properties are requested. |
|
|
|
|
* @param bool $useIid |
|
|
|
|
* @return array All properties. Array-keys are: |
|
|
|
|
* name, tutor_id, description, maximum_number_of_students, |
|
|
|
|
* directory and visibility of tools |
|
|
|
|
@ -483,10 +487,10 @@ class GroupManager |
|
|
|
|
$result['self_registration_allowed'] = $db_object->self_registration_allowed; |
|
|
|
|
$result['self_unregistration_allowed'] = $db_object->self_unregistration_allowed; |
|
|
|
|
$result['count_users'] = count( |
|
|
|
|
self::get_subscribed_users($db_object->iid) |
|
|
|
|
self::get_subscribed_users($result) |
|
|
|
|
); |
|
|
|
|
$result['count_tutor'] = count( |
|
|
|
|
self::get_subscribed_tutors($db_object->iid) |
|
|
|
|
self::get_subscribed_tutors($result) |
|
|
|
|
); |
|
|
|
|
$result['count_all'] = $result['count_users'] + $result['count_tutor']; |
|
|
|
|
} |
|
|
|
|
@ -775,7 +779,8 @@ class GroupManager |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
if (Database::num_rows($res) > 0) { |
|
|
|
|
while ($group = Database::fetch_object($res)) { |
|
|
|
|
self::delete_groups($group->iid, $course_code); |
|
|
|
|
$groupInfo = self::get_group_properties($group->iid, true); |
|
|
|
|
self::delete_groups($groupInfo, $course_code); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$sql = "DELETE FROM $table_group_cat |
|
|
|
|
@ -948,7 +953,7 @@ class GroupManager |
|
|
|
|
*/ |
|
|
|
|
public static function get_current_max_groups_per_user($category_id = null, $course_code = null) |
|
|
|
|
{ |
|
|
|
|
$course_info = api_get_course_info ($course_code); |
|
|
|
|
$course_info = api_get_course_info($course_code); |
|
|
|
|
$group_table = Database::get_course_table(TABLE_GROUP); |
|
|
|
|
$group_user_table = Database::get_course_table(TABLE_GROUP_USER); |
|
|
|
|
$sql = 'SELECT COUNT(gu.group_id) AS current_max |
|
|
|
|
@ -1018,7 +1023,6 @@ class GroupManager |
|
|
|
|
$group_user_table = Database::get_course_table(TABLE_GROUP_USER); |
|
|
|
|
$groupTable = Database::get_course_table(TABLE_GROUP); |
|
|
|
|
$user_table = Database::get_main_table(TABLE_MAIN_USER); |
|
|
|
|
|
|
|
|
|
$group_id = intval($group_id); |
|
|
|
|
|
|
|
|
|
if (empty($courseId)) { |
|
|
|
|
@ -1071,7 +1075,7 @@ class GroupManager |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param int $group_id |
|
|
|
|
* @param int $group_id id |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public static function getStudentsAndTutors($group_id) |
|
|
|
|
@ -1109,21 +1113,21 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get only tutors from a group |
|
|
|
|
* @param int $group_id iid |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public static function getTutors($group_id) |
|
|
|
|
public static function getTutors($groupInfo) |
|
|
|
|
{ |
|
|
|
|
$groupTable = Database::get_course_table(TABLE_GROUP); |
|
|
|
|
$tutor_user_table = Database::get_course_table(TABLE_GROUP_TUTOR); |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
$group_id = intval($group_id); |
|
|
|
|
$group_id = intval($groupInfo['iid']); |
|
|
|
|
|
|
|
|
|
$sql = "SELECT user_id |
|
|
|
|
FROM $tutor_user_table gu |
|
|
|
|
INNER JOIN $groupTable g |
|
|
|
|
ON (gu.group_id = g.id and g.c_id = gu.c_id) |
|
|
|
|
WHERE gu.c_id = $course_id AND g.id = $group_id"; |
|
|
|
|
WHERE gu.c_id = $course_id AND g.iid = $group_id"; |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
|
|
|
|
|
$users = array(); |
|
|
|
|
@ -1209,25 +1213,30 @@ class GroupManager |
|
|
|
|
* ywarnier:> Now the course_id has been removed (25/1/2005) |
|
|
|
|
* The databases are als very inconsistent in this. |
|
|
|
|
* |
|
|
|
|
* @param int $groupId iid |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @author Chrisptophe Gesche <christophe.geshe@claroline.net>, |
|
|
|
|
* Hugues Peeters <hugues.peeters@claroline.net> - original version |
|
|
|
|
* @author Roan Embrechts - virtual course support, code cleaning |
|
|
|
|
* @author Bart Mollet - code cleaning, use other GroupManager-functions |
|
|
|
|
* @return void |
|
|
|
|
*/ |
|
|
|
|
public static function fill_groups($groupId) |
|
|
|
|
public static function fill_groups($groupInfo) |
|
|
|
|
{ |
|
|
|
|
$_course = api_get_course_info(); |
|
|
|
|
$groupId = (int) $groupId; |
|
|
|
|
$groupIid = $groupInfo['iid']; |
|
|
|
|
$groupId = $groupInfo['id']; |
|
|
|
|
|
|
|
|
|
$category = self::get_category_from_group($groupId); |
|
|
|
|
$category = self::get_category_from_group($groupIid); |
|
|
|
|
$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_user_table = Database:: get_course_table(TABLE_GROUP_USER); |
|
|
|
|
$session_id = api_get_session_id(); |
|
|
|
|
|
|
|
|
|
$complete_user_list = CourseManager::get_real_and_linked_user_list($_course['code'], true, $session_id); |
|
|
|
|
$complete_user_list = CourseManager::get_real_and_linked_user_list( |
|
|
|
|
$_course['code'], |
|
|
|
|
true, |
|
|
|
|
$session_id |
|
|
|
|
); |
|
|
|
|
$number_groups_per_user = $groups_per_user == self::GROUP_PER_MEMBER_NO_LIMIT ? self::INFINITE : $groups_per_user; |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
@ -1241,9 +1250,9 @@ class GroupManager |
|
|
|
|
LEFT JOIN $group_user_table ug ON |
|
|
|
|
g.c_id = $course_id AND |
|
|
|
|
ug.c_id = $course_id AND |
|
|
|
|
g.iid = ug.group_id |
|
|
|
|
g.id = ug.group_id |
|
|
|
|
WHERE |
|
|
|
|
g.iid = $groupId |
|
|
|
|
g.id = $groupId |
|
|
|
|
GROUP BY (g.iid) |
|
|
|
|
HAVING (nbPlaces > 0 OR g.max_student = ".self::MEMBER_PER_GROUP_NO_LIMIT.") |
|
|
|
|
ORDER BY nbPlaces DESC"; |
|
|
|
|
@ -1267,7 +1276,6 @@ class GroupManager |
|
|
|
|
$complete_user_list[$i]['number_groups_left'] = $number_groups_per_user - $number_of_groups; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//first sort by user_id to filter out duplicates |
|
|
|
|
$complete_user_list = TableSort::sort_table($complete_user_list, 'user_id'); |
|
|
|
|
$complete_user_list = self::filter_duplicates($complete_user_list, 'user_id'); |
|
|
|
|
@ -1291,11 +1299,12 @@ class GroupManager |
|
|
|
|
reset($userToken); |
|
|
|
|
arsort($userToken); |
|
|
|
|
|
|
|
|
|
foreach ($group_available_place as $group_id => $place) { |
|
|
|
|
foreach ($group_available_place as $groupIid => $place) { |
|
|
|
|
foreach ($userToken as $user_id => $places) { |
|
|
|
|
if (self::can_user_subscribe($user_id, $group_id)) { |
|
|
|
|
self::subscribe_users($user_id, $group_id); |
|
|
|
|
$group_available_place[$group_id]--; |
|
|
|
|
$groupInfo = self::get_group_properties($groupIid, true); |
|
|
|
|
if (self::can_user_subscribe($user_id, $groupInfo)) { |
|
|
|
|
self::subscribe_users($user_id, $groupInfo); |
|
|
|
|
$group_available_place[$groupIid]--; |
|
|
|
|
unset($userToken[$user_id]); |
|
|
|
|
$changed = true; |
|
|
|
|
break; |
|
|
|
|
@ -1310,7 +1319,7 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get the number of students in a group. |
|
|
|
|
* @param int $group_id iid |
|
|
|
|
* @param int $group_id id |
|
|
|
|
* @return int Number of students in the given group. |
|
|
|
|
*/ |
|
|
|
|
public static function number_of_students($group_id, $course_id = null) |
|
|
|
|
@ -1322,7 +1331,7 @@ class GroupManager |
|
|
|
|
} else { |
|
|
|
|
$course_id = intval($course_id); |
|
|
|
|
} |
|
|
|
|
$sql = "SELECT COUNT(*) AS number_of_students |
|
|
|
|
$sql = "SELECT COUNT(*) AS number_of_students |
|
|
|
|
FROM $table_group_user |
|
|
|
|
WHERE c_id = $course_id AND group_id = $group_id"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
@ -1385,30 +1394,31 @@ class GroupManager |
|
|
|
|
/** |
|
|
|
|
* Is sef-registration allowed? |
|
|
|
|
* @param int $user_id |
|
|
|
|
* @param int $group_id iid |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @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, $groupInfo) |
|
|
|
|
{ |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
if (!$user_id > 0) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
$groupIid = $groupInfo['iid']; |
|
|
|
|
$groupId = $groupInfo['id']; |
|
|
|
|
|
|
|
|
|
$table_group = Database::get_course_table(TABLE_GROUP); |
|
|
|
|
$group_id = intval($group_id); |
|
|
|
|
if (isset($group_id)) { |
|
|
|
|
$sql = "SELECT status, self_registration_allowed |
|
|
|
|
FROM $table_group |
|
|
|
|
WHERE c_id = $course_id AND iid = $group_id"; |
|
|
|
|
WHERE c_id = $course_id AND iid = $groupIid"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
$group = Database::fetch_object($result); |
|
|
|
|
|
|
|
|
|
if ($group->status == 0 || $group->self_registration_allowed != 1) { |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return self::can_user_subscribe($user_id, $group_id); |
|
|
|
|
return self::can_user_subscribe($user_id, $groupInfo); |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
@ -1417,46 +1427,45 @@ class GroupManager |
|
|
|
|
/** |
|
|
|
|
* Is sef-unregistration allowed? |
|
|
|
|
* @param int $user_id |
|
|
|
|
* @param int $group_id iid |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @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, $groupInfo) |
|
|
|
|
{ |
|
|
|
|
if (!$user_id > 0) { |
|
|
|
|
if (!$user_id > 0 || empty($groupInfo)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
$groupIid = $groupInfo['iid']; |
|
|
|
|
$table_group = Database::get_course_table(TABLE_GROUP); |
|
|
|
|
$group_id = intval($group_id); |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
|
|
|
|
|
$sql = "SELECT status, self_unregistration_allowed |
|
|
|
|
FROM $table_group |
|
|
|
|
WHERE c_id = $course_id AND iid = $group_id"; |
|
|
|
|
WHERE c_id = $course_id AND iid = $groupIid"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
$group = Database::fetch_object($result); |
|
|
|
|
|
|
|
|
|
if ($group->status == 0 || $group->self_unregistration_allowed != 1) { |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return self::is_subscribed($user_id, $group_id); |
|
|
|
|
return self::is_subscribed($user_id, $groupInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Is user subscribed in group? |
|
|
|
|
* @param int $user_id |
|
|
|
|
* @param int $group_id iid |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @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, $groupInfo) |
|
|
|
|
{ |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
if (empty($user_id) || empty($group_id) || empty($course_id)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
$table_group_user = Database::get_course_table(TABLE_GROUP_USER); |
|
|
|
|
$group_id = intval($group_id); |
|
|
|
|
$group_id = intval($groupInfo['id']); |
|
|
|
|
$user_id = intval($user_id); |
|
|
|
|
|
|
|
|
|
$sql = "SELECT 1 FROM $table_group_user |
|
|
|
|
@ -1473,39 +1482,41 @@ class GroupManager |
|
|
|
|
/** |
|
|
|
|
* Can a user subscribe to a specified group in a course |
|
|
|
|
* @param int $user_id |
|
|
|
|
* @param int $group_id iid |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @param bool $checkMaxNumberStudents |
|
|
|
|
* |
|
|
|
|
* @return bool TRUE if given user can be subscribed in given group |
|
|
|
|
*/ |
|
|
|
|
public static function can_user_subscribe($user_id, $group_id, $checkMaxNumberStudents = true) |
|
|
|
|
public static function can_user_subscribe($user_id, $groupInfo, $checkMaxNumberStudents = true) |
|
|
|
|
{ |
|
|
|
|
$group_id = $groupInfo['id']; |
|
|
|
|
$groupIid = $groupInfo['iid']; |
|
|
|
|
if ($checkMaxNumberStudents) { |
|
|
|
|
$category = self:: get_category_from_group($group_id); |
|
|
|
|
$category = self::get_category_from_group($groupIid); |
|
|
|
|
if ($category) { |
|
|
|
|
if ($category['groups_per_user'] == self::GROUP_PER_MEMBER_NO_LIMIT) { |
|
|
|
|
$category['groups_per_user'] = self::INFINITE; |
|
|
|
|
} |
|
|
|
|
$result = self:: user_in_number_of_groups($user_id, $category['id'] ) < $category['groups_per_user']; |
|
|
|
|
$result = self:: user_in_number_of_groups($user_id, $category['id']) < $category['groups_per_user']; |
|
|
|
|
if ($result == false) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$result = self:: number_of_students($group_id) < self:: maximum_number_of_students($group_id); |
|
|
|
|
$result = self::number_of_students($group_id) < self:: maximum_number_of_students($groupIid); |
|
|
|
|
|
|
|
|
|
if ($result == false) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$result = self::is_tutor_of_group($user_id, $group_id); |
|
|
|
|
$result = self::is_tutor_of_group($user_id, $groupInfo); |
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$result = self::is_subscribed($user_id, $group_id); |
|
|
|
|
$result = self::is_subscribed($user_id, $groupInfo); |
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
|
return false; |
|
|
|
|
@ -1516,11 +1527,11 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get all subscribed users (members) from a group |
|
|
|
|
* @param int $group_id (iid) |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @return array An array with information of all users from the given group. |
|
|
|
|
* (user_id, firstname, lastname, email) |
|
|
|
|
*/ |
|
|
|
|
public static function get_subscribed_users($group_id) |
|
|
|
|
public static function get_subscribed_users($groupInfo) |
|
|
|
|
{ |
|
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER); |
|
|
|
|
$table_group_user = Database::get_course_table(TABLE_GROUP_USER); |
|
|
|
|
@ -1530,18 +1541,28 @@ class GroupManager |
|
|
|
|
$order_clause = " ORDER BY u.official_code, u.firstname, u.lastname"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$group_id = intval($groupInfo['id']); |
|
|
|
|
|
|
|
|
|
if (empty($group_id)) { |
|
|
|
|
return array(); |
|
|
|
|
} |
|
|
|
|
$group_id = intval($group_id); |
|
|
|
|
|
|
|
|
|
$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 INNER JOIN $table_group_user ug |
|
|
|
|
$sql = "SELECT |
|
|
|
|
ug.id, |
|
|
|
|
u.user_id, |
|
|
|
|
u.lastname, |
|
|
|
|
u.firstname, |
|
|
|
|
u.email, |
|
|
|
|
u.username |
|
|
|
|
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)) { |
|
|
|
|
@ -1560,11 +1581,11 @@ class GroupManager |
|
|
|
|
/** |
|
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
|
* Get all subscribed tutors of a group |
|
|
|
|
* @param int $group_id (iid) |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @return array An array with information of all users from the given group. |
|
|
|
|
* (user_id, firstname, lastname, email) |
|
|
|
|
*/ |
|
|
|
|
public static function get_subscribed_tutors($group_id, $id_only = false) |
|
|
|
|
public static function get_subscribed_tutors($groupInfo, $id_only = false) |
|
|
|
|
{ |
|
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER); |
|
|
|
|
$table_group_tutor = Database::get_course_table(TABLE_GROUP_TUTOR); |
|
|
|
|
@ -1575,7 +1596,7 @@ class GroupManager |
|
|
|
|
$order_clause = " ORDER BY u.official_code, u.firstname, u.lastname"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$group_id = intval($group_id); |
|
|
|
|
$group_id = intval($groupInfo['id']); |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
|
|
|
|
|
$sql = "SELECT tg.id, u.user_id, u.lastname, u.firstname, u.email |
|
|
|
|
@ -1606,20 +1627,20 @@ class GroupManager |
|
|
|
|
/** |
|
|
|
|
* 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 int $group_id iid |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @param int $course_id |
|
|
|
|
* @return bool TRUE if successful |
|
|
|
|
*/ |
|
|
|
|
public static function subscribe_users($user_ids, $group_id, $course_id = null) |
|
|
|
|
public static function subscribe_users($user_ids, $groupInfo, $course_id = null) |
|
|
|
|
{ |
|
|
|
|
$user_ids = is_array($user_ids) ? $user_ids : array($user_ids); |
|
|
|
|
$course_id = isset($course_id) && !empty($course_id) ? intval($course_id) : api_get_course_int_id(); |
|
|
|
|
$group_id = intval($group_id); |
|
|
|
|
$group_id = $groupInfo['id']; |
|
|
|
|
|
|
|
|
|
$table_group_user = Database::get_course_table(TABLE_GROUP_USER); |
|
|
|
|
if (!empty($user_ids)) { |
|
|
|
|
foreach ($user_ids as $user_id) { |
|
|
|
|
if (self::can_user_subscribe($user_id, $group_id)) { |
|
|
|
|
if (self::can_user_subscribe($user_id, $groupInfo)) { |
|
|
|
|
$user_id = intval($user_id); |
|
|
|
|
$sql = "INSERT INTO ".$table_group_user." (c_id, user_id, group_id) |
|
|
|
|
VALUES ('$course_id', '".$user_id."', '".$group_id."')"; |
|
|
|
|
@ -1634,24 +1655,24 @@ class GroupManager |
|
|
|
|
/** |
|
|
|
|
* 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 int $group_id iid |
|
|
|
|
* @param int $group_id id |
|
|
|
|
* @param int $course_id |
|
|
|
|
* |
|
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
|
* @see subscribe_users. This function is almost an exact copy of that function. |
|
|
|
|
* @return bool TRUE if successful |
|
|
|
|
*/ |
|
|
|
|
public static function subscribe_tutors($user_ids, $groupId, $course_id = null) |
|
|
|
|
public static function subscribe_tutors($user_ids, $groupInfo, $course_id = null) |
|
|
|
|
{ |
|
|
|
|
$user_ids = is_array($user_ids) ? $user_ids : array($user_ids); |
|
|
|
|
$result = true; |
|
|
|
|
$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); |
|
|
|
|
$groupId = (int) $groupId; |
|
|
|
|
$groupId = (int) $groupInfo['id']; |
|
|
|
|
|
|
|
|
|
foreach ($user_ids as $user_id) { |
|
|
|
|
$user_id = intval($user_id); |
|
|
|
|
if (self::can_user_subscribe($user_id, $groupId, false)) { |
|
|
|
|
if (self::can_user_subscribe($user_id, $groupInfo, false)) { |
|
|
|
|
$sql = "INSERT INTO " . $table_group_tutor . " (c_id, user_id, group_id) |
|
|
|
|
VALUES ('$course_id', '" . $user_id . "', '" . $groupId . "')"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
@ -1664,14 +1685,14 @@ class GroupManager |
|
|
|
|
/** |
|
|
|
|
* 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 int $group_id iid |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @return bool TRUE if successful |
|
|
|
|
*/ |
|
|
|
|
public static function unsubscribe_users($user_ids, $group_id) |
|
|
|
|
public static function unsubscribe_users($user_ids, $groupInfo) |
|
|
|
|
{ |
|
|
|
|
$user_ids = is_array($user_ids) ? $user_ids : array ($user_ids); |
|
|
|
|
$table_group_user = Database::get_course_table(TABLE_GROUP_USER); |
|
|
|
|
$group_id = intval($group_id); |
|
|
|
|
$group_id = intval($groupInfo['id']); |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
$sql = 'DELETE FROM '.$table_group_user.' |
|
|
|
|
WHERE |
|
|
|
|
@ -1684,15 +1705,13 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Unsubscribe all users from one or more groups |
|
|
|
|
* @param int $group_id iid |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @return bool TRUE if successful |
|
|
|
|
*/ |
|
|
|
|
public static function unsubscribe_all_users($groupId) |
|
|
|
|
public static function unsubscribe_all_users($groupInfo) |
|
|
|
|
{ |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
//api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i]) |
|
|
|
|
|
|
|
|
|
$groupId = (int) $groupId; |
|
|
|
|
$groupId = (int) $groupInfo['id']; |
|
|
|
|
if (empty($course_id) || empty($groupId)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
@ -1736,16 +1755,20 @@ class GroupManager |
|
|
|
|
/** |
|
|
|
|
* Is the user a tutor of this group? |
|
|
|
|
* @param int $user_id the id of the user |
|
|
|
|
* @param int $group_id the iid of the group |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @return boolean true/false |
|
|
|
|
* @todo use the function user_has_access that includes this function |
|
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
|
*/ |
|
|
|
|
public static function is_tutor_of_group($user_id, $group_id) |
|
|
|
|
public static function is_tutor_of_group($user_id, $groupInfo) |
|
|
|
|
{ |
|
|
|
|
if (empty($groupInfo)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
$table_group_tutor = Database::get_course_table(TABLE_GROUP_TUTOR); |
|
|
|
|
$user_id = intval($user_id); |
|
|
|
|
$group_id = intval($group_id); |
|
|
|
|
$group_id = intval($groupInfo['id']); |
|
|
|
|
|
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM $table_group_tutor |
|
|
|
|
@ -1769,14 +1792,14 @@ class GroupManager |
|
|
|
|
* 1. a member of the group OR |
|
|
|
|
* 2. a tutor of the group. This function combines both |
|
|
|
|
* @param int $user_id the id of the user |
|
|
|
|
* @param int $group_id the iid of the group |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @return boolean true/false |
|
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
|
*/ |
|
|
|
|
public static function is_user_in_group($user_id, $group_id) |
|
|
|
|
public static function is_user_in_group($user_id, $groupInfo) |
|
|
|
|
{ |
|
|
|
|
$member = self::is_subscribed($user_id, $group_id); |
|
|
|
|
$tutor = self::is_tutor_of_group($user_id, $group_id); |
|
|
|
|
$member = self::is_subscribed($user_id, $groupInfo); |
|
|
|
|
$tutor = self::is_tutor_of_group($user_id, $groupInfo); |
|
|
|
|
if ($member || $tutor) { |
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
|
@ -1946,7 +1969,7 @@ class GroupManager |
|
|
|
|
return true; |
|
|
|
|
break; |
|
|
|
|
case self::TOOL_PRIVATE: |
|
|
|
|
$userIsInGroup = self::is_user_in_group($user_id, $groupInfo['iid']); |
|
|
|
|
$userIsInGroup = self::is_user_in_group($user_id, $groupInfo); |
|
|
|
|
if ($userIsInGroup) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
@ -1978,7 +2001,7 @@ class GroupManager |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$groupId = $groupInfo['iid']; |
|
|
|
|
$tutors = self::get_subscribed_tutors($groupId, true); |
|
|
|
|
$tutors = self::get_subscribed_tutors($groupInfo, true); |
|
|
|
|
|
|
|
|
|
if (in_array($userId, $tutors)) { |
|
|
|
|
return true; |
|
|
|
|
@ -2072,19 +2095,23 @@ class GroupManager |
|
|
|
|
* Fill the groups with students. |
|
|
|
|
* |
|
|
|
|
* note : optimize fill_groups_list <--> fill_groups |
|
|
|
|
* @param int $groupId (group iid) |
|
|
|
|
* @param array $groupInfo |
|
|
|
|
* @return array|bool |
|
|
|
|
*/ |
|
|
|
|
public static function fill_groups_list($groupId) |
|
|
|
|
public static function fill_groups_list($groupInfo) |
|
|
|
|
{ |
|
|
|
|
$groupId = (int) $groupId; |
|
|
|
|
$_course = api_get_course_info(); |
|
|
|
|
if (empty($groupInfo)) { |
|
|
|
|
return []; |
|
|
|
|
} |
|
|
|
|
$groupIid = (int) $groupInfo['iid']; |
|
|
|
|
$groupId = (int) $groupInfo['id']; |
|
|
|
|
|
|
|
|
|
$_course = api_get_course_info(); |
|
|
|
|
if (empty($_course) || empty($groupId)) { |
|
|
|
|
return []; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$category = self::get_category_from_group($groupId); |
|
|
|
|
$category = self::get_category_from_group($groupIid); |
|
|
|
|
$number_groups_per_user = self::GROUP_PER_MEMBER_NO_LIMIT; |
|
|
|
|
$categoryId = 0; |
|
|
|
|
if ($category) { |
|
|
|
|
@ -2107,7 +2134,7 @@ class GroupManager |
|
|
|
|
for ($i = 0; $i < count($complete_user_list); $i ++) { |
|
|
|
|
// find # of groups the user is enrolled in |
|
|
|
|
$number_of_groups = self:: user_in_number_of_groups( |
|
|
|
|
$complete_user_list[$i]["user_id"], |
|
|
|
|
$complete_user_list[$i]['user_id'], |
|
|
|
|
$categoryId |
|
|
|
|
); |
|
|
|
|
// add # of groups to user list |
|
|
|
|
@ -2145,8 +2172,8 @@ class GroupManager |
|
|
|
|
$session_img = api_get_session_image($this_group['session_id'], $user_info['status']); |
|
|
|
|
|
|
|
|
|
// All the tutors of this group |
|
|
|
|
$tutorsids_of_group = self::get_subscribed_tutors($this_group['iid'], true); |
|
|
|
|
$isMember = self::is_subscribed($user_id, $this_group['iid']); |
|
|
|
|
$tutorsids_of_group = self::get_subscribed_tutors($this_group, true); |
|
|
|
|
$isMember = self::is_subscribed($user_id, $this_group); |
|
|
|
|
|
|
|
|
|
// Create a new table-row |
|
|
|
|
$row = array(); |
|
|
|
|
@ -2225,9 +2252,9 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
// Self-registration / unregistration |
|
|
|
|
if (!api_is_allowed_to_edit(false, true)) { |
|
|
|
|
if (self::is_self_registration_allowed($user_id, $this_group['iid'])) { |
|
|
|
|
if (self::is_self_registration_allowed($user_id, $this_group)) { |
|
|
|
|
$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['iid'])) { |
|
|
|
|
} elseif (self::is_self_unregistration_allowed($user_id, $this_group)) { |
|
|
|
|
$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 { |
|
|
|
|
$row[] = '-'; |
|
|
|
|
@ -2426,6 +2453,7 @@ class GroupManager |
|
|
|
|
$data['group_id'] = $groupId; |
|
|
|
|
$result['added']['group'][] = $data; |
|
|
|
|
} |
|
|
|
|
$groupInfo = self::get_group_properties($groupId, true); |
|
|
|
|
} else { |
|
|
|
|
// Update |
|
|
|
|
$groupId = $groupInfo['id']; |
|
|
|
|
@ -2448,8 +2476,11 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
$data['group_id'] = $groupId; |
|
|
|
|
$result['updated']['group'][] = $data; |
|
|
|
|
$groupInfo = self::get_group_properties($groupId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$students = isset($data['students']) ? explode(',', $data['students']) : []; |
|
|
|
|
if (!empty($students)) { |
|
|
|
|
$studentUserIdList = array(); |
|
|
|
|
@ -2457,7 +2488,7 @@ class GroupManager |
|
|
|
|
$userInfo = api_get_user_info_from_username($student); |
|
|
|
|
$studentUserIdList[] = $userInfo['user_id']; |
|
|
|
|
} |
|
|
|
|
self::subscribe_users($studentUserIdList, $groupId); |
|
|
|
|
self::subscribe_users($studentUserIdList, $groupInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$tutors = isset($data['tutors']) ? explode(',', $data['tutors']) : []; |
|
|
|
|
@ -2467,7 +2498,7 @@ class GroupManager |
|
|
|
|
$userInfo = api_get_user_info_from_username($tutor); |
|
|
|
|
$tutorIdList[] = $userInfo['user_id']; |
|
|
|
|
} |
|
|
|
|
self::subscribe_tutors($tutorIdList, $groupId); |
|
|
|
|
self::subscribe_tutors($tutorIdList, $groupInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$elementsFound['groups'][] = $groupId; |
|
|
|
|
@ -2488,7 +2519,7 @@ class GroupManager |
|
|
|
|
$groups = self::get_groups(); |
|
|
|
|
foreach ($groups as $group) { |
|
|
|
|
if (!in_array($group['iid'], $elementsFound['groups'])) { |
|
|
|
|
self::delete_groups($group['iid']); |
|
|
|
|
self::delete_groups($group); |
|
|
|
|
$group['group'] = $group['name']; |
|
|
|
|
$result['deleted']['group'][] = $group; |
|
|
|
|
} |
|
|
|
|
@ -2573,7 +2604,7 @@ class GroupManager |
|
|
|
|
$userList[] = $user['username']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$tutors = self::getTutors($groupInfo['iid']); |
|
|
|
|
$tutors = self::getTutors($groupInfo); |
|
|
|
|
$tutorList = array(); |
|
|
|
|
foreach ($tutors as $user) { |
|
|
|
|
$user = api_get_user_info($user['user_id']); |
|
|
|
|
@ -2696,7 +2727,7 @@ class GroupManager |
|
|
|
|
foreach ($groups as $group) { |
|
|
|
|
$content .= '<li>'; |
|
|
|
|
$content .= Display::tag('h3', Security::remove_XSS($group['name'])); |
|
|
|
|
$users = self::getTutors($group['iid']); |
|
|
|
|
$users = self::getTutors($group); |
|
|
|
|
if (!empty($users)) { |
|
|
|
|
$content .= '<ul>'; |
|
|
|
|
$content .= "<li>".Display::tag('h4', get_lang('Tutors'))."</li><ul>"; |
|
|
|
|
|