Source for file groupmanager.lib.php
Documentation is available at groupmanager.lib.php
==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
==============================================================================
==============================================================================
* This is the group library for Dokeos.
* Include/require it in your code to use its functionality.
* @author various authors
* @author Roan Embrechts (Vrije Universiteit Brussel), virtual courses support + some cleaning
* @author Bart Mollet (HoGent), all functions in class GroupManager
* @package dokeos.library
==============================================================================
require_once ('database.lib.php');
require_once ('course.lib.php');
require_once ('tablesort.lib.php');
require_once ('fileManage.lib.php');
require_once ('fileUpload.lib.php');
* No limit on the number of users in a group
define("MEMBER_PER_GROUP_NO_LIMIT", "0");
* No limit on the number of groups per user
define("GROUP_PER_MEMBER_NO_LIMIT", "0");
* The tools of a group can have 3 states
define("TOOL_NOT_AVAILABLE", "0");
* Constants for the available group tools
//define("GROUP_TOOL_FORUM", "0");
define("GROUP_TOOL_DOCUMENTS", "1");
define("GROUP_TOOL_CALENDAR","2");
define("GROUP_TOOL_ANNOUNCEMENT","3");
define("GROUP_TOOL_WORK","4");
* Fixed id's for group categories
* - VIRTUAL_COURSE_CATEGORY: in this category groups are created based on the
* virtual course of a course
* - DEFAULT_GROUP_CATEGORY: When group categories aren't available (platform-
* setting), all groups are created in this 'dummy'-category
define("VIRTUAL_COURSE_CATEGORY", 1);
define("DEFAULT_GROUP_CATEGORY", 2);
* This library contains some functions for group-management.
* @package dokeos.library
* @todo Add $course_code parameter to all functions. So this GroupManager can
* be used outside a session.
/*==============================================================================
==============================================================================*/
* Get list of groups for current course.
* @param int $category The id of the category from which the groups are
* @param string $course_code Default is current course
* @return array An array with all information about the groups.
if ($course_code != null)
$course_db = $course_info['database'];
g.max_student maximum_number_of_members,
g.self_registration_allowed,
g.self_unregistration_allowed,
COUNT(ug2.id) number_of_members
FROM ". $table_group. " `g`
LEFT JOIN ". $table_group_user. " `ug`
ON `ug`.`group_id` = `g`.`id` AND `ug`.`user_id` = '". $_user['user_id']. "'
LEFT JOIN ". $table_group_user. " `ug2`
ON `ug2`.`group_id` = `g`.`id`";
$sql .= " WHERE `g`.`category_id` = '". $category. "' ";
$sql .= " GROUP BY `g`.`id` ORDER BY UPPER(g.name)";
$sql = "SELECT title FROM $table_course WHERE code = '". $thisGroup['name']. "'";
$thisGroup['name'] = $obj->title;
* @param string $name The name for this group
* @param int $tutor The user-id of the group's tutor
* @param int $places How many people can subscribe to the new group
$currentCourseRepository = $_course['path'];
if (intval($places) == 0) //if the amount of users per group is not filled in, use the setting from the category
$places = $category['max_student'];
$sql = "INSERT INTO ". $table_group. " SET category_id='". $category_id. "', max_student = '". $places. "', doc_state = '". $category['doc_state']. "', calendar_state = '". $category['calendar_state']. "', work_state = '". $category['work_state']. "', announcements_state = '". $category['announcements_state']. "', self_registration_allowed = '". $category['self_reg_allowed']. "', self_unregistration_allowed = '". $category['self_unreg_allowed']. "'";
/*$secret_directory = uniqid("")."_team_".$lastId;
while (is_dir(api_get_path(SYS_COURSE_PATH).$currentCourseRepository."/group/$secret_directory"))
$secret_directory = uniqid("")."_team_".$lastId;
FileManager :: mkdirs(api_get_path(SYS_COURSE_PATH).$currentCourseRepository."/group/".$secret_directory, 0770);
/* Stores the directory path into the group table */
$sql = "UPDATE ". $table_group. " SET name = '". mysql_real_escape_string($name). "', secret_directory = '". $dir_name. "' WHERE id ='". $lastId. "'";
// create a forum if needed
if ($category['forum_state'] > 0)
$values['forum_title'] = get_lang('ForumOfGroup'). ' '. $name;
foreach ($forum_categories as $key=> $value)
$forum_category_id = $key;
$values['forum_category'] = $forum_category_id;
$values['allow_anonymous_group']['allow_anonymous'] = 0;
$values['students_can_edit_group']['students_can_edit'] = 0;
$values['approval_direct_group']['approval_direct'] = 0;
$values['allow_attachments_group']['allow_attachments'] = 1;
$values['allow_new_threads_group']['allow_new_threads'] = 1;
$values['default_view_type_group']['default_view_type']= api_get_setting('default_forum_view');
$values['group_forum'] = $lastId;
if ($category['forum_state'] == '1')
$values['public_private_group_forum_group']['public_private_group_forum']= 'public';
$values['public_private_group_forum_group']['public_private_group_forum']= 'private';
* This function creates new groups based on an existing group. It will
* create the specified number of groups and fill those groups with users
* @param int $group_id The group from which subgroups have to be created.
* @param int $number_of_groups The number of groups that have to be created
for ($group_nr = 1; $group_nr <= $number_of_groups; $group_nr ++ )
foreach ($users as $index => $user_id)
$members[$group_ids[$index % $number_of_groups]]++ ;
foreach ($members as $group_id => $places)
$sql = "UPDATE $table_group SET max_student = $places WHERE id = $group_id";
* Create groups from all virtual courses in the given course.
$course['code'] = $course['sysCode'];
$course['title'] = $course['name'];
$group_courses = $virtual_courses;
$group_courses[] = $course;
foreach ($group_courses as $index => $group_course)
foreach ($users as $index => $user)
if ($user['status'] == 5 && $user['tutor_id'] == 0)
$members[] = $user['user_id'];
* Create a group for every class subscribed to the current course
* @param int $category_id The category in which the groups should be
foreach($classes as $index => $class)
foreach($users as $index_user => $user)
$user_ids[] = $user['user_id'];
$group_ids[] = $group_id;
* deletes groups and their data.
* @author Christophe Gesche <christophe.gesche@claroline.net>
* @author Hugues Peeters <hugues.peeters@claroline.net>
* @param mixed $groupIdList - group(s) to delete. It can be a single id
* (int) or a list of id (array).
* @param string $course_code Default is current course
* @return integer - number of groups deleted.
if ($course_code != null)
$course['path'] = $course['directory'];
$course_db = $course['database'];
// Database table definitions
$group_ids = is_array($group_ids) ? $group_ids : array ($group_ids);
// define repository for deleted element
$perm = (!empty($perm)? $perm: '0770');
$sql = 'SELECT id, secret_directory FROM '. $group_table. ' WHERE id IN ('. implode(' , ', $group_ids). ')';
// move group-documents to garbage
$destination_directory = $group_garbage. $group->secret_directory;
rename($source_directory, $destination_directory);
//$forum_ids[] = $group->forum_id;
$sql = "DELETE FROM ". $group_table. " WHERE id IN ('". implode("' , '", $group_ids). "')";
* @param int $group_id The group from which properties are requested.
* @return array All properties. Array-keys are name, tutor_id, description, maximum_number_of_students, directory
$sql = 'SELECT * FROM '. $table_group. ' WHERE id = '. $group_id;
$result['id'] = $db_object->id;
$result['name'] = $db_object->name;
$result['tutor_id'] = $db_object->tutor_id;
$result['description'] = $db_object->description;
$result['maximum_number_of_students'] = $db_object->max_student;
$result['doc_state'] = $db_object->doc_state;
$result['work_state'] = $db_object->work_state;
$result['calendar_state'] = $db_object->calendar_state;
$result['announcements_state'] = $db_object->announcements_state;
$result['directory'] = $db_object->secret_directory;
$result['self_registration_allowed'] = $db_object->self_registration_allowed;
$result['self_unregistration_allowed'] = $db_object->self_unregistration_allowed;
* Changes the group's properties.
* @param string $description
* @param int $maximum_number_of_students
* @param bool $self_registration_allowed
* @param bool $self_unregistration_allowed
* @return bool TRUE if properties are successfully changed.
function set_group_properties($group_id, $name, $description, $maximum_number_of_students, $doc_state, $work_state, $calendar_state, $announcements_state, $self_registration_allowed, $self_unregistration_allowed)
//$table_forum = Database :: get_course_table(TABLE_FORUM);
$sql = "UPDATE ". $table_group. "
SET name='". trim($name). "',
doc_state = '". $doc_state. "',
work_state = '". $work_state. "',
calendar_state = '". $calendar_state. "',
announcements_state = '". $announcements_state. "',
description='". trim($description). "',
max_student=". $maximum_number_of_students. ",
self_registration_allowed='". $self_registration_allowed. "',
self_unregistration_allowed='". $self_unregistration_allowed. "'
//$sql = "UPDATE ".$table_forum." SET forum_name='".trim($name)."' WHERE forum_id=".$forum_id;
//$result &= api_sql_query($sql,__FILE__,__LINE__);
* Get the total number of groups for the current course.
* @return int The number of groups for the current course.
$res = api_sql_query('SELECT COUNT(id) AS number_of_groups FROM '. $table_group);
return $obj->number_of_groups;
/*==============================================================================
* GROUPCATEGORY FUNCTIONS
==============================================================================*/
* @param string $course_code The cours (default = current course)
if ($course_code != null)
$course_db = $course_info['database'];
$sql = "SELECT * FROM $table_group_cat ORDER BY display_order";
* @param int $id The category id
* @param string $course_code The course (default = current course)
if ($course_code != null)
$course_db = $course_info['database'];
$sql = "SELECT * FROM $table_group_cat WHERE id = $id";
* Get the category of a given group
* @param int $group_id The id of the group
* @param string $course_code The course in which the group is (default =
* @return array The category
if ($course_code != null)
$course_db = $course_info['database'];
$sql = "SELECT gc.* FROM $table_group_cat gc, $table_group g WHERE gc.id = g.category_id AND g.id=$group_id";
* Delete a group category
* @param int $cat_id The id of the category to delete
* @param string $course_code The code in which the category should be
* deleted (default = current course)
if ($course_code != null)
$course_db = $course_info['database'];
$sql = "SELECT id FROM $table_group WHERE category_id='". $cat_id. "'";
$groups_to_delete = array ();
$groups_to_delete[] = $group->id;
$sql = "DELETE FROM $table_group_cat WHERE id='". $cat_id. "'";
* @param string $title The title of the new category
* @param string $description The description of the new category
* @param bool $self_registration_allowed
* @param bool $self_unregistration_allowed
* @param int $max_number_of_students
* @param int $groups_per_user
function create_category($title, $description, $doc_state, $work_state, $calendar_state, $announcements_state, $forum_state, $self_registration_allowed, $self_unregistration_allowed, $maximum_number_of_students, $groups_per_user)
$sql = "SELECT MAX(display_order)+1 as new_order FROM $table_group_category ";
if (!isset ($obj->new_order))
$sql = "INSERT INTO ". $table_group_category. "
display_order = $obj->new_order,
doc_state = '". $doc_state. "',
work_state = '". $work_state. "',
calendar_state = '". $calendar_state. "',
announcements_state = '". $announcements_state. "',
groups_per_user = ". $groups_per_user. ",
self_reg_allowed = '". $self_registration_allowed. "',
self_unreg_allowed = '". $self_unregistration_allowed. "',
max_student = ". $maximum_number_of_students. " ";
$sql = "UPDATE ". $table_group_category. " SET id = ". ($id + 1). " WHERE id = $id";
* @param int $id The id of the category
* @param string $title The title of the new category
* @param string $description The description of the new category
* @param bool $self_registration_allowed
* @param bool $self_unregistration_allowed
* @param int $max_number_of_students
* @param int $groups_per_user
function update_category($id, $title, $description, $doc_state, $work_state, $calendar_state, $announcements_state, $forum_state, $self_registration_allowed, $self_unregistration_allowed, $maximum_number_of_students, $groups_per_user)
$sql = "UPDATE ". $table_group_category. "
doc_state = '". $doc_state. "',
work_state = '". $work_state. "',
calendar_state = '". $calendar_state. "',
announcements_state = '". $announcements_state. "',
groups_per_user = ". $groups_per_user. ",
self_reg_allowed = '". $self_registration_allowed. "',
self_unreg_allowed = '". $self_unregistration_allowed. "',
max_student = ". $maximum_number_of_students. "
* Returns the number of groups of the user with the greatest number of
* subscribtions in the given category
if ($course_code != null)
$course_db = $course_info['database'];
$sql = 'SELECT COUNT(gu.group_id) AS current_max FROM '. $group_user_table. ' gu, '. $group_table. ' g WHERE gu.group_id = g.id ';
if ($category_id != null)
$sql .= ' AND g.category_id = '. $category_id;
$sql .= ' GROUP BY gu.user_id ORDER BY current_max DESC LIMIT 1';
return $obj->current_max;
* Swaps the display-order of two categories
* @param int $id1 The id of the first category
* @param int $id2 The id of the second category
$sql = "SELECT id,display_order FROM $table_group_cat WHERE id IN ($id1,$id2)";
$sql = "UPDATE $table_group_cat SET display_order=$cat2->display_order WHERE id=$cat1->id";
$sql = "UPDATE $table_group_cat SET display_order=$cat1->display_order WHERE id=$cat2->id";
/*==============================================================================
==============================================================================*/
* Get all users from a given group
* @param int $group_id The group
$sql = "SELECT user_id FROM $group_user_table WHERE group_id = $group_id";
$users[] = $obj->user_id;
* Fill the groups with students.
* The algorithm takes care to first fill the groups with the least # of users.
* There was a problem with the "ALL" setting.
* When max # of groups is set to all, the value is sometimes NULL and sometimes ALL
* and in both cased the query does not work as expected.
* Stupid solution (currently implemented: set ALL to a big number (INFINITE) and things are solved :)
* Better solution: that's up to you.
* Throughout Dokeos there is some confusion about "course id" and "course code"
* The code is e.g. TEST101, but sometimes a variable that is called courseID also contains a course code string.
* However, there is also a integer course_id that uniquely identifies the course.
* ywarnier:> Now the course_id has been removed (25/1/2005)
* The databases are als very inconsistent in this.
* @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
$group_ids = is_array($group_ids) ? $group_ids : array ($group_ids);
$groups_per_user = $category['groups_per_user'];
* Retrieve all the groups where enrollment is still allowed
* (reverse) ordered by the number of place available
$sql = "SELECT g.id gid, g.max_student-count(ug.user_id) nbPlaces, g.max_student
LEFT JOIN ". $group_user_table. " ug
ON `g`.`id` = `ug`.`group_id`
WHERE g.id IN (". implode(',', $group_ids). ")
$group_available_place = array ();
$group_available_place[$group['gid']] = $group['nbPlaces'];
* Retrieve course users (reverse) ordered by the number
* of group they are already enrolled
for ($i = 0; $i < count($complete_user_list); $i ++ )
//find # of groups the user is enrolled in
//add # of groups to user list
$complete_user_list[$i]['number_groups_left'] = $number_groups_per_user - $number_of_groups;
//first sort by user_id to filter out duplicates
//now sort by # of group left
$complete_user_list = TableSort :: sort_table($complete_user_list, 'number_groups_left', SORT_DESC);
foreach ($complete_user_list as $this_user)
if ($this_user['number_groups_left'] > 0)
$userToken[$this_user['user_id']] = $this_user['number_groups_left'];
* Retrieve the present state of the users repartion in groups
$sql = "SELECT user_id uid, group_id gid FROM ". $group_user_table;
$groupUser[$member['gid']][] = $member['uid'];
reset($group_available_place);
arsort($group_available_place);
foreach ($group_available_place as $group_id => $place)
foreach ($userToken as $user_id => $places)
$group_available_place[$group_id]-- ;
* Get the number of students in a group.
* @return int Number of students in the given group.
$db_result = api_sql_query('SELECT COUNT(*) AS number_of_students FROM '. $table_group_user. ' WHERE group_id = '. $group_id);
return $db_object->number_of_students;
* Maximum number of students in a group
* @return int Maximum number of students in the given group.
$db_result = api_sql_query('SELECT max_student FROM '. $table_group. ' WHERE id = '. $group_id);
if ($db_object->max_student == 0)
return $db_object->max_student;
* Number of groups of a user
* @return int The number of groups the user is subscribed in.
$sql = 'SELECT COUNT(*) AS number_of_groups FROM '. $table_group_user. ' gu, '. $table_group. ' g WHERE gu.user_id = \''. $user_id. '\' AND g.id = gu.group_id AND g.category_id= \''. $cat_id. '\'';
return $db_object->number_of_groups;
* Is sef-registration allowed?
* @return bool TRUE if self-registration is allowed in the given group.
$sql = 'SELECT self_registration_allowed FROM '. $table_group. ' WHERE id = '. $group_id;
* Is sef-unregistration allowed?
* @return bool TRUE if self-unregistration is allowed in the given group.
$db_result = api_sql_query('SELECT self_unregistration_allowed FROM '. $table_group. ' WHERE id = '. $group_id);
* Is user subscribed in group?
* @return bool TRUE if given user is subscribed in given group
if(empty($user_id) or empty($group_id)){return false;}
$sql = 'SELECT 1 FROM '. $table_group_user. ' WHERE group_id = '. $group_id. ' AND user_id = '. $user_id;
* Can a user subscribe to a specified group in a course
* @return bool TRUE if given user can be subscribed in given group
$course_code = $_course['sysCode'];
$category['groups_per_user'] = INFINITE;
* Can a user unsubscribe to a specified group in a course
* @return bool TRUE if given user can be unsubscribed from given group
* @internal for now, same as GroupManager::is_subscribed($user_id,$group_id)
* Get all subscribed users from a group
* @return array An array with information of all users from the given group.
* (user_id, firstname, lastname, email)
$sql = "SELECT `ug`.`id`, `u`.`user_id`, `u`.`lastname`, `u`.`firstname`, `u`.`email`
FROM ". $table_user. " u, ". $table_group_user. " ug
WHERE `ug`.`group_id`='". $group_id. "'
AND `ug`.`user_id`=`u`.`user_id`
ORDER BY UPPER(`u`.`lastname`), UPPER(`u`.`firstname`)";
$member['user_id'] = $user->user_id;
$member['firstname'] = $user->firstname;
$member['lastname'] = $user->lastname;
$member['email'] = $user->email;
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* Get all subscribed tutors of a group
* @return array An array with information of all users from the given group.
* (user_id, firstname, lastname, email)
$sql = "SELECT `tg`.`id`, `u`.`user_id`, `u`.`lastname`, `u`.`firstname`, `u`.`email`
FROM ". $table_user. " u, ". $table_group_tutor. " tg
WHERE `tg`.`group_id`='". $group_id. "'
AND `tg`.`user_id`=`u`.`user_id`
ORDER BY UPPER(`u`.`lastname`), UPPER(`u`.`firstname`)";
$member['user_id'] = $user->user_id;
$member['firstname'] = $user->firstname;
$member['lastname'] = $user->lastname;
$member['email'] = $user->email;
* Subscribe user(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
* @return bool TRUE if successfull
$user_ids = is_array($user_ids) ? $user_ids : array ($user_ids);
foreach ($user_ids as $index => $user_id)
$sql = "INSERT INTO ". $table_group_user. " (user_id, group_id) VALUES ('". $user_id. "', '". $group_id. "')";
* 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
* @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 successfull
$user_ids = is_array($user_ids) ? $user_ids : array ($user_ids);
foreach ($user_ids as $index => $user_id)
$sql = "INSERT INTO ". $table_group_tutor. " (user_id, group_id) VALUES ('". $user_id. "', '". $group_id. "')";
* 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
* @return bool TRUE if successfull
$user_ids = is_array($user_ids) ? $user_ids : array ($user_ids);
$result &= api_sql_query('DELETE FROM '. $table_group_user. ' WHERE group_id = '. $group_id. ' AND user_id IN ('. implode(',', $user_ids). ')');
* 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
* @return bool TRUE if successfull
$group_ids = is_array($group_ids) ? $group_ids : array ($group_ids);
if( count($group_ids) > 0)
$sql = 'DELETE FROM '. $table_group_user. ' WHERE group_id IN ('. implode(',', $group_ids). ')';
* 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
* @see unsubscribe_all_users. This function is almost an exact copy of that function.
* @return bool TRUE if successfull
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
$group_ids = is_array($group_ids) ? $group_ids : array ($group_ids);
if( count($group_ids) > 0)
$sql = 'DELETE FROM '. $table_group_tutor. ' WHERE group_id IN ('. implode(',', $group_ids). ')';
* Is the user a tutor of this group?
* @param $user_id the id of the user
* @param $group_id the id of the group
* @return boolean true/false
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
$sql = "SELECT * FROM ". $table_group_tutor. " WHERE user_id='". $user_id. "' AND group_id='". $group_id. "'";
* Is the user part of this group? This can be a tutor or a normal member
* you should use this function if the access to a tool or functionality is restricted to the people who are actually in the group
* before you had to check if the user was 1. a member of the group OR 2. a tutor of the group. This function combines both
* @param $user_id the id of the user
* @param $group_id the id of the group
* @return boolean true/false
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* Get all tutors for the current course.
* @return array An array with firstname, lastname and user_id for all
* tutors in the current course.
* @deprecated this function uses the old tutor implementation
$sql = "SELECT user.user_id AS user_id, user.lastname AS lastname, user.firstname AS firstname
FROM ". $user_table. " user, ". $course_user_table. " cu
WHERE cu.user_id=user.user_id
AND cu.course_code='". $_course['sysCode']. "'";
* Is user a tutor in current course
* @return bool TRUE if given user is a tutor in the current course.
* @deprecated this function uses the old tutor implementation
$sql = "SELECT tutor_id FROM ". $course_user_table. "
WHERE `user_id`='". $user_id. "'
AND `course_code`='". $_course['sysCode']. "'". "AND tutor_id=1";
* Get all group's from a given course in which a given user is ubscribed
* @param string $course_db: the database of the course you want to
* retrieve the groups for
* @param integer $user_id: the ID of the user you want to know all its
$sql = "SELECT group_id FROM $tbl_group WHERE user_id = '$user_id'";
// uncommenting causes a bug in Agenda AND announcements because there we check if the return value of this function is an array or not
$groups[]= $myrow['group_id'];
-----------------------------------------------------------
these take virtual/linked courses into account when necessary
-----------------------------------------------------------
* 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
* - 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.
$real_course_code = $_course['sysCode'];
//get list of all virtual courses
//add real course to the list
$user_subscribed_course_list[] = $real_course_info;
if (!is_array($user_subscribed_course_list))
foreach ($user_subscribed_course_list as $this_course)
$this_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"];
$tutor_id = $this_user["tutor_id"];
$full_name = $lastname. ", ". $firstname;
if ($lastname == "" || $firstname == '')
$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["tutor_id"] = $tutor_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;
//sort once, on array field "full_name"
//filter out duplicates, based on field "user_id"
//$complete_user_list = GroupManager :: filter_only_students($complete_user_list);
return $complete_user_list;
* Filter out duplicates in a multidimensional array
* by comparing field $compare_field.
* @param $user_array_in list of users (must be sorted).
* @param string $compare_field, the field to be compared
$total_number = count($user_array_in);
$user_array_out[0] = $user_array_in[0];
for ($count_in = 1; $count_in < $total_number; $count_in ++ )
if ($user_array_in[$count_in][$compare_field] != $user_array_out[$count_out][$compare_field])
$user_array_out[$count_out] = $user_array_in[$count_in];
* Filters from the array $user_array_in the users already in the group $group_id.
foreach ($user_array_in as $this_user)
$user_array_out[] = $this_user;
* Remove all users that are not students and all users who have tutor status
$user_array_out = array ();
foreach ($user_array_in as $this_user)
if ($this_user['status'] == STUDENT && $this_user['tutor_id'] == 0)
$user_array_out[] = $this_user;
* Check if a user has access to a certain group tool
* @param int $user_id The user id
* @param int $group_id The group id
* @param constant $tool The tool to check the access rights. This should be
* one of constants: GROUP_TOOL_DOCUMENTS
* @return bool True if the given user has access to the given tool in the
$state_key = 'doc_state';
$state_key = 'calendar_state';
$state_key = 'announcements_state';
$state_key = 'work_state';
elseif($group['tutor_id'] == $user_id)
* Get all groups where a specific user is subscribed
$sql_groups = 'SELECT name FROM '. $table_group. ' g,'. $table_group_user. ' gu WHERE gu.user_id="'. $user_id. '" AND gu.group_id=g.id';
$groups[] .= $group['name'];
|