You are here

public function YamlFormSubmissionStorage::getMaxSubmissionId in YAML Form 8

Get the maximum sid.

Parameters

\Drupal\yamlform\YamlFormInterface|null $yamlform: (optional) A form. If set the total number of submissions for the Form will be returned.

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

\Drupal\Core\Session\AccountInterface|null $account: (optional) A user account.

Return value

int Total number of submissions.

Overrides YamlFormSubmissionStorageInterface::getMaxSubmissionId

File

src/YamlFormSubmissionStorage.php, line 145

Class

YamlFormSubmissionStorage
Defines the form submission storage.

Namespace

Drupal\yamlform

Code

public function getMaxSubmissionId(YamlFormInterface $yamlform = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL) {
  $query = $this
    ->getQuery();
  $query
    ->sort('sid', 'DESC');
  if ($yamlform) {
    $query
      ->condition('yamlform_id', $yamlform
      ->id());
  }
  if ($source_entity) {
    $query
      ->condition('entity_type', $source_entity
      ->getEntityTypeId());
    $query
      ->condition('entity_id', $source_entity
      ->id());
  }
  if ($account) {
    $query
      ->condition('uid', $account
      ->id());
  }
  $query
    ->range(0, 1);
  $result = $query
    ->execute();
  return reset($result);
}