|
|
|
@ -4195,89 +4195,6 @@ class UserManager |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Deletes a contact. |
|
|
|
|
* |
|
|
|
|
* @param bool $friend_id |
|
|
|
|
* @param bool $real_removed true will delete ALL friends relationship |
|
|
|
|
* @param string $with_status_condition |
|
|
|
|
* |
|
|
|
|
* @author isaac flores paz <isaac.flores@dokeos.com> |
|
|
|
|
* @author Julio Montoya <gugli100@gmail.com> Cleaning code |
|
|
|
|
*/ |
|
|
|
|
public static function remove_user_rel_user( |
|
|
|
|
$friend_id, |
|
|
|
|
$real_removed = false, |
|
|
|
|
$with_status_condition = '' |
|
|
|
|
) { |
|
|
|
|
$tbl_my_friend = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
|
|
|
|
$tbl_my_message = Database::get_main_table(TABLE_MESSAGE); |
|
|
|
|
$friend_id = (int) $friend_id; |
|
|
|
|
$user_id = api_get_user_id(); |
|
|
|
|
|
|
|
|
|
if ($real_removed) { |
|
|
|
|
$extra_condition = ''; |
|
|
|
|
if ('' != $with_status_condition) { |
|
|
|
|
$extra_condition = ' AND relation_type = '.intval($with_status_condition); |
|
|
|
|
} |
|
|
|
|
$sql = 'DELETE FROM '.$tbl_my_friend.' |
|
|
|
|
WHERE |
|
|
|
|
relation_type <> '.USER_RELATION_TYPE_RRHH.' AND |
|
|
|
|
friend_user_id='.$friend_id.' '.$extra_condition; |
|
|
|
|
Database::query($sql); |
|
|
|
|
$sql = 'DELETE FROM '.$tbl_my_friend.' |
|
|
|
|
WHERE |
|
|
|
|
relation_type <> '.USER_RELATION_TYPE_RRHH.' AND |
|
|
|
|
user_id='.$friend_id.' '.$extra_condition; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} else { |
|
|
|
|
$sql = 'SELECT COUNT(*) as count FROM '.$tbl_my_friend.' |
|
|
|
|
WHERE |
|
|
|
|
user_id='.$user_id.' AND |
|
|
|
|
relation_type NOT IN('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND |
|
|
|
|
friend_user_id='.$friend_id; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
$row = Database::fetch_array($result, 'ASSOC'); |
|
|
|
|
if (1 == $row['count']) { |
|
|
|
|
//Delete user rel user |
|
|
|
|
$sql_i = 'UPDATE '.$tbl_my_friend.' SET relation_type='.USER_RELATION_TYPE_DELETED.' |
|
|
|
|
WHERE user_id='.$user_id.' AND friend_user_id='.$friend_id; |
|
|
|
|
|
|
|
|
|
$sql_j = 'UPDATE '.$tbl_my_message.' SET msg_status='.MESSAGE_STATUS_INVITATION_DENIED.' |
|
|
|
|
WHERE |
|
|
|
|
user_receiver_id='.$user_id.' AND |
|
|
|
|
user_sender_id='.$friend_id.' AND update_date="0000-00-00 00:00:00" '; |
|
|
|
|
// Delete user |
|
|
|
|
$sql_ij = 'UPDATE '.$tbl_my_friend.' SET relation_type='.USER_RELATION_TYPE_DELETED.' |
|
|
|
|
WHERE user_id='.$friend_id.' AND friend_user_id='.$user_id; |
|
|
|
|
$sql_ji = 'UPDATE '.$tbl_my_message.' SET msg_status='.MESSAGE_STATUS_INVITATION_DENIED.' |
|
|
|
|
WHERE |
|
|
|
|
user_receiver_id='.$friend_id.' AND |
|
|
|
|
user_sender_id='.$user_id.' AND |
|
|
|
|
update_date="0000-00-00 00:00:00" '; |
|
|
|
|
Database::query($sql_i); |
|
|
|
|
Database::query($sql_j); |
|
|
|
|
Database::query($sql_ij); |
|
|
|
|
Database::query($sql_ji); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Delete accepted invitations |
|
|
|
|
$sql = "DELETE FROM $tbl_my_message |
|
|
|
|
WHERE |
|
|
|
|
msg_status = ".MESSAGE_STATUS_INVITATION_ACCEPTED." AND |
|
|
|
|
( |
|
|
|
|
user_receiver_id = $user_id AND |
|
|
|
|
user_sender_id = $friend_id |
|
|
|
|
) OR |
|
|
|
|
( |
|
|
|
|
user_sender_id = $user_id AND |
|
|
|
|
user_receiver_id = $friend_id |
|
|
|
|
) |
|
|
|
|
"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param int $userId |
|
|
|
|
* |
|
|
|
|