You are here

protected function Memory::randomDeliveryReports in SMS Framework 8

Same name and namespace in other branches
  1. 2.x tests/modules/sms_test_gateway/src/Plugin/SmsGateway/Memory.php \Drupal\sms_test_gateway\Plugin\SmsGateway\Memory::randomDeliveryReports()
  2. 2.1.x tests/modules/sms_test_gateway/src/Plugin/SmsGateway/Memory.php \Drupal\sms_test_gateway\Plugin\SmsGateway\Memory::randomDeliveryReports()

Generates random delivery reports for each of the recipients of a message.

Parameters

\Drupal\sms\Message\SmsMessageInterface $sms_message: The SMS message.

Return value

\Drupal\sms\Message\SmsDeliveryReportInterface[] An array of delivery reports.

1 call to Memory::randomDeliveryReports()
Memory::send in tests/modules/sms_test_gateway/src/Plugin/SmsGateway/Memory.php
Sends an SMS.

File

tests/modules/sms_test_gateway/src/Plugin/SmsGateway/Memory.php, line 161

Class

Memory
Defines a gateway storing transmitted SMS in memory.

Namespace

Drupal\sms_test_gateway\Plugin\SmsGateway

Code

protected function randomDeliveryReports(SmsMessageInterface $sms_message) {
  $random = new Random();
  $request_time = \Drupal::time()
    ->getRequestTime();
  $reports = [];
  foreach ($sms_message
    ->getRecipients() as $number) {
    $reports[] = (new SmsDeliveryReport())
      ->setRecipient($number)
      ->setMessageId($random
      ->name(16))
      ->setStatus(SmsMessageReportStatus::QUEUED)
      ->setStatusTime($request_time)
      ->setStatusMessage('Sent to memory gateway')
      ->setTimeQueued($request_time)
      ->setTimeDelivered($request_time + rand(0, 10));
  }
  return $reports;
}