private function WebformSubmissionStorage::_addQueryConditions in Webform 8.5
Add condition to submission query.
@todo Webform 8.x-6.x: Remove and move code to ::addQueryConditions.
Parameters
\Drupal\Core\Database\Query\AlterableInterface|\Drupal\Core\Entity\Query\ConditionInterface $query: A SQL query or entity conditions.
\Drupal\webform\WebformInterface $webform: (optional) A webform.
\Drupal\Core\Entity\EntityInterface|null $source_entity: (optional) A webform submission source entity.
\Drupal\Core\Session\AccountInterface $account: (optional) The current user account.
array $options: (optional) Additional options and query conditions. Options/conditions include:
- in_draft (boolean): NULL will return all saved submissions and drafts. Defaults to NULL
- check_source_entity (boolean): Check that a source entity is defined.
- interval (int): Limit total within an seconds interval.
- check_access (boolean): Check access to the submission.
2 calls to WebformSubmissionStorage::_addQueryConditions()
- WebformSubmissionStorage::addQueryConditions in src/
WebformSubmissionStorage.php - Add condition to submission query.
- WebformSubmissionStorage::buildPropertyQuery in src/
WebformSubmissionStorage.php - Builds an entity query.
File
- src/
WebformSubmissionStorage.php, line 414
Class
- WebformSubmissionStorage
- Defines the webform submission storage.
Namespace
Drupal\webformCode
private function _addQueryConditions($query, WebformInterface $webform = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL, array $options = []) {
// Set default options/conditions.
$options += [
'check_source_entity' => FALSE,
'in_draft' => NULL,
'interval' => NULL,
'access_check' => TRUE,
];
if ($webform) {
$query
->condition('webform_id', $webform
->id());
}
if ($source_entity) {
$query
->condition('entity_type', $source_entity
->getEntityTypeId());
$query
->condition('entity_id', $source_entity
->id());
}
elseif ($options['check_source_entity']) {
$query
->notExists('entity_type');
$query
->notExists('entity_id');
}
if ($account) {
$query
->condition('uid', $account
->id());
// Add anonymous submission ids stored in $_SESSION.
if ($account
->isAnonymous() && (int) $account
->id() === (int) $this->currentUser
->id()) {
$sids = $this
->getAnonymousSubmissionIds($account);
if (empty($sids)) {
// Look for NULL sid to force returning no results.
$query
->condition('sid', NULL);
}
else {
$query
->condition('sid', $sids, 'IN');
}
}
}
if ($options['in_draft'] !== NULL) {
// Cast boolean to integer to support SQLite.
$query
->condition('in_draft', (int) $options['in_draft']);
}
if ($options['interval']) {
$query
->condition('completed', \Drupal::time()
->getRequestTime() - $options['interval'], '>');
}
if ($options['access_check'] === FALSE) {
$query
->accessCheck(FALSE);
}
}