You are here

public function MassContact::getGroupedRecipients in Mass Contact 8

Get groups of recipients for batch processing.

Parameters

int[] $all_recipients: An array of all recipients.

Return value

array An array of arrays of recipients.

Overrides MassContactInterface::getGroupedRecipients

1 call to MassContact::getGroupedRecipients()
MassContact::queueRecipients in src/MassContact.php
Takes a mass contact, calculates recipients and queues them for delivery.

File

src/MassContact.php, line 208

Class

MassContact
The Mass Contact helper service.

Namespace

Drupal\mass_contact

Code

public function getGroupedRecipients(array $all_recipients) {
  $groupings = [];
  $recipients = [];
  foreach ($all_recipients as $recipient) {
    $recipients[] = $recipient;
    if (count($recipients) == static::MAX_QUEUE_RECIPIENTS) {

      // Send in batches.
      $groupings[] = $recipients;
      $recipients = [];
    }
  }

  // If there are any left, group those too.
  if (!empty($recipients)) {
    $groupings[] = $recipients;
  }
  return $groupings;
}