From a8115d5fc4d043b221f337b5d7f9e252a054b851 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 14 Dec 2009 13:43:36 -0500 Subject: [PATCH] User group minor fixes see #190 --- main/css/blue_lagoon/default.css | 2 +- main/inc/lib/group_portal_manager.lib.php | 120 +++++++++++++++------- main/inc/lib/message.lib.php | 44 ++++---- main/inc/lib/social.lib.php | 4 + main/social/group_members.php | 68 ++++++------ main/social/group_waiting_list.php | 28 +++-- main/social/groups.php | 10 +- main/social/invitations.php | 10 +- main/social/profile.php | 10 +- 9 files changed, 171 insertions(+), 125 deletions(-) diff --git a/main/css/blue_lagoon/default.css b/main/css/blue_lagoon/default.css index 2d0d0171b2..dd2c6946e5 100755 --- a/main/css/blue_lagoon/default.css +++ b/main/css/blue_lagoon/default.css @@ -389,7 +389,7 @@ default.css (lĂ­nea 362) width: auto; margin: 24px 6px 0 6px; padding-left: 10px; - border: 1px solid #636363; + border: 1px solid #ccc; background-color: #FFF; } .menusectioncaption { diff --git a/main/inc/lib/group_portal_manager.lib.php b/main/inc/lib/group_portal_manager.lib.php index d35af292b2..69b37bc2bf 100755 --- a/main/inc/lib/group_portal_manager.lib.php +++ b/main/inc/lib/group_portal_manager.lib.php @@ -302,16 +302,28 @@ class GroupPortalManager } /** - * Gets the members of a group + * Gets the group's members */ - public static function get_users_by_group($group_id='', $with_image = false, $relation_type = array(), $limit = 100, $image_conf = array('size'=>'medium_','height'=>80)) + public static function get_users_by_group($group_id, $with_image = false, $relation_type = array(), $from = 0, $limit = 15, $image_conf = array('size'=>'medium_','height'=>80)) { $where = ''; $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP); $tbl_user = Database::get_main_table(TABLE_MAIN_USER); $group_id = intval($group_id); - $limit = intval($limit); + $from = intval($from); + $limit = intval($limit); + if (empty($group_id)){ + return array(); + } + + if (empty($limit)) { + $limit = 15; + } + if (empty($from)) { + $from = 0; + } + if (count($relation_type) == 0) { $where_relation_condition = ''; } else { @@ -326,7 +338,7 @@ class GroupPortalManager $sql="SELECT picture_uri as image, u.user_id, u.firstname, u.lastname, relation_type FROM $tbl_user u INNER JOIN $table_group_rel_user gu - ON (gu.user_id = u.user_id) WHERE gu.group_id= $group_id $where_relation_condition ORDER BY relation_type, firstname LIMIT $limit"; + ON (gu.user_id = u.user_id) WHERE gu.group_id= $group_id $where_relation_condition ORDER BY relation_type, firstname LIMIT $from, $limit"; $result=Database::query($sql,__FILE__,__LINE__); $array = array(); @@ -340,6 +352,32 @@ class GroupPortalManager return $array; } + /** + * Gets all the members of a group no matter the relationship for more specifications use get_users_by_group + * @param int group id + * @return array + */ + public static function get_all_users_by_group($group_id) + { + $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP); + $tbl_user = Database::get_main_table(TABLE_MAIN_USER); + $group_id = intval($group_id); + + if (empty($group_id)){ + return array(); + } + $sql="SELECT u.user_id, u.firstname, u.lastname, relation_type FROM $tbl_user u + INNER JOIN $table_group_rel_user gu + ON (gu.user_id = u.user_id) WHERE gu.group_id= $group_id ORDER BY relation_type, firstname"; + + $result=Database::query($sql,__FILE__,__LINE__); + $array = array(); + while ($row = Database::fetch_array($result, 'ASSOC')) { + $array[$row['user_id']] = $row; + } + return $array; + } + /** Gets the inner join of access_url and the course table @@ -422,9 +460,8 @@ class GroupPortalManager * @author Julio Montoya * @param int user id * @param int group_id - * @return int 0 if there are not relationship otherwise return GROUP_USER_PERMISSION_ADMIN or GROUP_USER_PERMISSION_READER constants - * */ - + * @return int 0 if there are not relationship otherwise returns the user group + * */ public static function get_user_group_role($user_id, $group_id) { $table_group_rel_user= Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP); @@ -974,8 +1011,12 @@ class GroupPortalManager return self::update_group_picture($group_id); } - public static function is_group_admin($group_id) { - $user_role = GroupPortalManager::get_user_group_role(api_get_user_id(), $group_id); + + public static function is_group_admin($group_id, $user_id = 0) { + if (empty($user_id)) { + $user_id = api_get_user_id(); + } + $user_role = GroupPortalManager::get_user_group_role($user_id, $group_id); if (in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN))) { return true; } else { @@ -983,8 +1024,11 @@ class GroupPortalManager } } - public static function is_group_moderator($group_id) { - $user_role = GroupPortalManager::get_user_group_role(api_get_user_id(), $group_id); + public static function is_group_moderator($group_id, $user_id = 0) { + if (empty($user_id)) { + $user_id = api_get_user_id(); + } + $user_role = GroupPortalManager::get_user_group_role($user_id, $group_id); if (in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR))) { return true; } else { @@ -992,8 +1036,11 @@ class GroupPortalManager } } - public static function is_group_member($group_id) { - $user_role = GroupPortalManager::get_user_group_role(api_get_user_id(), $group_id); + public static function is_group_member($group_id, $user_id = 0) { + if (empty($user_id)) { + $user_id = api_get_user_id(); + } + $user_role = GroupPortalManager::get_user_group_role($user_id, $group_id); if (in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR, GROUP_USER_PERMISSION_READER))) { return true; } else { @@ -1013,22 +1060,11 @@ class GroupPortalManager $big_image = GroupPortalManager::get_picture_group($group_id, $group_info['picture_uri'],'','big_'); $tags = GroupPortalManager::get_group_tags($group_id, true); - $users = GroupPortalManager::get_users_by_group($group_id, true); + $members = GroupPortalManager::get_users_by_group($group_id, true); //my relation with the group is set here - - if (is_array($users[api_get_user_id()]) && count($users[api_get_user_id()]) > 0) { - //im a member - if ($users[api_get_user_id()]['relation_type'] != '' ) { - $my_group_role = $users[api_get_user_id()]['relation_type']; - } else { - $my_group_role = GROUP_USER_PERMISSION_ANONYMOUS; - } - } else { - //im not a member - $my_group_role = GROUP_USER_PERMISSION_ANONYMOUS; - } + $my_group_role = self::get_user_group_role($user_id, $group_id); //@todo this must be move to default.css for dev use only echo '