function notifications_query_build in Notifications 6.2
Same name and namespace in other branches
- 5 notifications.module \notifications_query_build()
- 6.4 includes/query.inc \notifications_query_build()
- 6 notifications.module \notifications_query_build()
- 6.3 notifications.module \notifications_query_build()
Query builder for subscriptions
This adds up query elements into a big array so they can be later rendered as SQL
Parameters
$params: Array of query conditions
$query: Base query to build upon
See also
3 calls to notifications_query_build()
- NotificationsBasicTests::testNotificationsQueryBuilder in tests/
notifications_api.test - Test query builder
- notifications_queue in ./
notifications.module - Queue events for notifications adding query conditions from plug-ins
- notifications_user_get_subscriptions in ./
notifications.module - Get subscription for a given user
File
- ./
notifications.module, line 547 - Notifications module
Code
function notifications_query_build($params, $query = array()) {
foreach ($params as $name => $elements) {
if ($name == 'fields') {
// Fields elements have some special handling, they have the form: field => value
foreach ($elements as $field => $value) {
// Use field definition provided by hook_notifications('subscription fields') and handle array values with IN conditions
// Workaround to have a valid one because not all modules provide the information yet (og?)
if (notifications_subscription_fields($field, 'type') == 'int') {
$type = 'int';
$fieldval = 'intval';
}
else {
$type = 'char';
$fieldval = 'value';
}
if (is_array($value)) {
$query['fields'][] = "f.field = '%s' AND f.{$fieldval} IN (" . db_placeholders($value, $type) . ")";
$query['fields args'][] = $field;
$query['fields args'] = empty($query['fields args']) ? $value : array_merge($query['fields args'], $value);
}
else {
$query['fields'][] = "f.field = '%s' AND f.{$fieldval} = " . db_type_placeholder($type);
$query['fields args'][] = $field;
$query['fields args'][] = $value;
}
}
}
else {
if ($name == 'fields sql') {
// These are added as 'fields' parameters without further parsing
$name = 'fields';
}
if (is_array($elements)) {
$query[$name] = empty($query[$name]) ? $elements : array_merge($query[$name], $elements);
}
else {
$query[$name][] = $elements;
}
}
}
return $query;
}