You are here

public function DigestBase::aggregate in Message Digest 8

Aggregate all of the messages for this digest.

Collect all messages for the digest's interval and notifier that haven't already been sent, and group them by user and then by group.

$aggregate = [
  '' => [
    // Non-grouped message digests here.
    12,
    24,
  ],
  'node' => [
    23 => [
      1,
      3,
      5,
    ],
  ],
];

Parameters

int $uid: The recipient's user ID for which to aggregate the digest.

int $end_time: The unix timestamp from which all messages in the past will be aggregated.

Return value

array An array of message IDs for the given user, keyed by entity_type, then by entity_id.

Overrides DigestInterface::aggregate

File

src/Plugin/Notifier/DigestBase.php, line 171

Class

DigestBase
Message Digest notifier.

Namespace

Drupal\message_digest\Plugin\Notifier

Code

public function aggregate($uid, $end) {
  $message_groups = [];
  $query = $this->connection
    ->select('message_digest', 'md');
  $query
    ->fields('md')
    ->condition('timestamp', $end, '<=')
    ->condition('receiver', $uid)
    ->condition('sent', 0)
    ->condition('notifier', $this
    ->getPluginId());
  $query
    ->orderBy('id');
  $result = $query
    ->execute();
  foreach ($result as $row) {
    $entity_type = $row->entity_type;
    $entity_id = $row->entity_id;
    $context = [
      'data' => $row,
      // Set this to zero to aggregate group content.
      'entity_type' => $entity_type,
      'entity_id' => $entity_id,
    ];
    if (!empty($context['data']->mid)) {
      $message_groups[$context['entity_type']][$context['entity_id']][] = $context['data']->mid;
    }
  }
  return $message_groups;
}