You are here

protected function WebformSubmissionStorage::getTerminusSubmission in Webform 8.5

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

Get a webform submission's terminus (aka first or last).

Parameters

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

\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 $terminus: Submission terminus, first or last.

Return value

\Drupal\webform\WebformSubmissionInterface|null The webform submission's terminus (aka first or last).

2 calls to WebformSubmissionStorage::getTerminusSubmission()
WebformSubmissionStorage::getFirstSubmission in src/WebformSubmissionStorage.php
Get a webform's first submission.
WebformSubmissionStorage::getLastSubmission in src/WebformSubmissionStorage.php
Get a webform's last submission.

File

src/WebformSubmissionStorage.php, line 555

Class

WebformSubmissionStorage
Defines the webform submission storage.

Namespace

Drupal\webform

Code

protected function getTerminusSubmission(WebformInterface $webform, EntityInterface $source_entity = NULL, AccountInterface $account = NULL, array $options = [], $terminus = 'first') {
  $options += [
    'in_draft' => FALSE,
  ];
  $query = $this
    ->getQuery();
  $this
    ->addQueryConditions($query, $webform, $source_entity, $account, $options);
  $query
    ->sort('sid', $terminus === 'first' ? 'ASC' : 'DESC');
  $query
    ->range(0, 1);
  return ($entity_ids = $query
    ->execute()) ? $this
    ->load(reset($entity_ids)) : NULL;
}