Fixing group bugs when deleting a user from the platform

skala
Julio Montoya 14 years ago
parent aa7608fbf9
commit 0f09c6842d
  1. 6
      main/admin/add_users_to_group.php
  2. 77
      main/inc/lib/group_portal_manager.lib.php
  3. 30
      main/inc/lib/usermanager.lib.php
  4. 11
      main/social/groups.php
  5. 55
      main/social/home.php

@ -243,9 +243,9 @@ if ($_POST['form_sent']) {
if ($form_sent == 1) {
if ($relation_type == GROUP_USER_PERMISSION_PENDING_INVITATION) {
$relations = array(GROUP_USER_PERMISSION_PENDING_INVITATION,GROUP_USER_PERMISSION_READER);
$users_by_group = GroupPortalManager::get_users_by_group($group_id,null,$relations);
$user_id_relation = array_keys($users_by_group);
$user_relation_diff = array_diff($user_id_relation,$UserList);
$users_by_group = GroupPortalManager::get_users_by_group($group_id,null,$relations);
$user_id_relation = array_keys($users_by_group);
$user_relation_diff = array_diff($user_id_relation,$UserList);
foreach ($user_relation_diff as $user_id) {
GroupPortalManager::delete_user_rel_group($user_id,$group_id);
}

@ -187,8 +187,7 @@ class GroupPortalManager
* @return array Database::store_result of the result
* @author Julio Montoya
* */
public static function get_groups_by_user($user_id='', $relation_type = GROUP_USER_PERMISSION_READER, $with_image = false)
{
public static function get_groups_by_user($user_id = '', $relation_type = GROUP_USER_PERMISSION_READER, $with_image = false) {
$where = '';
$table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
$tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
@ -210,12 +209,12 @@ class GroupPortalManager
$array = array();
if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result, 'ASSOC')) {
if ($with_image) {
$picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
$img = '<img src="'.$picture['file'].'" />';
$row['picture_uri'] = $img;
}
$array[$row['id']] = $row;
if ($with_image) {
$picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
$img = '<img src="'.$picture['file'].'" />';
$row['picture_uri'] = $img;
}
$array[$row['id']] = $row;
}
}
return $array;
@ -227,8 +226,7 @@ class GroupPortalManager
* @return array with group content
* @author Julio Montoya
* */
public static function get_groups_by_popularity($num = 6, $with_image = true)
{
public static function get_groups_by_popularity($num = 6, $with_image = true) {
$where = '';
$table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
$tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
@ -239,10 +237,10 @@ class GroupPortalManager
}
// only show admins and readers
$where_relation_condition = " WHERE gu.relation_type IN ('".GROUP_USER_PERMISSION_ADMIN."' , '".GROUP_USER_PERMISSION_READER."') ";
$sql = "SELECT count(user_id) as count, g.picture_uri, g.name, g.description, g.id
$sql = "SELECT DISTINCT count(user_id) as count, g.picture_uri, g.name, g.description, g.id
FROM $tbl_group g
INNER JOIN $table_group_rel_user gu
ON gu.group_id = g.id $where_relation_condition GROUP BY g.id ORDER BY count DESC LIMIT $num";
ON gu.group_id = g.id $where_relation_condition ORDER BY count DESC LIMIT $num";
$result=Database::query($sql);
$array = array();
@ -263,8 +261,7 @@ class GroupPortalManager
* @return array with group content
* @author Julio Montoya
* */
public static function get_groups_by_age($num = 6, $with_image = true)
{
public static function get_groups_by_age($num = 6, $with_image = true) {
$where = '';
$table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
$tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
@ -273,11 +270,13 @@ class GroupPortalManager
$num = 6;
} else {
$num = intval($num);
}
$sql = "SELECT g.picture_uri, g.name, g.description, g.id
}
$where_relation_condition = " WHERE gu.relation_type IN ('".GROUP_USER_PERMISSION_ADMIN."' , '".GROUP_USER_PERMISSION_READER."') ";
$sql = "SELECT DISTINCT count(user_id) as count, g.picture_uri, g.name, g.description, g.id
FROM $tbl_group g
ORDER BY created_on desc LIMIT $num ";
INNER JOIN $table_group_rel_user gu
ON gu.group_id = g.id $where_relation_condition ORDER BY created_on desc LIMIT $num ";
$result=Database::query($sql);
$array = array();
while ($row = Database::fetch_array($result, 'ASSOC')) {
@ -301,25 +300,22 @@ class GroupPortalManager
* @param array image configuration, i.e array('height'=>'20px', 'size'=> '20px')
* @return array list of users in a group
*/
public static function get_users_by_group($group_id, $with_image = false, $relation_type = array(), $from = 0, $limit = 15, $image_conf = array('size'=>USER_IMAGE_SIZE_MEDIUM,'height'=>80))
{
public static function get_users_by_group($group_id, $with_image = false, $relation_type = array(), $from = null, $limit = null, $image_conf = array('size'=>USER_IMAGE_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);
$from = intval($from);
$limit = intval($limit);
if (empty($group_id)){
return array();
}
if (empty($limit)) {
$limit = 15;
}
if (empty($from)) {
$from = 0;
}
}
$limit_text = '';
if ($empty != '' && $limit != '') {
$from = intval($from);
$limit = intval($limit);
$limit_text = "LIMIT $from, $limit";
}
if (count($relation_type) == 0) {
$where_relation_condition = '';
@ -334,16 +330,18 @@ class GroupPortalManager
$where_relation_condition = "AND gu.relation_type IN ($relation_type) ";
}
$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 $from, $limit";
$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_text";
$result=Database::query($sql);
$array = array();
$result = Database::query($sql);
$array = array();
while ($row = Database::fetch_array($result, 'ASSOC')) {
if ($with_image) {
$image_path = UserManager::get_user_picture_path_by_id($row['user_id'], 'web', false, true);
$picture = UserManager::get_picture_user($row['user_id'], $image_path['file'],$image_conf['height'],$image_conf['size']);
$image_path = UserManager::get_user_picture_path_by_id($row['user_id'], 'web', false, true);
$picture = UserManager::get_picture_user($row['user_id'], $image_path['file'], $image_conf['height'], $image_conf['size']);
$row['image'] = '<img src="'.$picture['file'].'" '.$picture['style'].' />';
}
$array[$row['user_id']] = $row;
@ -482,8 +480,7 @@ class GroupPortalManager
* @param int url id
* @return boolean true if success
* */
public static function delete_user_rel_group($user_id, $group_id)
{
public static function delete_user_rel_group($user_id, $group_id) {
$table = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
$sql= "DELETE FROM $table WHERE user_id = ".intval($user_id)." AND group_id=".intval($group_id)." ";
$result = Database::query($sql);

@ -207,13 +207,13 @@ class UserManager
if (!self::can_delete_user($user_id)) {
return false;
}
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$table_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
$table_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
$table_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$table_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
$table_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
$table_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
// Unsubscribe the user from all groups in all his courses
$sql = "SELECT * FROM $table_course c, $table_course_user cu WHERE cu.user_id = '".$user_id."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." AND c.code = cu.course_code";
@ -289,11 +289,19 @@ class UserManager
}
if (api_get_setting('allow_social_tool')=='true' ) {
require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
//Delete user from portal groups
$group_list = GroupPortalManager::get_groups_by_user($user_id);
if (!empty($group_list)) {
foreach($group_list as $group_id => $data) {
GroupPortalManager::delete_user_rel_group($user_id, $group_id);
}
}
require_once api_get_path(LIBRARY_PATH).'social.lib.php';
//@todo Delete user from groups
//Delete from user friend lists
SocialManager::remove_user_rel_user($user_id,true);
//Delete user from friend lists
SocialManager::remove_user_rel_user($user_id, true);
}
// add event to system log
$time = time();

@ -284,16 +284,13 @@ if ($group_id != 0 ) {
}
$members = GroupPortalManager::get_users_by_group($group_id);
$member_content = '';
//Members
if (count($members) > 0) {
$min_count_members = 4;
$i = 1;
if ($my_group_role == GROUP_USER_PERMISSION_ADMIN) {
$member_content .= Display::url(Display::return_icon('edit.gif', get_lang('EditMembersList')).' '.get_lang('EditMembersList'), 'group_members.php?id='.$group_id);
}
foreach($members as $member) {
if ($i > $min_count_members) break;
}
foreach($members as $member) {
// if is a member
if (in_array($member['relation_type'] , array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER,GROUP_USER_PERMISSION_MODERATOR))) {
//add icons
@ -311,7 +308,7 @@ if ($group_id != 0 ) {
$member_name = Display::url(api_get_person_name(cut($member['firstname'],15),cut($member['lastname'],15)).'&nbsp;'.$icon, 'profile.php?u='.$member['user_id']);
$member_content .= Display::div('<img height="44" border="2" align="middle" vspace="10" class="social-groups-image" src="'.$picture['file'].'"/>&nbsp'.$member_name);
$member_content .= '</div>';
$i++;
}
}
}

@ -86,7 +86,6 @@ echo '<div id="social-content">';
echo '<div><p><strong>'.get_lang('Name').'</strong><br /><span class="social-groups-text4">'.api_get_person_name($user_info['firstname'], $user_info['lastname']).'</span></p></div>
<div><p><strong>'.get_lang('Email').'</strong><br /><span class="social-groups-text4">'.($user_info['email']?$user_info['email']:'').'</span></p></div>
<div class="box_description_group_actions" ><a href="'.api_get_path(WEB_PATH).'main/auth/profile.php">'.Display::return_icon('profile_edit.png', get_lang('EditProfile'), array('hspace'=>'6')).get_lang('EditProfile').$url_close.'</a></div>';
echo '</div>';
/*
echo '<div class="rounded_div" style="width:280px">';
@ -98,57 +97,55 @@ echo '<div id="social-content">';
}
echo '</div>';*/
//Search box
echo '<div class="social-box-right">';
echo '<br />';
echo UserManager::get_search_form($query);
echo '<br />';
//Group box by age
$results = GroupPortalManager::get_groups_by_age(1,false);
$groups_newest = array();
foreach ($results as $result) {
$id = $result['id'];
$url_open = '<a href="groups.php?id='.$id.'">';
$url_close = '</a>';
$count_users_group = count(GroupPortalManager::get_users_by_group($id, false, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER)));
if ($count_users_group == 1 ) {
$count_users_group = $count_users_group.' '.get_lang('Member');
} else {
$count_users_group = $count_users_group.' '.get_lang('Members');
}
$result['name'] = $url_open.api_ucwords(cut($result['name'],40,true)).$url_close.Display::span('<br />'.$count_users_group,array('class'=>'box_description_group_member'));
$picture = GroupPortalManager::get_picture_group($id, $result['picture_uri'],80);
$result['picture_uri'] = '<img class="social-groups-image" src="'.$picture['file'].'" hspace="10" height="44" border="2" align="left" width="44" />';
$actions = '<div class="box_description_group_actions" ><a href="groups.php?#tab_browse-2">'.get_lang('SeeMore').$url_close.'</div>';
$groups_newest[]= array($url_open.$result['picture_uri'].$url_close, $result['name'], cut($result['description'],120,true).$actions);
if (!empty($results)) {
foreach ($results as $result) {
$id = $result['id'];
if ($result['count'] == 1 ) {
$result['count'] = '1 '.get_lang('Member');
} else {
$result['count'] = $result['count'].' '.get_lang('Members');
}
$group_url = "groups.php?id=$id";
$result['name'] = Display::url(api_ucwords(cut($result['name'],40,true)), $group_url).Display::span('<br />'.$result['count'],array('class'=>'box_description_group_member'));
$picture = GroupPortalManager::get_picture_group($id, $result['picture_uri'],80);
$result['picture_uri'] = '<img class="social-groups-image" src="'.$picture['file'].'" hspace="10" height="44" border="2" align="left" width="44" />';
$actions = '<div class="box_description_group_actions"><a href="groups.php?#tab_browse-2">'.get_lang('SeeMore').'</a></div>';
$groups_newest[]= array(Display::url($result['picture_uri'], $group_url), $result['name'], cut($result['description'],120,true).$actions);
}
}
$results = GroupPortalManager::get_groups_by_popularity(1,false);
$groups_pop = array();
foreach ($results as $result) {
$id = $result['id'];
$url_open = '<a href="groups.php?id='.$id.'">';
$url_close = '</a>';
$group_url = "groups.php?id=$id";
if ($result['count'] == 1 ) {
$result['count'] = $result['count'].' '.get_lang('Member');
$result['count'] = '1 '.get_lang('Member');
} else {
$result['count'] = $result['count'].' '.get_lang('Members');
}
$result['name'] = $url_open.api_ucwords(cut($result['name'],40,true)).$url_close.Display::span('<br />'.$result['count'],array('class'=>'box_description_group_member'));
$result['name'] = Display::url(api_ucwords(cut($result['name'],40,true)), $group_url).Display::span('<br />'.$result['count'],array('class'=>'box_description_group_member'));
$picture = GroupPortalManager::get_picture_group($id, $result['picture_uri'],80);
$result['picture_uri'] = '<img class="social-groups-image" src="'.$picture['file'].'" hspace="10" height="44" border="2" align="left" width="44" />';
$actions = '<div class="box_description_group_actions" ><a href="groups.php?#tab_browse-3">'.get_lang('SeeMore').$url_close.'</div>';
$groups_pop[]= array($url_open.$result['picture_uri'].$url_close, $result['name'], cut($result['description'],120,true).$actions);
$actions = '<div class="box_description_group_actions" ><a href="groups.php?#tab_browse-3">'.get_lang('SeeMore').'</a></div>';
$groups_pop[]= array(Display::url($result['picture_uri'], $group_url) , $result['name'], cut($result['description'],120,true).$actions);
}
if (count($groups_newest) > 0) {
echo '<div class="social-groups-home-title">'.get_lang('Newest').'</div>';
Display::display_sortable_grid('home_group', array(), $groups_newest, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false));
echo '<br />';
Display::display_sortable_grid('home_group', array(), $groups_newest, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false));
}
if (count($groups_pop) > 0) {

Loading…
Cancel
Save