Skip to content

Instantly share code, notes, and snippets.

@lianglee
Created March 17, 2016 19:12
Show Gist options
  • Save lianglee/cef412a6e7048a97b805 to your computer and use it in GitHub Desktop.
Save lianglee/cef412a6e7048a97b805 to your computer and use it in GitHub Desktop.
Get user groups that he is member of (not his own groups)
$id = 2;
$groups = new OssnGroup;
$joined = ossn_get_relationships(array(
'to' => $id,
'type' => 'group:join:approve'
));
$myown = $groups->searchObject(array(
'type' => 'user',
'subtype' => 'ossngroup',
'owner_guid' => $id
));
if($myown) {
foreach($myown as $mitem) {
$mowngroups[] = $mitem->guid;
}
}
if($joined) {
foreach($joined as $item) {
if(!in_array($item->relation_from, $mowngroups)) {
$ids[] = $item->relation_from;
}
}
$joinedids = implode(',', $ids);
$groups_memberof = $groups->searchObject(array(
'type' => 'user',
'subtype' => 'ossngroup',
'wheres' => "o.guid IN ('$joinedids')"
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment