You are here

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

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\SensorPlugin
View 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

Namesort descending Modifiers Type Description Overrides
ContentEntityAggregatorSensorPlugin::$aggregateField protected property Local variable to store the field that is used as aggregate.
ContentEntityAggregatorSensorPlugin::$entityFieldManager protected property The entity field manager.
ContentEntityAggregatorSensorPlugin::$entityTypeManager protected property Local variable to store \Drupal::entityTypeManger().
ContentEntityAggregatorSensorPlugin::addAggregate protected function Add aggregation to the query.
ContentEntityAggregatorSensorPlugin::addConditionSubmit public function Adds sensor to entity when 'Add another condition' button is pressed.
ContentEntityAggregatorSensorPlugin::addFieldSubmit public function Adds sensor to entity when 'Add another field' button is pressed.
ContentEntityAggregatorSensorPlugin::buildConfigurationForm public function Adds UI for variables entity_type, conditions and verbose_fields. Overrides DatabaseAggregatorSensorPluginBase::buildConfigurationForm 1
ContentEntityAggregatorSensorPlugin::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides SensorPluginBase::calculateDependencies
ContentEntityAggregatorSensorPlugin::conditionsReplace public function Returns the updated 'conditions' fieldset for replacement by ajax.
ContentEntityAggregatorSensorPlugin::create public static function Creates an instance of the sensor with config. Overrides SensorPluginBase::create 1
ContentEntityAggregatorSensorPlugin::fieldsReplace public function Returns the updated 'verbose_fields' fieldset for replacement by ajax.
ContentEntityAggregatorSensorPlugin::getEntityQuery protected function Builds the entity query for verbose output.
ContentEntityAggregatorSensorPlugin::getEntityQueryAggregate protected function Builds the entity aggregate query. 1
ContentEntityAggregatorSensorPlugin::resultVerbose public function Provide additional info about sensor call. Overrides ExtendedInfoSensorPluginInterface::resultVerbose
ContentEntityAggregatorSensorPlugin::submitConfigurationForm public function Form submission handler. Overrides DatabaseAggregatorSensorPluginBase::submitConfigurationForm
ContentEntityAggregatorSensorPlugin::validateConfigurationForm public function Form validation handler. Overrides SensorPluginBase::validateConfigurationForm
ContentEntityAggregatorSensorPlugin::verboseResultUnaggregated public function Adds unaggregated verbose output to the render array $output.
ContentEntityAggregatorSensorPlugin::__construct public function Instantiates a sensor object. Overrides SensorPluginBase::__construct 1
DatabaseAggregatorSensorPluginBase::$configurableValueType protected property Allows plugins to control if the value type can be configured. Overrides SensorPluginBase::$configurableValueType
DatabaseAggregatorSensorPluginBase::getConditions protected function Gets conditions to be used in the select query.
DatabaseAggregatorSensorPluginBase::getTimeIntervalField protected function Gets the time field.
DatabaseAggregatorSensorPluginBase::getTimeIntervalOptions protected function Returns time interval options.
DatabaseAggregatorSensorPluginBase::getTimeIntervalValue protected function Gets the time interval value.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DependencyTrait::$dependencies protected property The object's dependencies.
DependencyTrait::addDependencies protected function Adds multiple dependencies.
DependencyTrait::addDependency protected function Adds a dependency.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PaymentTurnoverSensorPlugin::$configurableEntityType protected property Allows plugins to control if the entity type can be configured. Overrides ContentEntityAggregatorSensorPlugin::$configurableEntityType
PaymentTurnoverSensorPlugin::$configurableTimestampField protected property Allows plugins to control if a timestamp field can be configured. Overrides DatabaseAggregatorSensorPluginBase::$configurableTimestampField
PaymentTurnoverSensorPlugin::getDefaultConfiguration public function Default configuration for a sensor. Overrides ContentEntityAggregatorSensorPlugin::getDefaultConfiguration
PaymentTurnoverSensorPlugin::runSensor public function Runs the sensor, updating $sensor_result. Overrides ContentEntityAggregatorSensorPlugin::runSensor
SensorPluginBase::$pluginDefinition protected property The plugin implementation definition.
SensorPluginBase::$pluginId protected property The plugin_id.
SensorPluginBase::$sensorConfig protected property Current sensor config object.
SensorPluginBase::$services protected property
SensorPluginBase::addService public function Service setter. Overrides SensorPluginInterface::addService
SensorPluginBase::getConfigurableValueType public function Configurable value type. Overrides SensorPluginInterface::getConfigurableValueType
SensorPluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
SensorPluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
SensorPluginBase::getSensorId public function Gets sensor name (not the label). Overrides SensorPluginInterface::getSensorId
SensorPluginBase::getService public function @todo: Replace with injection Overrides SensorPluginInterface::getService
SensorPluginBase::isEnabled public function Determines if sensor is enabled. Overrides SensorPluginInterface::isEnabled
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.