You are here

public function MessageDigest::aggregate in Message Digest 7

Aggregate all of the messages for this interval and notifier that haven't already been sent, and group them by user and then by group.

File

plugins/notifier/abstract.inc, line 57

Class

MessageDigest
Message Digest notifier.

Code

public function aggregate() {
  $interval = $this
    ->getInterval();
  $start = strtotime('-' . $interval);

  // Invert $interval since it's in the past.
  $message_groups = array();
  $query = db_select('message_digest', 'md');
  $query
    ->fields('md');
  $query
    ->condition('timestamp', $start, '>');
  $query
    ->condition('sent', FALSE);
  $query
    ->condition('notifier', $this->plugin['name']);
  $result = $query
    ->execute();
  foreach ($result as $row) {
    $gid = $row->gid;
    if (empty($gid)) {
      $gid = 0;
    }
    $account = user_load($row->receiver);
    $context = array(
      'account' => $account,
      // reference only
      'data' => $row,
      'gid' => $gid,
      // set this to zero to aggregate group content
      'plugin' => $this->plugin,
    );
    drupal_alter('message_digest_aggregate', $context);
    if (!empty($context['data']->mid)) {
      $message_groups[$context['data']->receiver][$context['gid']][] = $context['data']->mid;
    }
  }
  return $message_groups;
}