function oa_notifications_get_notifications in Open Atrium Notifications 7.2
Return the resolved list of all users to be notified on a piece of content.
Parameters
object $node: The node to return notifications.
Return value
array An array of users keyed by uid.
File
- ./
oa_notifications.module, line 93
Code
function oa_notifications_get_notifications($node, $notifications = NULL) {
$cache =& drupal_static(__FUNCTION__);
// See if notifications should be skipped.
if (oa_notification_skip()) {
return array();
}
$nid = isset($node) ? $node->nid : 0;
if (!isset($cache[$nid])) {
$bucket = array();
$gid = isset($node) ? oa_core_get_group_from_node($node) : oa_core_get_space_context();
if (!isset($notifications)) {
$notifications = oa_notifications_load_multiple($node);
}
if (isset($notifications['group'])) {
foreach (array_keys($notifications['group']) as $group_id) {
$users = oa_core_get_group_users_for_space($gid, $group_id);
$bucket += $users;
}
}
if (isset($notifications['team'])) {
foreach (array_keys($notifications['team']) as $team_id) {
$results = oa_teams_get_team_members($team_id);
$users = user_load_multiple(array_keys($results));
$bucket += $users;
}
}
if (isset($notifications['user'])) {
$users = user_load_multiple(array_keys($notifications['user']));
$bucket += $users;
}
if (isset($node)) {
// Also grab users who flagged the content.
$flags = flag_get_entity_flags('node', $node->nid, 'subscribe_section_content');
if (!empty($flags) && is_array($flags)) {
$bucket += user_load_multiple(array_keys($flags));
}
// Get users who subscribed to entire section.
if (isset($node->{OA_SECTION_FIELD}[LANGUAGE_NONE][0]['target_id'])) {
$flags = flag_get_entity_flags('node', $node->{OA_SECTION_FIELD}[LANGUAGE_NONE][0]['target_id'], 'subscribe_section_content');
if (!empty($flags) && is_array($flags)) {
$bucket += user_load_multiple(array_keys($flags));
}
}
// Get users who subscribed to entire space.
if (isset($node->{OA_SPACE_FIELD}[LANGUAGE_NONE][0]['target_id'])) {
$flags = flag_get_entity_flags('node', $node->{OA_SPACE_FIELD}[LANGUAGE_NONE][0]['target_id'], 'subscribe_section_content');
if (!empty($flags) && is_array($flags)) {
$bucket += user_load_multiple(array_keys($flags));
}
}
// Only notify users who have access to this node
foreach ($bucket as $uid => $user) {
if (!node_access('view', $node, $user)) {
unset($bucket[$uid]);
}
}
// Allow modules to alter users.
drupal_alter('notifications_users', $bucket, $node);
}
$cache[$nid] = $bucket;
}
return $cache[$nid];
}