Skip to content

Commit

Permalink
Adds a function to lookup a member's id within a group
Browse files Browse the repository at this point in the history
  • Loading branch information
rgaida committed Oct 13, 2015
1 parent 3cbda92 commit 60652f3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
Expand Down
22 changes: 22 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 60652f3

Please sign in to comment.