You are here

protected function WebformSubmissionStorage::getSiblingSubmission in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/WebformSubmissionStorage.php \Drupal\webform\WebformSubmissionStorage::getSiblingSubmission()

Get a webform submission's sibling.

Parameters

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

\Drupal\Core\Entity\EntityInterface|null $source_entity: (optional) A webform submission source entity.

\Drupal\Core\Session\AccountInterface $account: The current user account.

array $options: (optional) Additional options and query conditions.

string $direction: Direction of the sibling.

Return value

\Drupal\webform\WebformSubmissionInterface|null The webform submission's sibling.

2 calls to WebformSubmissionStorage::getSiblingSubmission()
WebformSubmissionStorage::getNextSubmission in src/WebformSubmissionStorage.php
Get a webform submission's next sibling.
WebformSubmissionStorage::getPreviousSubmission in src/WebformSubmissionStorage.php
Get a webform submission's previous sibling.

File

src/WebformSubmissionStorage.php, line 581

Class

WebformSubmissionStorage
Defines the webform submission storage.

Namespace

Drupal\webform

Code

protected function getSiblingSubmission(WebformSubmissionInterface $webform_submission, EntityInterface $source_entity = NULL, AccountInterface $account = NULL, array $options = [], $direction = 'previous') {
  $webform = $webform_submission
    ->getWebform();
  $query = $this
    ->getQuery();
  $this
    ->addQueryConditions($query, $webform, $source_entity, $account, $options);
  if ($direction === 'previous') {
    $query
      ->condition('sid', $webform_submission
      ->id(), '<');
    $query
      ->sort('sid', 'DESC');
  }
  else {
    $query
      ->condition('sid', $webform_submission
      ->id(), '>');
    $query
      ->sort('sid', 'ASC');
  }
  $query
    ->range(0, 1);
  $submission = ($entity_ids = $query
    ->execute()) ? $this
    ->load(reset($entity_ids)) : NULL;

  // If account is specified, we need make sure the user can view the submission.
  if ($submission && $account && !$submission
    ->access('view', $account)) {
    return NULL;
  }
  return $submission;
}