You are here

private function SitewideAlertManager::soonestAppearingScheduledAlertDateTime in Sitewide Alert 8

Determines the datetime of the soonest expiring scheduled alert.

Return value

\Drupal\Core\Datetime\DrupalDateTime|null The datetime of the soonest expiring scheduled alert; null if none of the alerts are scheduled to expire.

1 call to SitewideAlertManager::soonestAppearingScheduledAlertDateTime()
SitewideAlertManager::nextScheduledChange in src/SitewideAlertManager.php
The time of the next scheduled change of alerts.

File

src/SitewideAlertManager.php, line 149

Class

SitewideAlertManager

Namespace

Drupal\sitewide_alert

Code

private function soonestAppearingScheduledAlertDateTime() {

  /** @var DrupalDateTime|null $soonestScheduledEndDate */
  $soonestScheduledStartDate = NULL;
  foreach ($this
    ->activeSitewideAlerts() as $sitewideAlert) {
    if (!$sitewideAlert
      ->isScheduled()) {
      continue;
    }
    if (!($startDateTime = $sitewideAlert
      ->getScheduledStartDateTime())) {
      continue;
    }
    if ($startDateTime
      ->getPhpDateTime() < $this
      ->requestDateTime()) {
      continue;
    }
    if ($soonestScheduledStartDate === NULL) {
      $soonestScheduledStartDate = $startDateTime;
      continue;
    }
    if ($soonestScheduledStartDate > $startDateTime) {
      $soonestScheduledStartDate = $startDateTime;
    }
  }
  return $soonestScheduledStartDate;
}