function notifications_get_subscriptions in Notifications 6.4
Same name and namespace in other branches
- 5 notifications.module \notifications_get_subscriptions()
- 6 notifications.module \notifications_get_subscriptions()
- 6.2 notifications.module \notifications_get_subscriptions()
- 6.3 notifications.module \notifications_get_subscriptions()
- 7 notifications.module \notifications_get_subscriptions()
Get subscriptions that match a set of conditions.
@todo Check field types for building the query
Parameters
$main_conditions: Conditions for the main notifications table
$field_conditions: Optional array of condition fields. The elements may be
- single field => value pairs
- or numeric key => array('type' => field, 'value' => value)
$exact_fields: Whether to limit the result to subscriptions with exactly that condition fields. Otherwise we look for subscriptions that have and match that fields but may have more than that.
$key: Optional key field to use as the array index. Will default to sid For notifications with one field, it may be 'value' or 'intval'
$pager: Whether to throw a pager query
Return value
Array of subscriptions indexed by uid, module, field, value, author
9 calls to notifications_get_subscriptions()
- NotificationsBasicTests::testNotificationsBasicAPI in tests/
notifications_api.test - Play with creating, retrieving, deleting a pair subscriptions
- NotificationsTestCase::contentCreateSubscription in tests/
notifications_test_case.inc - Helper function to create a subscription
- notifications_autosubscribe in notifications_autosubscribe/
notifications_autosubscribe.module - Subscribes users to content they post, if not already subscribed
- notifications_destination_get_subscriptions in includes/
destination.inc - Query subscriptions for destination
- notifications_object_user_subscriptions in includes/
object.inc - Get list of possible and existing subscriptions for user/object
File
- ./
notifications.module, line 863 - Notifications module
Code
function notifications_get_subscriptions($main_conditions, $field_conditions = NULL, $exact_fields = TRUE, $key = 'sid', $pager = NULL) {
notifications_include('query.inc');
// Build query conditions using the query builder.
$query['select'][] = 's.*';
// If we have the exact fields, make sure we match only the rows with this number of conditions
if ($exact_fields && isset($field_conditions)) {
$main_conditions += array(
'conditions' => count($field_conditions),
);
}
// Query for the notifications table
$result = notifications_query_subscriptions($main_conditions, $field_conditions, $query);
// Build list with results, we may need to index by a different field
if ($key == 'sid') {
$subscriptions = $result;
}
else {
$subscriptions = array();
foreach ($result as $subs) {
if ($key == 'value' || $key == 'intval') {
$field = array_shift($subs
->get_fields());
$subscriptions[$field->value] = $subs;
}
else {
$subscriptions[$subs->{$key}] = $subs;
}
}
}
return $subscriptions;
}