public function WebformSubmissionStorage::addQueryConditions in Webform 6.x
Same name and namespace in other branches
- 8.5 src/WebformSubmissionStorage.php \Drupal\webform\WebformSubmissionStorage::addQueryConditions()
Add condition to submission query.
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.
Overrides WebformSubmissionStorageInterface::addQueryConditions
7 calls to WebformSubmissionStorage::addQueryConditions()
- WebformSubmissionStorage::buildPropertyQuery in src/
WebformSubmissionStorage.php - Builds an entity query.
- WebformSubmissionStorage::deleteAll in src/
WebformSubmissionStorage.php - Delete all webform submissions.
- WebformSubmissionStorage::getMaxSubmissionId in src/
WebformSubmissionStorage.php - Get the maximum sid.
- WebformSubmissionStorage::getSiblingSubmission in src/
WebformSubmissionStorage.php - Get a webform submission's sibling.
- WebformSubmissionStorage::getTerminusSubmission in src/
WebformSubmissionStorage.php - Get a webform submission's terminus (aka first or last).
File
- src/
WebformSubmissionStorage.php, line 407
Class
- WebformSubmissionStorage
- Defines the webform submission storage.
Namespace
Drupal\webformCode
public 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', $this->time
->getRequestTime() - $options['interval'], '>');
}
if ($options['access_check'] === FALSE) {
$query
->accessCheck(FALSE);
}
}