From 60652f3c81a580e56e7862a7952bfaad4c839835 Mon Sep 17 00:00:00 2001 From: Roland Gaida Date: Tue, 13 Oct 2015 10:36:15 +0200 Subject: [PATCH] Adds a function to lookup a member's id within a group --- README.md | 1 + src/Client.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 298258f..2579dba 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ public function getGroupMessagesAfter($group_id, $message_id, $limit=20) public function getGroupMessagesSince($group_id, $message_id, $limit=20) public function getGroupNameById($id) public function getGroupIdByName($name) +public function getGroupMemberId($group_id, $name, $caseSensitive = FALSE) public function isMemberOfGroup($grp) public function sendGroupMessage($group_id, $text, array $attachments=array(), $source_guid=null) ``` diff --git a/src/Client.php b/src/Client.php index 69a529c..3f18644 100644 --- a/src/Client.php +++ b/src/Client.php @@ -791,6 +791,28 @@ public function disableSmsMode() { // ADDITIONAL METHODS + /** + * Looks up a member's id within a group + * + * @param int $group_id Group id + * @param string $name Member name + * @param bool $caseSensitive Name is case sensitive (default NO) + * + * @return mixed Member id or FALSE if not found + */ + public function getGroupMemberId($group_id, $name, $caseSensitive = FALSE) { + $group_members = $this->getGroupMembers($group_id); + + $name = (!$caseSensitive) ? strtolower($name) : $name; + + foreach ($group_members as $member) { + $member_name = (!$caseSensitive) ? strtolower($member['nickname']) : $member['nickname']; + if ($member_name == $name) return $member['user_id']; + } + + return FALSE; + } + /** * Looks up member ids and member name positions * in the message string and returns a mentions