public function WebformEntityStorage::getTotalNumberOfResults in Webform 8.5
Same name and namespace in other branches
- 6.x src/WebformEntityStorage.php \Drupal\webform\WebformEntityStorage::getTotalNumberOfResults()
Get total number of results for specified webform or all webforms.
Parameters
string|null $webform_id: (optional) A webform id.
Return value
array|int If no webform id is passed, an associative array keyed by webform id contains total results for all webforms, otherwise the total number of results for specified webform
Overrides WebformEntityStorageInterface::getTotalNumberOfResults
File
- src/
WebformEntityStorage.php, line 334
Class
- WebformEntityStorage
- Storage controller class for "webform" configuration entities.
Namespace
Drupal\webformCode
public function getTotalNumberOfResults($webform_id = NULL) {
if (!isset($this->totals)) {
$query = $this->database
->select('webform_submission', 'ws');
$query
->fields('ws', [
'webform_id',
]);
$query
->addExpression('COUNT(sid)', 'results');
$query
->groupBy('webform_id');
$this->totals = array_map('intval', $query
->execute()
->fetchAllKeyed());
}
if ($webform_id) {
return isset($this->totals[$webform_id]) ? $this->totals[$webform_id] : 0;
}
else {
return $this->totals;
}
}