Loading src/Plugin/UsageType/Generic.php +5 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,11 @@ class Generic extends UsageTypePluginBase { 'type' => 'text', 'not null' => FALSE, 'description' => 'Path of the event.', 'views_field_label' => t('Path'), 'views_field_type' => 'standard', 'views_sort_type' => 'standard', 'views_filter_type' => 'string', 'views_argument_type' => 'standard', ], ], ]; Loading src/Plugin/UsageType/Legacy.php +20 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,11 @@ class Legacy extends UsageTypePluginBase { 'type' => 'text', 'not null' => FALSE, 'description' => 'Path of the event.', 'views_field_label' => t('Path'), 'views_field_type' => 'standard', 'views_sort_type' => 'standard', 'views_filter_type' => 'string', 'views_argument_type' => 'standard', ], 'uid' => [ 'description' => 'The user ID.', Loading @@ -72,6 +77,11 @@ class Legacy extends UsageTypePluginBase { 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'views_field_label' => t('UID'), 'views_field_type' => 'standard', 'views_sort_type' => 'standard', 'views_filter_type' => 'string', 'views_argument_type' => 'user_uid', ], 'user_name' => [ 'description' => 'The username of the user.', Loading @@ -79,6 +89,11 @@ class Legacy extends UsageTypePluginBase { 'length' => 128, 'not null' => TRUE, 'default' => '', 'views_field_label' => t('Username'), 'views_field_type' => 'standard', 'views_sort_type' => 'standard', 'views_filter_type' => 'user_name', 'views_argument_type' => 'standard', ], 'user_role' => [ 'description' => 'The role of the user.', Loading @@ -86,6 +101,11 @@ class Legacy extends UsageTypePluginBase { 'length' => 128, 'not null' => TRUE, 'default' => '', 'views_field_label' => t('Role'), 'views_field_type' => 'user_roles', 'views_sort_type' => 'standard', 'views_filter_type' => 'user_roles', 'views_argument_type' => 'user__roles_rid', ], ], 'indexes' => [ Loading src/Plugin/views/query/UsageDataQuery.php 0 → 100644 +17 −0 Original line number Diff line number Diff line <?php namespace Drupal\usage_data\Plugin\views\query; use Drupal\views\Plugin\views\query\Sql; /** * usage_data views query plugin in order to query the tracking to views. * * @ViewsQuery( * id = "usage_data_query", * title = @Translation("Usage Data Query"), * ) */ class UsageDataQuery extends Sql { } src/UsageDataDatabaseStorage.php +30 −0 Original line number Diff line number Diff line Loading @@ -233,6 +233,11 @@ class UsageDataDatabaseStorage implements UsageDataStorageInterface { 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'views_field_label' => 'ID', 'views_field_type' => 'numeric', 'views_sort_type' => 'numeric', 'views_filter_type' => 'numeric', 'views_argument_type' => 'numeric', ], 'event_type' => [ 'description' => 'The event type.', Loading @@ -240,6 +245,11 @@ class UsageDataDatabaseStorage implements UsageDataStorageInterface { 'length' => 32, 'not null' => TRUE, 'default' => '', 'views_field_label' => 'Event Type', 'views_field_type' => 'standard', 'views_sort_type' => 'standard', 'views_filter_type' => 'string', 'views_argument_type' => 'standard', ], 'entity_type_id' => [ 'description' => 'The entity type id.', Loading @@ -247,11 +257,21 @@ class UsageDataDatabaseStorage implements UsageDataStorageInterface { 'length' => 32, 'not null' => TRUE, 'default' => '', 'views_field_label' => 'Entity Type ID', 'views_field_type' => 'standard', 'views_sort_type' => 'standard', 'views_filter_type' => 'string', 'views_argument_type' => 'standard', ], 'entity_id' => [ 'description' => 'The entity id for these statistics.', 'type' => 'int', 'unsigned' => TRUE, 'views_field_label' => 'Entity ID', 'views_field_type' => 'numeric', 'views_sort_type' => 'numeric', 'views_filter_type' => 'numeric', 'views_argument_type' => 'numeric', ], 'timestamp' => [ 'description' => 'The most recent time the event took place.', Loading @@ -259,6 +279,11 @@ class UsageDataDatabaseStorage implements UsageDataStorageInterface { 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'views_field_type' => 'date', 'views_sort_type' => 'date', 'views_filter_type' => 'date', 'views_argument_type' => 'date', 'views_field_label' => 'Timestamp', ], ], 'primary key' => ['id'], Loading Loading @@ -291,6 +316,11 @@ class UsageDataDatabaseStorage implements UsageDataStorageInterface { 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'views_field_label' => 'Counter', 'views_field_type' => 'numeric', 'views_sort_type' => 'numeric', 'views_filter_type' => 'numeric', 'views_argument_type' => 'numeric', ]; } return $schema; Loading usage_data.module +45 −2 Original line number Diff line number Diff line Loading @@ -154,15 +154,47 @@ function usage_data_views_data() { if (!empty($activePlugins = $usageTypeManager->getActiveDefinitions())) { foreach ($activePlugins as $id => $definition) { $class = $definition['class']; $label = $definition['label']; $tableName = $usageDataDatabaseStorage->tableName($id); $data[$tableName]['table'] = [ 'group' => t('Usage Data'), 'provider' => 'usage_data', 'base' => [ 'title' => t('Usage Data: @label', ['@label' => $label]), 'help' => t('Usage Data table query for @label tracking.', ['@label' => $label]), 'query_id' => 'usage_data_query', ], ]; $default_schema = $usageDataDatabaseStorage->defaultSchema()['fields'] ?? []; $custom_schema = $class::schema()['fields'] ?? []; $schema = array_merge($default_schema, $custom_schema); foreach ($schema as $field_name => $field_definitions) { $data[$tableName][$field_name] = [ 'title' => $field_definitions['views_field_label'] ?? $field_name, 'help' => $field_definitions['description'] ?? $field_name, 'field' => [ 'id' => $field_definitions['views_field_type'] ?? 'standard', ], 'sort' => [ 'id' => $field_definitions['views_sort_type'] ?? 'standard', ], 'filter' => [ 'id' => $field_definitions['views_filter_type'] ?? 'standard', ], 'argument' => [ 'id' => $field_definitions['views_argument_type'] ?? 'standard', ], ]; } if (!defined("$class::ENTITY_TYPES") || empty($class::ENTITY_TYPES)) { continue; } $entityTypes = $class::ENTITY_TYPES; $eventTypes = $class::eventTypes(); $label = $definition['label']; $description = $definition['description']; $isCounter = defined("$class::COUNTER_FIELD_NAME") && !empty($class::COUNTER_FIELD_NAME); $tableName = $usageDataDatabaseStorage->tableName($id); foreach ($entityTypes as $entityTypeId) { if ($entityTypeManager->hasDefinition($entityTypeId)) { Loading @@ -170,6 +202,17 @@ function usage_data_views_data() { $table = $entityType->getBaseTable(); $entity_key = $entityType->getKey('id'); $data[$tableName]['entity_id_' . $table] = [ 'title' => $entityType->getLabel(), 'relationship' => [ 'id' => 'standard', 'label' => $entityType->getLabel(), 'base' => $table, 'base field' => $entity_key, 'real field' => 'entity_id', ], ]; foreach ($eventTypes as $event) { $title = t('Usage Data: @type counter for @label', [ '@label' => $label, Loading Loading
src/Plugin/UsageType/Generic.php +5 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,11 @@ class Generic extends UsageTypePluginBase { 'type' => 'text', 'not null' => FALSE, 'description' => 'Path of the event.', 'views_field_label' => t('Path'), 'views_field_type' => 'standard', 'views_sort_type' => 'standard', 'views_filter_type' => 'string', 'views_argument_type' => 'standard', ], ], ]; Loading
src/Plugin/UsageType/Legacy.php +20 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,11 @@ class Legacy extends UsageTypePluginBase { 'type' => 'text', 'not null' => FALSE, 'description' => 'Path of the event.', 'views_field_label' => t('Path'), 'views_field_type' => 'standard', 'views_sort_type' => 'standard', 'views_filter_type' => 'string', 'views_argument_type' => 'standard', ], 'uid' => [ 'description' => 'The user ID.', Loading @@ -72,6 +77,11 @@ class Legacy extends UsageTypePluginBase { 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'views_field_label' => t('UID'), 'views_field_type' => 'standard', 'views_sort_type' => 'standard', 'views_filter_type' => 'string', 'views_argument_type' => 'user_uid', ], 'user_name' => [ 'description' => 'The username of the user.', Loading @@ -79,6 +89,11 @@ class Legacy extends UsageTypePluginBase { 'length' => 128, 'not null' => TRUE, 'default' => '', 'views_field_label' => t('Username'), 'views_field_type' => 'standard', 'views_sort_type' => 'standard', 'views_filter_type' => 'user_name', 'views_argument_type' => 'standard', ], 'user_role' => [ 'description' => 'The role of the user.', Loading @@ -86,6 +101,11 @@ class Legacy extends UsageTypePluginBase { 'length' => 128, 'not null' => TRUE, 'default' => '', 'views_field_label' => t('Role'), 'views_field_type' => 'user_roles', 'views_sort_type' => 'standard', 'views_filter_type' => 'user_roles', 'views_argument_type' => 'user__roles_rid', ], ], 'indexes' => [ Loading
src/Plugin/views/query/UsageDataQuery.php 0 → 100644 +17 −0 Original line number Diff line number Diff line <?php namespace Drupal\usage_data\Plugin\views\query; use Drupal\views\Plugin\views\query\Sql; /** * usage_data views query plugin in order to query the tracking to views. * * @ViewsQuery( * id = "usage_data_query", * title = @Translation("Usage Data Query"), * ) */ class UsageDataQuery extends Sql { }
src/UsageDataDatabaseStorage.php +30 −0 Original line number Diff line number Diff line Loading @@ -233,6 +233,11 @@ class UsageDataDatabaseStorage implements UsageDataStorageInterface { 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'views_field_label' => 'ID', 'views_field_type' => 'numeric', 'views_sort_type' => 'numeric', 'views_filter_type' => 'numeric', 'views_argument_type' => 'numeric', ], 'event_type' => [ 'description' => 'The event type.', Loading @@ -240,6 +245,11 @@ class UsageDataDatabaseStorage implements UsageDataStorageInterface { 'length' => 32, 'not null' => TRUE, 'default' => '', 'views_field_label' => 'Event Type', 'views_field_type' => 'standard', 'views_sort_type' => 'standard', 'views_filter_type' => 'string', 'views_argument_type' => 'standard', ], 'entity_type_id' => [ 'description' => 'The entity type id.', Loading @@ -247,11 +257,21 @@ class UsageDataDatabaseStorage implements UsageDataStorageInterface { 'length' => 32, 'not null' => TRUE, 'default' => '', 'views_field_label' => 'Entity Type ID', 'views_field_type' => 'standard', 'views_sort_type' => 'standard', 'views_filter_type' => 'string', 'views_argument_type' => 'standard', ], 'entity_id' => [ 'description' => 'The entity id for these statistics.', 'type' => 'int', 'unsigned' => TRUE, 'views_field_label' => 'Entity ID', 'views_field_type' => 'numeric', 'views_sort_type' => 'numeric', 'views_filter_type' => 'numeric', 'views_argument_type' => 'numeric', ], 'timestamp' => [ 'description' => 'The most recent time the event took place.', Loading @@ -259,6 +279,11 @@ class UsageDataDatabaseStorage implements UsageDataStorageInterface { 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'views_field_type' => 'date', 'views_sort_type' => 'date', 'views_filter_type' => 'date', 'views_argument_type' => 'date', 'views_field_label' => 'Timestamp', ], ], 'primary key' => ['id'], Loading Loading @@ -291,6 +316,11 @@ class UsageDataDatabaseStorage implements UsageDataStorageInterface { 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'views_field_label' => 'Counter', 'views_field_type' => 'numeric', 'views_sort_type' => 'numeric', 'views_filter_type' => 'numeric', 'views_argument_type' => 'numeric', ]; } return $schema; Loading
usage_data.module +45 −2 Original line number Diff line number Diff line Loading @@ -154,15 +154,47 @@ function usage_data_views_data() { if (!empty($activePlugins = $usageTypeManager->getActiveDefinitions())) { foreach ($activePlugins as $id => $definition) { $class = $definition['class']; $label = $definition['label']; $tableName = $usageDataDatabaseStorage->tableName($id); $data[$tableName]['table'] = [ 'group' => t('Usage Data'), 'provider' => 'usage_data', 'base' => [ 'title' => t('Usage Data: @label', ['@label' => $label]), 'help' => t('Usage Data table query for @label tracking.', ['@label' => $label]), 'query_id' => 'usage_data_query', ], ]; $default_schema = $usageDataDatabaseStorage->defaultSchema()['fields'] ?? []; $custom_schema = $class::schema()['fields'] ?? []; $schema = array_merge($default_schema, $custom_schema); foreach ($schema as $field_name => $field_definitions) { $data[$tableName][$field_name] = [ 'title' => $field_definitions['views_field_label'] ?? $field_name, 'help' => $field_definitions['description'] ?? $field_name, 'field' => [ 'id' => $field_definitions['views_field_type'] ?? 'standard', ], 'sort' => [ 'id' => $field_definitions['views_sort_type'] ?? 'standard', ], 'filter' => [ 'id' => $field_definitions['views_filter_type'] ?? 'standard', ], 'argument' => [ 'id' => $field_definitions['views_argument_type'] ?? 'standard', ], ]; } if (!defined("$class::ENTITY_TYPES") || empty($class::ENTITY_TYPES)) { continue; } $entityTypes = $class::ENTITY_TYPES; $eventTypes = $class::eventTypes(); $label = $definition['label']; $description = $definition['description']; $isCounter = defined("$class::COUNTER_FIELD_NAME") && !empty($class::COUNTER_FIELD_NAME); $tableName = $usageDataDatabaseStorage->tableName($id); foreach ($entityTypes as $entityTypeId) { if ($entityTypeManager->hasDefinition($entityTypeId)) { Loading @@ -170,6 +202,17 @@ function usage_data_views_data() { $table = $entityType->getBaseTable(); $entity_key = $entityType->getKey('id'); $data[$tableName]['entity_id_' . $table] = [ 'title' => $entityType->getLabel(), 'relationship' => [ 'id' => 'standard', 'label' => $entityType->getLabel(), 'base' => $table, 'base field' => $entity_key, 'real field' => 'entity_id', ], ]; foreach ($eventTypes as $event) { $title = t('Usage Data: @type counter for @label', [ '@label' => $label, Loading