Can get the list of members of a group

This commit is contained in:
Pierre HUBERT 2018-07-07 08:08:05 +02:00
parent 7a4dd8ea9f
commit 65ab64c22c
2 changed files with 90 additions and 0 deletions

View File

@ -233,6 +233,28 @@ class GroupsController {
); );
} }
/**
* Get the entire list of the members of a group
*
* @url POST /groups/get_members
*/
public function getMembers(){
user_login_required();
//Get the ID of the group (with admin access)
$groupID = getPostGroupIdWithAccess("id", GroupInfo::MODERATOR_ACCESS);
//Get the list of members of the group
$members = components()->groups->getListMembers($groupID);
//Parse the list of members
foreach($members as $num => $member)
$members[$num] = self::GroupMemberToAPI($member);
return $members;
}
/** /**
* Respond to a membership invitation * Respond to a membership invitation
* *
@ -366,4 +388,21 @@ class GroupsController {
return $data; return $data;
} }
/**
* Turn GroupMember oject into an API array
*
* @param GroupMember $member The member entry to convert
* @return array Generated entry
*/
public static function GroupMemberToAPI(GroupMember $member) : array {
$data = array();
$data["user_id"] = $member->get_userID();
$data["group_id"] = $member->get_group_id();
$data["time_create"] = $member->get_time_sent();
$data["level"] = self::GROUPS_MEMBERSHIP_LEVELS[$member->get_level()];
return $data;
}
} }

View File

@ -168,6 +168,24 @@ class GroupsComponent {
} }
/**
* Get the list of members of a group
*
* @param int $groupID The ID of the group to fetch
* @return array The list of members of the group
*/
public function getListMembers(int $groupID) : array {
$members = db()->select(
self::GROUPS_MEMBERS_TABLE,
"WHERE groups_id = ?",
array($groupID)
);
//Process the list of results
return $this->multipleDBToGroupMember($members);
}
/** /**
* Insert a new group member * Insert a new group member
* *
@ -524,6 +542,39 @@ class GroupsComponent {
return $data; return $data;
} }
/**
* Turn multiple database entries into GroupMember entries
*
* @param array $entries The entries to process
* @return array Generated GroupMember objects
*/
private function multipleDBToGroupMember(array $entries) : array {
foreach($entries as $num => $entry)
$entries[$num] = $this->dbToGroupMember($entry);
return $entries;
}
/**
* Turn a database entry into a GroupMember entry
*
* @param array $entry The database entry to convert
* @return GroupMember Generated entry
*/
private function dbToGroupMember(array $entry) : GroupMember {
$member = new GroupMember();
$member->set_id($entry["id"]);
$member->set_group_id($entry["groups_id"]);
$member->set_userID($entry["user_id"]);
$member->set_time_sent($entry["time_create"]);
$member->set_level($entry["level"]);
return $member;
}
} }
//Register component //Register component