📄 groupmanager.lib.php
字号:
while ($group = mysql_fetch_object($db_result)) { // move group-documents to garbage $source_directory = api_get_path(SYS_COURSE_PATH).$course['path']."/group/".$group->secret_directory; $destination_directory = $group_garbage.$group->secret_directory; if (file_exists($source_directory)) { rename($source_directory, $destination_directory); } //$forum_ids[] = $group->forum_id; } // delete the groups $sql = "DELETE FROM ".$group_table." WHERE id IN ('".implode("' , '", $group_ids)."')"; api_sql_query($sql,__FILE__,__LINE__); return mysql_affected_rows(); } /** * Get group properties * @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 */ function get_group_properties($group_id) { if (empty($group_id) or !is_integer(intval($group_id)) ) { return null; } $table_group = Database :: get_course_table(TABLE_GROUP); $sql = 'SELECT * FROM '.$table_group.' WHERE id = '.$group_id; $db_result = api_sql_query($sql,__FILE__,__LINE__); $db_object = mysql_fetch_object($db_result); $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; return $result; } /** * Set group properties * Changes the group's properties. * @param int $group_id * @param string $name * @param string $description * @param int $tutor_id * @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_group = Database :: get_course_table(TABLE_GROUP); //$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."' WHERE id=".$group_id; $result = api_sql_query($sql,__FILE__,__LINE__); //$sql = "UPDATE ".$table_forum." SET forum_name='".trim($name)."' WHERE forum_id=".$forum_id; //$result &= api_sql_query($sql,__FILE__,__LINE__); return $result; } /** * Get the total number of groups for the current course. * @return int The number of groups for the current course. */ function get_number_of_groups() { $table_group = Database :: get_course_table(TABLE_GROUP); $res = api_sql_query('SELECT COUNT(id) AS number_of_groups FROM '.$table_group); $obj = mysql_fetch_object($res); return $obj->number_of_groups; } /*============================================================================== * GROUPCATEGORY FUNCTIONS ==============================================================================*/ /** * Get all categories * @param string $course_code The cours (default = current course) */ function get_categories($course_code = null) { $course_db = ''; if ($course_code != null) { $course_info = Database :: get_course_info($course_code); $course_db = $course_info['database']; } $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY, $course_db); $sql = "SELECT * FROM $table_group_cat ORDER BY display_order"; $res = api_sql_query($sql,__FILE__,__LINE__); $cats = array (); while ($cat = mysql_fetch_array($res)) { $cats[] = $cat; } return $cats; } /** * Get a group category * @param int $id The category id * @param string $course_code The course (default = current course) */ function get_category($id, $course_code = null) { $course_db = ''; if ($course_code != null) { $course_info = Database :: get_course_info($course_code); $course_db = $course_info['database']; } $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY, $course_db); $sql = "SELECT * FROM $table_group_cat WHERE id = $id"; $res = api_sql_query($sql,__FILE__,__LINE__); return mysql_fetch_array($res); } /** * 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 = * current course) * @return array The category */ function get_category_from_group($group_id, $course_code = null) { $course_db = ''; if ($course_code != null) { $course_info = Database :: get_course_info($course_code); $course_db = $course_info['database']; } $table_group = Database :: get_course_table(TABLE_GROUP, $course_db); $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY, $course_db); $sql = "SELECT gc.* FROM $table_group_cat gc, $table_group g WHERE gc.id = g.category_id AND g.id=$group_id"; $res = api_sql_query($sql,__FILE__,__LINE__); $cat = mysql_fetch_array($res); return $cat; } /** * 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) */ function delete_category($cat_id, $course_code = null) { $course_db = ''; if ($course_code != null) { $course_info = Database :: get_course_info($course_code); $course_db = $course_info['database']; } $table_group = Database :: get_course_table(TABLE_GROUP, $course_db); $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY, $course_db); $sql = "SELECT id FROM $table_group WHERE category_id='".$cat_id."'"; $res = api_sql_query($sql,__FILE__,__LINE__); if (mysql_num_rows($res) > 0) { $groups_to_delete = array (); while ($group = mysql_fetch_object($res)) { $groups_to_delete[] = $group->id; } GroupManager :: delete_groups($groups_to_delete); } $sql = "DELETE FROM $table_group_cat WHERE id='".$cat_id."'"; api_sql_query($sql,__FILE__,__LINE__); } /** * Create group 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 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) { $table_group_category = Database :: get_course_table(TABLE_GROUP_CATEGORY); $sql = "SELECT MAX(display_order)+1 as new_order FROM $table_group_category "; $res = api_sql_query($sql,__FILE__,__LINE__); $obj = mysql_fetch_object($res); if (!isset ($obj->new_order)) { $obj->new_order = 1; } $sql = "INSERT INTO ".$table_group_category." SET title='".mysql_real_escape_string($title)."', display_order = $obj->new_order, description='".mysql_real_escape_string($description)."', doc_state = '".$doc_state."', work_state = '".$work_state."', calendar_state = '".$calendar_state."', announcements_state = '".$announcements_state."', forum_state = '".Database::escape_string($forum_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." "; api_sql_query($sql,__FILE__,__LINE__); $id = mysql_insert_id(); if ($id == VIRTUAL_COURSE_CATEGORY) { $sql = "UPDATE ".$table_group_category." SET id = ". ($id +1)." WHERE id = $id"; api_sql_query($sql,__FILE__,__LINE__); return $id +1; } return $id; } /** * Update group category * @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) { $table_group_category = Database :: get_course_table(TABLE_GROUP_CATEGORY); $sql = "UPDATE ".$table_group_category." SET title='".mysql_real_escape_string($title)."', description='".mysql_real_escape_string($description)."', doc_state = '".$doc_state."', work_state = '".$work_state."', calendar_state = '".$calendar_state."', announcements_state = '".$announcements_state."', forum_state = '".Database::escape_string($forum_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." WHERE id=$id"; api_sql_query($sql,__FILE__,__LINE__); } /** * Returns the number of groups of the user with the greatest number of * subscribtions in the given category */ function get_current_max_groups_per_user($category_id = null, $course_code = null) { $course_db = ''; if ($course_code != null) { $course_info = Database :: get_course_info($course_code); $course_db = $course_info['database']; } $group_table = Database :: get_course_table(TABLE_GROUP, $course_db); $group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_db); $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'; $res = api_sql_query($sql,__FILE__,__LINE__); $obj = mysql_fetch_object($res); 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 */ function swap_category_order($id1, $id2) { $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY); $sql = "SELECT id,display_order FROM $table_group_cat WHERE id IN ($id1,$id2)"; $res = api_sql_query($sql,__FILE__,__LINE__); $cat1 = mysql_fetch_object($res); $cat2 = mysql_fetch_object($res); $sql = "UPDATE $table_group_cat SET display_order=$cat2->display_order WHERE id=$cat1->id"; api_sql_query($sql,__FILE__,__LINE__); $sql = "UPDATE $table_group_cat SET display_order=$cat1->display_order WHERE id=$cat2->id"; api_sql_query($sql,__FILE__,__LINE__); } /*============================================================================== * GROUP USERS FUNCTIONS ==============================================================================*/ /** * Get all users from a given group * @param int $group_id The group */ function get_users($group_id) { $group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_db); $sql = "SELECT user_id FROM $group_user_table WHERE group_id = $group_id"; $res = api_sql_query($sql,__FILE__,__LINE__); $users = array (); while ($obj = mysql_fetch_object($res)) { $users[] = $obj->user_id; } return $users; } /** * Fill the groups with students. * The algorithm takes care to first fill the groups with the least # of users. * Analysis * 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. * * Note * 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 * @return void */ function fill_groups($group_ids) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -