|
|
|
@ -77,8 +77,8 @@ class GroupManager |
|
|
|
|
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_id = $course_info['real_id']; |
|
|
|
|
$table_group_user = Database :: get_course_table(TABLE_GROUP_USER); |
|
|
|
|
$table_group = Database :: get_course_table(TABLE_GROUP); |
|
|
|
@ -541,6 +541,7 @@ class GroupManager |
|
|
|
|
* @param int Chat tool's visibility (0=none,1=private,2=public) |
|
|
|
|
* @param bool Whether self registration is allowed or not |
|
|
|
|
* @param bool Whether self unregistration is allowed or not |
|
|
|
|
* @param int $categoryId |
|
|
|
|
* @return bool TRUE if properties are successfully changed, false otherwise |
|
|
|
|
*/ |
|
|
|
|
public static function set_group_properties( |
|
|
|
@ -556,14 +557,14 @@ class GroupManager |
|
|
|
|
$wiki_state, |
|
|
|
|
$chat_state, |
|
|
|
|
$self_registration_allowed, |
|
|
|
|
$self_unregistration_allowed |
|
|
|
|
$self_unregistration_allowed, |
|
|
|
|
$categoryId = null |
|
|
|
|
) { |
|
|
|
|
$table_group = Database :: get_course_table(TABLE_GROUP); |
|
|
|
|
$table_forum = Database :: get_course_table(TABLE_FORUM); |
|
|
|
|
$categoryId = intval($categoryId); |
|
|
|
|
//$forum_id = get_forums_of_group($group_id); |
|
|
|
|
$group_id = Database::escape_string($group_id); |
|
|
|
|
$category = self::get_category_from_group($group_id); |
|
|
|
|
|
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
|
|
|
|
|
$sql = "UPDATE ".$table_group." SET |
|
|
|
@ -578,7 +579,8 @@ class GroupManager |
|
|
|
|
description='".Database::escape_string(trim($description))."', |
|
|
|
|
max_student= '".Database::escape_string($maximum_number_of_students)."', |
|
|
|
|
self_registration_allowed='".Database::escape_string($self_registration_allowed)."', |
|
|
|
|
self_unregistration_allowed='".Database::escape_string($self_unregistration_allowed)."' |
|
|
|
|
self_unregistration_allowed = '".Database::escape_string($self_unregistration_allowed)."', |
|
|
|
|
category_id = '".Database::escape_string($categoryId)."' |
|
|
|
|
WHERE c_id = $course_id AND id=".$group_id; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
//Here we are updating a field in the table forum_forum that perhaps duplicates the table group_info.forum_state cvargas |
|
|
|
@ -764,8 +766,10 @@ class GroupManager |
|
|
|
|
$maximum_number_of_students = 8, |
|
|
|
|
$groups_per_user = 0 |
|
|
|
|
) { |
|
|
|
|
if (empty($title)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
$table_group_category = Database :: get_course_table(TABLE_GROUP_CATEGORY); |
|
|
|
|
|
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
|
|
|
|
|
$sql = "SELECT MAX(display_order)+1 as new_order FROM $table_group_category WHERE c_id = $course_id "; |
|
|
|
@ -874,7 +878,8 @@ class GroupManager |
|
|
|
|
$wiki_state, |
|
|
|
|
$chat_state, |
|
|
|
|
$self_registration_allowed, |
|
|
|
|
$self_unregistration_allowed |
|
|
|
|
$self_unregistration_allowed, |
|
|
|
|
$id |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -927,23 +932,65 @@ class GroupManager |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GROUP USERS FUNCTIONS |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get all users from a given group |
|
|
|
|
* @param int $group_id The group |
|
|
|
|
* @param bool $load_extra_info |
|
|
|
|
* @param int $start |
|
|
|
|
* @param int $limit |
|
|
|
|
* @param bool $getCount |
|
|
|
|
* @param int $courseId |
|
|
|
|
* @return array list of user id |
|
|
|
|
*/ |
|
|
|
|
public static function get_users($group_id, $load_extra_info = false) |
|
|
|
|
{ |
|
|
|
|
public static function get_users( |
|
|
|
|
$group_id, |
|
|
|
|
$load_extra_info = false, |
|
|
|
|
$start = null, |
|
|
|
|
$limit = null, |
|
|
|
|
$getCount = false, |
|
|
|
|
$courseId = null, |
|
|
|
|
$column = null, |
|
|
|
|
$direction = null |
|
|
|
|
) { |
|
|
|
|
$group_user_table = Database :: get_course_table(TABLE_GROUP_USER); |
|
|
|
|
$user_table = Database :: get_main_table(TABLE_MAIN_USER); |
|
|
|
|
|
|
|
|
|
$group_id = Database::escape_string($group_id); |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
$sql = "SELECT user_id FROM $group_user_table WHERE c_id = $course_id AND group_id = $group_id"; |
|
|
|
|
if (empty($courseId)) { |
|
|
|
|
$courseId = api_get_course_int_id(); |
|
|
|
|
} else { |
|
|
|
|
$courseId = intval($courseId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$select = " SELECT g.user_id, firstname, lastname "; |
|
|
|
|
if ($getCount) { |
|
|
|
|
$select = " SELECT count(u.user_id) count"; |
|
|
|
|
} |
|
|
|
|
$sql = "$select |
|
|
|
|
FROM $group_user_table g |
|
|
|
|
INNER JOIN $user_table u |
|
|
|
|
ON (u.user_id = g.user_id) |
|
|
|
|
WHERE c_id = $courseId AND g.group_id = $group_id"; |
|
|
|
|
|
|
|
|
|
if (!empty($column) && !empty($direction)) { |
|
|
|
|
$column = Database::escape_string($column); |
|
|
|
|
$direction = Database::escape_string($direction); |
|
|
|
|
$sql .= " ORDER BY $column $direction"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($start) && !empty($limit)) { |
|
|
|
|
$start = intval($start); |
|
|
|
|
$limit = intval($limit); |
|
|
|
|
$sql .= " LIMIT $start, $limit"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
$users = array (); |
|
|
|
|
while ($obj = Database::fetch_object($res)) { |
|
|
|
|
if ($getCount) { |
|
|
|
|
return $obj->count; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if ($load_extra_info) { |
|
|
|
|
$users[] = api_get_user_info($obj->user_id); |
|
|
|
|
} else { |
|
|
|
@ -1292,10 +1339,14 @@ class GroupManager |
|
|
|
|
$group_id = Database::escape_string($group_id); |
|
|
|
|
$user_id = Database::escape_string($user_id); |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
$sql = 'SELECT 1 FROM '.$table_group_user.' WHERE c_id = '.$course_id.' AND group_id = '.$group_id.' AND user_id = '.$user_id; |
|
|
|
|
$db_result = Database::query($sql); |
|
|
|
|
$sql = 'SELECT 1 FROM '.$table_group_user.' |
|
|
|
|
WHERE |
|
|
|
|
c_id = '.$course_id.' AND |
|
|
|
|
group_id = '.$group_id.' AND |
|
|
|
|
user_id = '.$user_id; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
|
|
|
|
|
return Database::num_rows($db_result) > 0; |
|
|
|
|
return Database::num_rows($result) > 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -1888,21 +1939,19 @@ class GroupManager |
|
|
|
|
$table_group = Database::get_course_table(TABLE_GROUP); |
|
|
|
|
$user_id = intval($user_id); |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
$sql = "SELECT DISTINCT name FROM $table_group g |
|
|
|
|
INNER JOIN $table_group_user gu |
|
|
|
|
ON (gu.group_id = g.id) |
|
|
|
|
INNER JOIN $table_tutor_user tu |
|
|
|
|
ON (tu.group_id = g.id) |
|
|
|
|
$sql = "SELECT DISTINCT name |
|
|
|
|
FROM $table_group g |
|
|
|
|
LEFT JOIN $table_group_user gu |
|
|
|
|
ON (gu.group_id = g.id AND g.c_id = gu.c_id) |
|
|
|
|
LEFT JOIN $table_tutor_user tu |
|
|
|
|
ON (tu.group_id = g.id AND g.c_id = tu.c_id) |
|
|
|
|
WHERE |
|
|
|
|
tu.c_id= $course_id AND |
|
|
|
|
gu.c_id= $course_id AND |
|
|
|
|
g.c_id= $course_id AND |
|
|
|
|
(gu.user_id = $user_id OR tu.user_id = $user_id) "; |
|
|
|
|
|
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
$groups = array(); |
|
|
|
|
while ($group = Database::fetch_array($res)) { |
|
|
|
|
$groups[] .= $group['name']; |
|
|
|
|
$groups[] = $group['name']; |
|
|
|
|
} |
|
|
|
|
return $groups; |
|
|
|
|
} |
|
|
|
@ -2161,12 +2210,17 @@ class GroupManager |
|
|
|
|
|
|
|
|
|
$groupCategories = GroupManager :: get_categories(); |
|
|
|
|
|
|
|
|
|
if (empty($groupCategories)) { |
|
|
|
|
$result['error'][] = get_lang('CreateACategory'); |
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach ($groupData as $data) { |
|
|
|
|
$isCategory = empty($data['group']) ? true : false; |
|
|
|
|
|
|
|
|
|
if ($isCategory) { |
|
|
|
|
$categoryInfo = self::getCategoryByTitle($data['category']); |
|
|
|
|
$categoryId = $categoryInfo['id']; |
|
|
|
|
|
|
|
|
|
if (!empty($categoryInfo)) { |
|
|
|
|
// Update |
|
|
|
|
self::update_category( |
|
|
|
@ -2188,6 +2242,7 @@ class GroupManager |
|
|
|
|
$data['category_id'] = $categoryId; |
|
|
|
|
$result['updated']['category'][] = $data; |
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
// Add |
|
|
|
|
$categoryId = self::create_category( |
|
|
|
|
$data['category'], |
|
|
|
@ -2212,21 +2267,20 @@ class GroupManager |
|
|
|
|
} |
|
|
|
|
$elementsFound['categories'][] = $categoryId; |
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
$groupInfo = self::getGroupByName($data['group']); |
|
|
|
|
|
|
|
|
|
if (empty($groupInfo)) { |
|
|
|
|
$categoryInfo = self::getCategoryByTitle($data['category']); |
|
|
|
|
|
|
|
|
|
$categoryId = null; |
|
|
|
|
if (!empty($categoryInfo)) { |
|
|
|
|
$categoryId = $categoryInfo['id']; |
|
|
|
|
} else { |
|
|
|
|
if (!empty($groupCategories) && isset($groupCategories[0])) { |
|
|
|
|
$defaultGroupCategory = $groupCategories[0]; |
|
|
|
|
$categoryId = $defaultGroupCategory['id']; |
|
|
|
|
} |
|
|
|
|
$categoryInfo = self::getCategoryByTitle($data['category']); |
|
|
|
|
$categoryId = null; |
|
|
|
|
if (!empty($categoryInfo)) { |
|
|
|
|
$categoryId = $categoryInfo['id']; |
|
|
|
|
} else { |
|
|
|
|
if (!empty($groupCategories) && isset($groupCategories[0])) { |
|
|
|
|
$defaultGroupCategory = $groupCategories[0]; |
|
|
|
|
$categoryId = $defaultGroupCategory['id']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (empty($groupInfo)) { |
|
|
|
|
|
|
|
|
|
// Add |
|
|
|
|
$groupId = self::create_group( |
|
|
|
@ -2250,7 +2304,8 @@ class GroupManager |
|
|
|
|
$data['wiki_state'], |
|
|
|
|
$data['chat_state'], |
|
|
|
|
$data['self_reg_allowed'], |
|
|
|
|
$data['self_unreg_allowed'] |
|
|
|
|
$data['self_unreg_allowed'], |
|
|
|
|
$categoryId |
|
|
|
|
); |
|
|
|
|
$data['group_id'] = $groupId; |
|
|
|
|
$result['added']['group'][] = $data; |
|
|
|
@ -2271,7 +2326,8 @@ class GroupManager |
|
|
|
|
$data['wiki_state'], |
|
|
|
|
$data['chat_state'], |
|
|
|
|
$data['self_reg_allowed'], |
|
|
|
|
$data['self_unreg_allowed'] |
|
|
|
|
$data['self_unreg_allowed'], |
|
|
|
|
$categoryId |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$data['group_id'] = $groupId; |
|
|
|
|