class WebformSubmissionLogManager in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_submission_log/src/WebformSubmissionLogManager.php \Drupal\webform_submission_log\WebformSubmissionLogManager
Webform submission log manager.
Hierarchy
- class \Drupal\webform_submission_log\WebformSubmissionLogManager implements WebformSubmissionLogManagerInterface uses DependencySerializationTrait
Expanded class hierarchy of WebformSubmissionLogManager
1 string reference to 'WebformSubmissionLogManager'
- webform_submission_log.services.yml in modules/
webform_submission_log/ webform_submission_log.services.yml - modules/webform_submission_log/webform_submission_log.services.yml
1 service uses WebformSubmissionLogManager
- webform_submission_log.manager in modules/
webform_submission_log/ webform_submission_log.services.yml - Drupal\webform_submission_log\WebformSubmissionLogManager
File
- modules/
webform_submission_log/ src/ WebformSubmissionLogManager.php, line 15
Namespace
Drupal\webform_submission_logView source
class WebformSubmissionLogManager implements WebformSubmissionLogManagerInterface {
use DependencySerializationTrait;
/**
* The database service.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* WebformSubmissionLogManager constructor.
*
* @param \Drupal\Core\Database\Connection $database
* The database service.
*/
public function __construct(Connection $database) {
$this->database = $database;
}
/**
* {@inheritdoc}
*/
public function insert(array $fields) {
$fields += [
'webform_id' => '',
'sid' => '',
'handler_id' => '',
'operation' => '',
'uid' => '',
'message' => '',
'variables' => serialize([]),
'data' => serialize([]),
'timestamp' => '',
];
$this->database
->insert(WebformSubmissionLogManagerInterface::TABLE)
->fields($fields)
->execute();
}
/**
* {@inheritdoc}
*/
public function getQuery(EntityInterface $webform_entity = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL, array $options = []) {
// Default options.
$options += [
'header' => NULL,
'limit' => NULL,
];
$query = $this->database
->select(WebformSubmissionLogManagerInterface::TABLE, 'log');
// Log fields.
$query
->fields('log', [
'lid',
'uid',
'webform_id',
'sid',
'handler_id',
'operation',
'message',
'variables',
'timestamp',
'data',
]);
// User fields.
$query
->leftJoin('users_field_data', 'user', 'log.uid = user.uid');
// Submission fields.
$query
->leftJoin('webform_submission', 'submission', 'log.sid = submission.sid');
$query
->fields('submission', [
'entity_type',
'entity_id',
]);
// Webform condition.
if ($webform_entity instanceof WebformInterface) {
$query
->condition('log.webform_id', $webform_entity
->id());
}
elseif ($webform_entity instanceof WebformSubmissionInterface) {
$query
->condition('log.webform_id', $webform_entity
->getWebform()
->id());
$query
->condition('log.sid', $webform_entity
->id());
}
// Source entity conditions.
if ($source_entity) {
$query
->condition('submission.entity_type', $source_entity
->getEntityTypeId());
$query
->condition('submission.entity_id', $source_entity
->id());
}
// User account condition.
if ($account) {
$query
->condition('log.uid', $account
->id());
}
// Set header sorting.
if ($options['header']) {
$query = $query
->extend('\\Drupal\\Core\\Database\\Query\\TableSortExtender')
->orderByHeader($options['header']);
}
// Set limit pager.
if ($options['limit']) {
$query = $query
->extend('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->limit($options['limit']);
}
return $query;
}
/**
* {@inheritdoc}
*/
public function loadByEntities(EntityInterface $webform_entity = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL, array $options = []) {
$result = $this
->getQuery($webform_entity, $source_entity, $account, $options)
->execute();
$records = [];
while ($record = $result
->fetchObject()) {
$record->variables = unserialize($record->variables);
$record->data = unserialize($record->data);
$records[] = $record;
}
return $records;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
WebformSubmissionLogManager:: |
protected | property | The database service. | |
WebformSubmissionLogManager:: |
public | function |
Get webform submission log query. Overrides WebformSubmissionLogManagerInterface:: |
|
WebformSubmissionLogManager:: |
public | function |
Insert submission log. Overrides WebformSubmissionLogManagerInterface:: |
|
WebformSubmissionLogManager:: |
public | function |
Log webform submission logs. Overrides WebformSubmissionLogManagerInterface:: |
|
WebformSubmissionLogManager:: |
public | function | WebformSubmissionLogManager constructor. | |
WebformSubmissionLogManagerInterface:: |
constant | Name of the table where log entries are stored. |