/** * Find out how a person prefers to get the event notification * * @param string $action Key of the event in format component:event * @param string $recipient GUID of the receiving person * @return Array options supported by user */ private static function _merge_notification_prefences($component, $action, $recipient) { // TODO: Should we sudo here to ensure getting correct prefs regardless of ACLs? $preference = 'none'; try { $recipient = new midcom_db_person($recipient); } catch (midcom_error $e) { return $preference; } // If user has preference for this message, we use that $personal_preferences = $recipient->list_parameters('org.openpsa.notifications'); if (count($personal_preferences) > 0 && array_key_exists("{$component}:{$action}", $personal_preferences)) { $preference = $personal_preferences[$action]; return $preference; } // Fall back to component defaults $customdata = midcom::get('componentloader')->get_all_manifest_customdata('org.openpsa.notifications'); if (!empty($customdata[$component][$action]['default'])) { $preference = $customdata[$component][$action]['default']; } // Seek possible preferences for this action from user's groups $qb = new midgard_query_builder('midgard_parameter'); $qb->add_constraint('domain', '=', 'org.openpsa.notifications'); $qb->add_constraint('name', '=', "{$component}:{$action}"); // Seek user's groups $member_qb = midcom_db_member::new_query_builder(); $member_qb->add_constraint('uid', '=', (int) $recipient->id); $memberships = $member_qb->execute(); $qb->begin_group('OR'); foreach ($memberships as $member) { $group = new midcom_db_group($member->gid); $qb->add_constraint('parentguid', '=', $group->guid); } $qb->end_group(); $group_preferences = $qb->execute(); if (count($group_preferences) > 0) { foreach ($group_preferences as $preference) { $preference = $preference->value; } } return $preference; }