|
|
@ -84,16 +84,13 @@ class GroupManager |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function get_group_list($category = null, $course_code = null) |
|
|
|
public static function get_group_list($category = null, $course_code = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$my_user_id = api_get_user_id(); |
|
|
|
|
|
|
|
$course_info = api_get_course_info($course_code); |
|
|
|
$course_info = api_get_course_info($course_code); |
|
|
|
|
|
|
|
$session_id = api_get_session_id(); |
|
|
|
|
|
|
|
|
|
|
|
$course_id = $course_info['real_id']; |
|
|
|
$course_id = $course_info['real_id']; |
|
|
|
$table_group_user = Database :: get_course_table(TABLE_GROUP_USER); |
|
|
|
$table_group_user = Database :: get_course_table(TABLE_GROUP_USER); |
|
|
|
$table_group = Database :: get_course_table(TABLE_GROUP); |
|
|
|
$table_group = Database :: get_course_table(TABLE_GROUP); |
|
|
|
|
|
|
|
|
|
|
|
//condition for the session |
|
|
|
|
|
|
|
$session_id = api_get_session_id(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT g.id, |
|
|
|
$sql = "SELECT g.id, |
|
|
|
g.name, |
|
|
|
g.name, |
|
|
|
g.description, |
|
|
|
g.description, |
|
|
@ -377,7 +374,7 @@ class GroupManager |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* deletes groups and their data. |
|
|
|
* Deletes groups and their data. |
|
|
|
* @author Christophe Gesche <christophe.gesche@claroline.net> |
|
|
|
* @author Christophe Gesche <christophe.gesche@claroline.net> |
|
|
|
* @author Hugues Peeters <hugues.peeters@claroline.net> |
|
|
|
* @author Hugues Peeters <hugues.peeters@claroline.net> |
|
|
|
* @author Bart Mollet |
|
|
|
* @author Bart Mollet |
|
|
@ -413,6 +410,7 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
|
|
// Unsubscribe all users |
|
|
|
// Unsubscribe all users |
|
|
|
self :: unsubscribe_all_users($group_ids); |
|
|
|
self :: unsubscribe_all_users($group_ids); |
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT id, secret_directory, session_id FROM $group_table |
|
|
|
$sql = "SELECT id, secret_directory, session_id FROM $group_table |
|
|
|
WHERE c_id = $course_id AND id IN (".implode(' , ', $group_ids).")"; |
|
|
|
WHERE c_id = $course_id AND id IN (".implode(' , ', $group_ids).")"; |
|
|
|
$db_result = Database::query($sql); |
|
|
|
$db_result = Database::query($sql); |
|
|
@ -1084,6 +1082,8 @@ class GroupManager |
|
|
|
$sql = "SELECT user_id FROM $tutor_user_table |
|
|
|
$sql = "SELECT user_id FROM $tutor_user_table |
|
|
|
WHERE c_id = $course_id AND group_id = $group_id"; |
|
|
|
WHERE c_id = $course_id AND group_id = $group_id"; |
|
|
|
$res = Database::query($sql); |
|
|
|
$res = Database::query($sql); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$users = array(); |
|
|
|
while ($obj = Database::fetch_object($res)) { |
|
|
|
while ($obj = Database::fetch_object($res)) { |
|
|
|
$users[] = api_get_user_info($obj->user_id); |
|
|
|
$users[] = api_get_user_info($obj->user_id); |
|
|
|
} |
|
|
|
} |
|
|
@ -1524,10 +1524,10 @@ class GroupManager |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Subscribe user(s) to a specified group in current course |
|
|
|
* 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 |
|
|
|
* @return bool TRUE if successfull |
|
|
|
* @return bool TRUE if successful |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function subscribe_users($user_ids, $group_id) |
|
|
|
public static function subscribe_users($user_ids, $group_id) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -1567,10 +1567,12 @@ class GroupManager |
|
|
|
foreach ($user_ids as $user_id) { |
|
|
|
foreach ($user_ids as $user_id) { |
|
|
|
$user_id = intval($user_id); |
|
|
|
$user_id = intval($user_id); |
|
|
|
$group_id = intval($group_id); |
|
|
|
$group_id = intval($group_id); |
|
|
|
|
|
|
|
if (self::can_user_subscribe($user_id, $group_id)) { |
|
|
|
$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 . "', '" . $group_id . "')"; |
|
|
|
$result &= Database::query($sql); |
|
|
|
$result &= Database::query($sql); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return $result; |
|
|
|
return $result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2266,7 +2268,6 @@ class GroupManager |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* |
|
|
|
|
|
|
|
* @param array $groupData |
|
|
|
* @param array $groupData |
|
|
|
* @param bool $deleteNotInArray |
|
|
|
* @param bool $deleteNotInArray |
|
|
|
* @return array |
|
|
|
* @return array |
|
|
@ -2404,6 +2405,27 @@ class GroupManager |
|
|
|
$data['group_id'] = $groupId; |
|
|
|
$data['group_id'] = $groupId; |
|
|
|
$result['updated']['group'][] = $data; |
|
|
|
$result['updated']['group'][] = $data; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$students = isset($data['students']) ? explode(',', $data['students']) : null; |
|
|
|
|
|
|
|
if (!empty($students)) { |
|
|
|
|
|
|
|
$studentUserIdList = array(); |
|
|
|
|
|
|
|
foreach ($students as $student) { |
|
|
|
|
|
|
|
$userInfo = api_get_user_info_from_username($student); |
|
|
|
|
|
|
|
$studentUserIdList[] = $userInfo['user_id']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
self::subscribe_users($studentUserIdList, $groupId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$tutors = isset($data['tutors']) ? explode(',', $data['tutors']) : null; |
|
|
|
|
|
|
|
if (!empty($tutors)) { |
|
|
|
|
|
|
|
$tutorIdList = array(); |
|
|
|
|
|
|
|
foreach ($tutors as $tutor) { |
|
|
|
|
|
|
|
$userInfo = api_get_user_info_from_username($tutor); |
|
|
|
|
|
|
|
$tutorIdList[] = $userInfo['user_id']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
self::subscribe_tutors($tutorIdList, $groupId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$elementsFound['groups'][] = $groupId; |
|
|
|
$elementsFound['groups'][] = $groupId; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -2434,9 +2456,11 @@ class GroupManager |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Export all categories/group from a course to an array. |
|
|
|
* Export all categories/group from a course to an array. |
|
|
|
* This function works only in a context of a course. |
|
|
|
* This function works only in a context of a course. |
|
|
|
|
|
|
|
* @param int $groupId |
|
|
|
|
|
|
|
* @param bool $loadUsers |
|
|
|
* @return array |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function exportCategoriesAndGroupsToArray() |
|
|
|
public static function exportCategoriesAndGroupsToArray($groupId = null, $loadUsers = false) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$data = array(); |
|
|
|
$data = array(); |
|
|
|
$data[] = array( |
|
|
|
$data[] = array( |
|
|
@ -2456,10 +2480,18 @@ class GroupManager |
|
|
|
'groups_per_user' |
|
|
|
'groups_per_user' |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$count = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($loadUsers) { |
|
|
|
|
|
|
|
$data[0][] = 'students'; |
|
|
|
|
|
|
|
$data[0][] = 'tutors'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($loadUsers == false) { |
|
|
|
$categories = GroupManager::get_categories(); |
|
|
|
$categories = GroupManager::get_categories(); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($categories as $categoryInfo) { |
|
|
|
foreach ($categories as $categoryInfo) { |
|
|
|
$data[] = array( |
|
|
|
$data[$count] = array( |
|
|
|
$categoryInfo['title'], |
|
|
|
$categoryInfo['title'], |
|
|
|
null, |
|
|
|
null, |
|
|
|
$categoryInfo['description'], |
|
|
|
$categoryInfo['description'], |
|
|
@ -2475,6 +2507,8 @@ class GroupManager |
|
|
|
$categoryInfo['self_unreg_allowed'], |
|
|
|
$categoryInfo['self_unreg_allowed'], |
|
|
|
$categoryInfo['groups_per_user'] |
|
|
|
$categoryInfo['groups_per_user'] |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
$count++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$groups = GroupManager::get_group_list(); |
|
|
|
$groups = GroupManager::get_group_list(); |
|
|
@ -2487,7 +2521,31 @@ class GroupManager |
|
|
|
$categoryTitle = $categoryInfo['title']; |
|
|
|
$categoryTitle = $categoryInfo['title']; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$data[] = array( |
|
|
|
$users = GroupManager::getStudents($groupInfo['id']); |
|
|
|
|
|
|
|
$userList = array(); |
|
|
|
|
|
|
|
foreach ($users as $user) { |
|
|
|
|
|
|
|
$user = api_get_user_info($user['user_id']); |
|
|
|
|
|
|
|
$userList[] = $user['username']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$tutors = GroupManager::getTutors($groupInfo['id']); |
|
|
|
|
|
|
|
$tutorList = array(); |
|
|
|
|
|
|
|
foreach ($tutors as $user) { |
|
|
|
|
|
|
|
$user = api_get_user_info($user['user_id']); |
|
|
|
|
|
|
|
$tutorList[] = $user['username']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$userListToString = null; |
|
|
|
|
|
|
|
if (!empty($userList)) { |
|
|
|
|
|
|
|
$userListToString = implode(',', $userList); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$tutorListToString = null; |
|
|
|
|
|
|
|
if (!empty($tutorList)) { |
|
|
|
|
|
|
|
$tutorListToString = implode(',', $tutorList); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data[$count] = array( |
|
|
|
$categoryTitle, |
|
|
|
$categoryTitle, |
|
|
|
$groupSettings['name'], |
|
|
|
$groupSettings['name'], |
|
|
|
$groupSettings['description'], |
|
|
|
$groupSettings['description'], |
|
|
@ -2501,8 +2559,22 @@ class GroupManager |
|
|
|
$groupSettings['maximum_number_of_students'], |
|
|
|
$groupSettings['maximum_number_of_students'], |
|
|
|
$groupSettings['self_registration_allowed'], |
|
|
|
$groupSettings['self_registration_allowed'], |
|
|
|
$groupSettings['self_unregistration_allowed'], |
|
|
|
$groupSettings['self_unregistration_allowed'], |
|
|
|
|
|
|
|
null |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($loadUsers) { |
|
|
|
|
|
|
|
$data[$count][] = $userListToString; |
|
|
|
|
|
|
|
$data[$count][] = $tutorListToString; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($groupId)) { |
|
|
|
|
|
|
|
if ($groupId == $groupInfo['id']) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$count++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $data; |
|
|
|
return $data; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|