From ad5c2f54b80f5e828af81c120895dd2cc222c1b7 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 10 Jul 2018 08:42:35 +0200 Subject: [PATCH] Can get the list of groups of a user --- RestControllers/GroupsController.php | 20 ++++++++++++++++++++ classes/components/GroupsComponent.php | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/RestControllers/GroupsController.php b/RestControllers/GroupsController.php index beb3ff7..4bec5e4 100644 --- a/RestControllers/GroupsController.php +++ b/RestControllers/GroupsController.php @@ -505,6 +505,26 @@ class GroupsController { return array("success" => "Membership invitation has been cancelled !"); } + /** + * Get the list of membership of the current user + * + * @url POST groups/get_my_list + */ + public function getMyList() : array { + + user_login_required(); + + //Get the list of groups of the user + $list = components()->groups->getListUser(userID); + + //Parse list + foreach($list as $num => $info) + $list[$num] = self::GroupInfoToAPI($info); + + return $list; + + } + /** * Parse a GroupInfo object into an array for the API * diff --git a/classes/components/GroupsComponent.php b/classes/components/GroupsComponent.php index f98afdb..0cc1b90 100644 --- a/classes/components/GroupsComponent.php +++ b/classes/components/GroupsComponent.php @@ -67,6 +67,30 @@ class GroupsComponent { } + /** + * Get the list of groups of a user + * + * @param int $userID The ID of the target user + * @return array The list of groups of the user + */ + public function getListUser(int $userID) : array { + + //First, get IDs of the groups the user belongs to + $groups = db()->select( + self::GROUPS_MEMBERS_TABLE, + "WHERE user_id = ?", + array($userID), + array("groups_id") + ); + + //Parse results + $info = array(); + foreach($groups as $group) + $info[] = $this->get_info($group["groups_id"]); + + return $info; + } + /** * Get the visibility level of a group *