Skip to content

Instantly share code, notes, and snippets.

@signalpoint
Created January 15, 2018 15:35
Show Gist options
  • Save signalpoint/e018da6bb429cdfac33ee69b29151289 to your computer and use it in GitHub Desktop.
Save signalpoint/e018da6bb429cdfac33ee69b29151289 to your computer and use it in GitHub Desktop.
Drupal 7 Push Notification Tokens for Organic Group Members
<?php
/**
* Given a group node id, this will return all the push notification tokens
* belonging to users who are active members of the group.
* @param $gid
* @return {Array} An array of push notification strings.
*/
function group_member_push_notification_tokens($gid) {
$query = db_select("og_membership", "ogm");
$query->join('push_notifications_tokens', 'tokens', 'ogm.etid = tokens.uid');
$query->condition("ogm.entity_type", 'user');
$query->condition("ogm.gid", $gid);
$query->condition("ogm.group_type", 'node');
$query->condition("ogm.state", OG_STATE_ACTIVE);
$query->condition("tokens.type", PUSH_NOTIFICATIONS_TYPE_ID_ANDROID); // @TODO support iOS too!
$query->fields("tokens", array('token'));
$result = $query->execute();
return $result->fetchAll();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment