You are here

protected function WebformScheduledEmailManager::addQueryConditions in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_scheduled_email/src/WebformScheduledEmailManager.php \Drupal\webform_scheduled_email\WebformScheduledEmailManager::addQueryConditions()

Add condition to scheduled email query.

Parameters

\Drupal\Core\Database\Query\AlterableInterface|\Drupal\Core\Database\Query\Delete $query: The query instance.

\Drupal\webform\WebformInterface|null $webform: A webform.

\Drupal\webform\WebformSubmissionInterface|null $webform_submission: A webform submission.

\Drupal\Core\Entity\EntityInterface|null $source_entity: A source entity.

string|null $handler_id: A webform handler id.

string|null $state: The state of the scheduled emails.

5 calls to WebformScheduledEmailManager::addQueryConditions()
WebformScheduledEmailManager::cronSchedule in modules/webform_scheduled_email/src/WebformScheduledEmailManager.php
Schedule emails.
WebformScheduledEmailManager::cronSend in modules/webform_scheduled_email/src/WebformScheduledEmailManager.php
Sending schedule emails.
WebformScheduledEmailManager::load in modules/webform_scheduled_email/src/WebformScheduledEmailManager.php
Load scheduled email for specified submission and handler.
WebformScheduledEmailManager::total in modules/webform_scheduled_email/src/WebformScheduledEmailManager.php
Get the total number of scheduled emails.
WebformScheduledEmailManager::unschedule in modules/webform_scheduled_email/src/WebformScheduledEmailManager.php
Unscheduled an email that is waiting to sent.

File

modules/webform_scheduled_email/src/WebformScheduledEmailManager.php, line 849

Class

WebformScheduledEmailManager
Defines the webform scheduled email manager.

Namespace

Drupal\webform_scheduled_email

Code

protected function addQueryConditions($query, WebformInterface $webform = NULL, WebformSubmissionInterface $webform_submission = NULL, EntityInterface $source_entity = NULL, $handler_id = NULL, $state = NULL) {
  $prefix = $query instanceof QueryDelete ? '' : 'w.';
  if ($webform) {
    $query
      ->condition($prefix . 'webform_id', $webform
      ->id());
  }
  if ($webform_submission) {
    $query
      ->condition($prefix . 'sid', $webform_submission
      ->id());
  }
  if ($source_entity) {
    $query
      ->condition($prefix . 'entity_type', $source_entity
      ->getEntityTypeId());
    $query
      ->condition($prefix . 'entity_id', $source_entity
      ->id());
  }
  if ($handler_id && ($webform || $webform_submission)) {
    $query
      ->condition($prefix . 'handler_id', $handler_id);
  }
  switch ($state) {
    case WebformScheduledEmailManagerInterface::SUBMISSION_SCHEDULE:
    case WebformScheduledEmailManagerInterface::SUBMISSION_UNSCHEDULE:
    case WebformScheduledEmailManagerInterface::SUBMISSION_RESCHEDULE:
    case WebformScheduledEmailManagerInterface::SUBMISSION_SEND:
      $query
        ->condition($prefix . 'state', $state);
      break;
    case WebformScheduledEmailManagerInterface::SUBMISSION_WAITING:
      $query
        ->condition($prefix . 'state', WebformScheduledEmailManagerInterface::SUBMISSION_SEND, '<>');
      break;
    case WebformScheduledEmailManagerInterface::SUBMISSION_QUEUED:
    case WebformScheduledEmailManagerInterface::SUBMISSION_READY:
      $query
        ->condition($prefix . 'state', WebformScheduledEmailManagerInterface::SUBMISSION_SEND);
      $query
        ->isNotNull($prefix . 'send');
      $query
        ->condition($prefix . 'send', time(), $state === WebformScheduledEmailManagerInterface::SUBMISSION_QUEUED ? '>=' : '<');
      $query
        ->condition($prefix . 'state', WebformScheduledEmailManagerInterface::SUBMISSION_SEND);
      break;
  }
}