private function handleGET_leave($request_data) { global $error_msg; if (PA::$login_uid && !empty($this->shared_data['group_info'])) { $group = $this->shared_data['group_info']; $user = PA::$login_user; $user_type = Group::get_user_type(PA::$login_uid, (int) $request_data['gid']); if (Group::is_admin((int) $request_data['gid'], (int) PA::$login_uid) && $user_type == OWNER) { // admin can leave a group but owner can't $error_msg = __("You can't leave your own group."); } else { if (Group::member_exists((int) $request_data['gid'], (int) PA::$login_uid)) { try { $x = $group->leave((int) PA::$login_uid); } catch (PAException $e) { $error_msg = "Operation failed (" . $e->message . "). Please try again"; } } else { $error_msg = sprintf(__("You are not member of \"%s\"."), stripslashes($group->title)); } } if (@$x) { $error_msg = sprintf(__("You have left \"%s\" successfully."), stripslashes($group->title)); // also delete Family relation require_once 'api/Entity/TypedGroupEntityRelation.php'; TypedGroupEntityRelation::delete_relation(PA::$login_uid, $request_data['gid'], PA::$network_info->network_id); } } }
private function leaveFamily($family, $uid) { $msg = null; $res = false; if (Group::member_exists((int) $family->collection_id, (int) $uid)) { try { $x = $family->leave((int) $uid); $res = true; } catch (PAException $e) { $msg = "Operation failed (" . $e->message . "). Please try again"; $res = false; } } if (@$x) { $msg = sprintf(__("You have left \"%s\" successfully."), stripslashes($family->title)); // also delete Family relation require_once 'api/Entity/TypedGroupEntityRelation.php'; TypedGroupEntityRelation::delete_relation((int) $uid, (int) $family->collection_id, PA::$network_info->network_id); } return array($res, $msg); }