You are here

function notifications_query_event_queue in Notifications 6.4

Build a query skeleton for inserting an event into the queue.

This can be reused by other modules to build their custom queue queries

Parameters

$event: Event object

Return value

array() Query skeleton

1 call to notifications_query_event_queue()
Notifications_Queue::queue_event in includes/notifications_queue.class.inc
Queue events for notifications adding query conditions from plug-ins

File

includes/query.inc, line 118
Notifications query API - Helper functions to build monster queries

Code

function notifications_query_event_queue($event) {
  $query['insert'] = array(
    'uid',
    'mdid',
    'send_method',
    'sid',
    'module',
    'eid',
    'send_interval',
    'language',
    'cron',
    'created',
    'conditions',
  );
  $query['into'] = '{notifications_queue}';
  $query['distinct'] = TRUE;
  $query['select'] = array(
    's.uid',
    's.mdid',
    's.send_method',
    's.sid',
    's.module',
    '%d',
    's.send_interval',
    's.language',
    's.cron',
    '%d',
    's.conditions',
  );
  $query['from'] = array(
    '{notifications} s',
  );
  $query['select args'] = array(
    $event->eid,
    $event->created,
  );

  // We do a left join instead of inner join to allow subscriptions with no fields to work
  $query['join'] = array(
    'LEFT JOIN {notifications_fields} f ON s.sid = f.sid',
  );
  $query['where'] = array(
    's.status = 1',
    "s.event_type = '%s'",
    's.send_interval >= 0',
  );
  $query['where args'] = array(
    $event->type,
  );

  // Add one more condition if we don't send notifications on own posts
  if (!variable_get('notifications_sendself', 1) && !empty($event->uid)) {
    $query['where'][] = 's.uid <> %d';
    $query['where args'][] = $event->uid;
  }

  // Some group by fields are not really needed but added for pgsql compatibility
  $query['group'] = array(
    's.uid',
    's.mdid',
    's.send_method',
    's.sid',
    's.module',
    's.send_interval',
    's.cron',
    's.conditions',
    's.language',
  );

  // We throw in all the conditions and check the number of matching conditions
  // that must be equal to the subscription conditions number
  $query['having'] = array(
    's.conditions = count(f.sid)',
  );
  return $query;
}