class PaymentTurnoverSensorPlugin in Monitoring 8
Monitors payment turnover stats.
A custom database query is used here instead of entity manager for performance reasons.
Plugin annotation
@SensorPlugin(
id = "payment_turnover",
label = @Translation("Payment Turnover"),
description = @Translation("Monitors how much money was transferred for payments with effective date."),
provider = "payment",
addable = TRUE
)
Hierarchy
- class \Drupal\monitoring\SensorPlugin\SensorPluginBase implements SensorPluginInterface uses MessengerTrait, StringTranslationTrait
- class \Drupal\monitoring\SensorPlugin\DatabaseAggregatorSensorPluginBase
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ContentEntityAggregatorSensorPlugin implements ExtendedInfoSensorPluginInterface uses DependencySerializationTrait, DependencyTrait
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\PaymentTurnoverSensorPlugin
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ContentEntityAggregatorSensorPlugin implements ExtendedInfoSensorPluginInterface uses DependencySerializationTrait, DependencyTrait
- class \Drupal\monitoring\SensorPlugin\DatabaseAggregatorSensorPluginBase
Expanded class hierarchy of PaymentTurnoverSensorPlugin
File
- src/
Plugin/ monitoring/ SensorPlugin/ PaymentTurnoverSensorPlugin.php, line 26 - Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\SensorPaymentTurnover.
Namespace
Drupal\monitoring\Plugin\monitoring\SensorPluginView source
class PaymentTurnoverSensorPlugin extends ContentEntityAggregatorSensorPlugin {
/**
* {@inheritdoc}
*/
protected $configurableEntityType = FALSE;
/**
* {@inheritdoc}
*/
protected $configurableTimestampField = FALSE;
/**
* {@inheritdoc}
*/
public function runSensor(SensorResultInterface $sensor_result) {
// @todo This will not perform for large number of payments.
// @todo Use a condition for the currency when available again.
$ids = $this
->getEntityQuery()
->execute();
$entity_type_id = $this->sensorConfig
->getSetting('entity_type');
$payments = $this->entityTypeManager
->getStorage($entity_type_id)
->loadMultiple($ids);
$turnover = 0;
foreach ($payments as $payment) {
foreach ($payment
->getLineItems() as $line_item) {
// @todo Add a form for this setting.
if ($line_item
->getCurrencyCode() == $this->sensorConfig
->getSetting('currency_code')) {
$turnover += $line_item
->getAmount();
}
}
}
$sensor_result
->setValue($turnover);
}
/**
* {@inheritdoc}
*/
public function getDefaultConfiguration() {
$default_config = array(
'settings' => array(
'entity_type' => 'payment',
),
);
return $default_config;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentEntityAggregatorSensorPlugin:: |
protected | property | Local variable to store the field that is used as aggregate. | |
ContentEntityAggregatorSensorPlugin:: |
protected | property | The entity field manager. | |
ContentEntityAggregatorSensorPlugin:: |
protected | property | Local variable to store \Drupal::entityTypeManger(). | |
ContentEntityAggregatorSensorPlugin:: |
protected | function | Add aggregation to the query. | |
ContentEntityAggregatorSensorPlugin:: |
public | function | Adds sensor to entity when 'Add another condition' button is pressed. | |
ContentEntityAggregatorSensorPlugin:: |
public | function | Adds sensor to entity when 'Add another field' button is pressed. | |
ContentEntityAggregatorSensorPlugin:: |
public | function |
Adds UI for variables entity_type, conditions and verbose_fields. Overrides DatabaseAggregatorSensorPluginBase:: |
1 |
ContentEntityAggregatorSensorPlugin:: |
public | function |
Calculates dependencies for the configured plugin. Overrides SensorPluginBase:: |
|
ContentEntityAggregatorSensorPlugin:: |
public | function | Returns the updated 'conditions' fieldset for replacement by ajax. | |
ContentEntityAggregatorSensorPlugin:: |
public static | function |
Creates an instance of the sensor with config. Overrides SensorPluginBase:: |
1 |
ContentEntityAggregatorSensorPlugin:: |
public | function | Returns the updated 'verbose_fields' fieldset for replacement by ajax. | |
ContentEntityAggregatorSensorPlugin:: |
protected | function | Builds the entity query for verbose output. | |
ContentEntityAggregatorSensorPlugin:: |
protected | function | Builds the entity aggregate query. | 1 |
ContentEntityAggregatorSensorPlugin:: |
public | function |
Provide additional info about sensor call. Overrides ExtendedInfoSensorPluginInterface:: |
|
ContentEntityAggregatorSensorPlugin:: |
public | function |
Form submission handler. Overrides DatabaseAggregatorSensorPluginBase:: |
|
ContentEntityAggregatorSensorPlugin:: |
public | function |
Form validation handler. Overrides SensorPluginBase:: |
|
ContentEntityAggregatorSensorPlugin:: |
public | function | Adds unaggregated verbose output to the render array $output. | |
ContentEntityAggregatorSensorPlugin:: |
public | function |
Instantiates a sensor object. Overrides SensorPluginBase:: |
1 |
DatabaseAggregatorSensorPluginBase:: |
protected | property |
Allows plugins to control if the value type can be configured. Overrides SensorPluginBase:: |
|
DatabaseAggregatorSensorPluginBase:: |
protected | function | Gets conditions to be used in the select query. | |
DatabaseAggregatorSensorPluginBase:: |
protected | function | Gets the time field. | |
DatabaseAggregatorSensorPluginBase:: |
protected | function | Returns time interval options. | |
DatabaseAggregatorSensorPluginBase:: |
protected | function | Gets the time interval value. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DependencyTrait:: |
protected | property | The object's dependencies. | |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PaymentTurnoverSensorPlugin:: |
protected | property |
Allows plugins to control if the entity type can be configured. Overrides ContentEntityAggregatorSensorPlugin:: |
|
PaymentTurnoverSensorPlugin:: |
protected | property |
Allows plugins to control if a timestamp field can be configured. Overrides DatabaseAggregatorSensorPluginBase:: |
|
PaymentTurnoverSensorPlugin:: |
public | function |
Default configuration for a sensor. Overrides ContentEntityAggregatorSensorPlugin:: |
|
PaymentTurnoverSensorPlugin:: |
public | function |
Runs the sensor, updating $sensor_result. Overrides ContentEntityAggregatorSensorPlugin:: |
|
SensorPluginBase:: |
protected | property | The plugin implementation definition. | |
SensorPluginBase:: |
protected | property | The plugin_id. | |
SensorPluginBase:: |
protected | property | Current sensor config object. | |
SensorPluginBase:: |
protected | property | ||
SensorPluginBase:: |
public | function |
Service setter. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Configurable value type. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets sensor name (not the label). Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
@todo: Replace with injection Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Determines if sensor is enabled. Overrides SensorPluginInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |