You are here

public function YamlFormSubmissionStorage::getTotal in YAML Form 8

Get the total number of submissions.

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::getTotal

File

src/YamlFormSubmissionStorage.php, line 122

Class

YamlFormSubmissionStorage
Defines the form submission storage.

Namespace

Drupal\yamlform

Code

public function getTotal(YamlFormInterface $yamlform = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL) {
  $query = $this
    ->getQuery();
  $query
    ->condition('in_draft', FALSE);
  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());
  }

  // Issue: Query count method is not working for SQL Lite.
  // return $query->count()->execute();
  // Work-around: Manually count the number of entity ids.
  return count($query
    ->execute());
}