class SendTinCanStatement in Opigno TinCan API 8
Same name and namespace in other branches
- 3.x src/Plugin/QueueWorker/SendTinCanStatement.php \Drupal\opigno_tincan_api\Plugin\QueueWorker\SendTinCanStatement
Send TinCan Statement.
Plugin annotation
@QueueWorker(
id = "opigno_tincan_send_tincan_statement",
title = @Translation("Send TinCan Statement via queue"),
cron = {"time" = 20}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
- class \Drupal\opigno_tincan_api\Plugin\QueueWorker\SendTinCanStatement implements ContainerFactoryPluginInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
Expanded class hierarchy of SendTinCanStatement
File
- src/
Plugin/ QueueWorker/ SendTinCanStatement.php, line 19
Namespace
Drupal\opigno_tincan_api\Plugin\QueueWorkerView source
class SendTinCanStatement extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* Config factory service.
*/
protected $configFactory;
/**
* Logger system service.
*/
protected $logger;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, $config_factory, $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configFactory = $config_factory;
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'), $container
->get('logger.factory'));
}
/**
* {@inheritdoc}
*/
public function processItem($data) {
// _opigno_tincan_api_send_statement.
// The variables 'opigno_tincan_api_*'
// will be used to send the statement to the LRS.
$config = $this->configFactory
->get('opigno_tincan_api.settings');
$endpoint = $config
->get('opigno_tincan_api_endpoint');
$username = $config
->get('opigno_tincan_api_username');
$password = $config
->get('opigno_tincan_api_password');
if (empty($endpoint) || empty($username) || empty($password)) {
return FALSE;
}
$lrs = new RemoteLRS($endpoint, '1.0.1', $username, $password);
$response = $lrs
->saveStatement($data->statement);
if ($response->success === FALSE) {
$this->logger
->get('Opigno Tincan API')
->error('The following statement could not be sent :<br /><pre>' . print_r($statement
->asVersion('1.0.1'), TRUE) . '</pre><br/>', []);
return FALSE;
}
return TRUE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
SendTinCanStatement:: |
protected | property | Config factory service. | |
SendTinCanStatement:: |
protected | property | Logger system service. | |
SendTinCanStatement:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
SendTinCanStatement:: |
public | function |
Works on a single queue item. Overrides QueueWorkerInterface:: |
|
SendTinCanStatement:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |