class SendActivityDestinationBase in Open Social 8
Same name and namespace in other branches
- 8.9 modules/custom/activity_send/src/Plugin/SendActivityDestinationBase.php \Drupal\activity_send\Plugin\SendActivityDestinationBase
- 8.2 modules/custom/activity_send/src/Plugin/SendActivityDestinationBase.php \Drupal\activity_send\Plugin\SendActivityDestinationBase
- 8.3 modules/custom/activity_send/src/Plugin/SendActivityDestinationBase.php \Drupal\activity_send\Plugin\SendActivityDestinationBase
- 8.4 modules/custom/activity_send/src/Plugin/SendActivityDestinationBase.php \Drupal\activity_send\Plugin\SendActivityDestinationBase
- 8.5 modules/custom/activity_send/src/Plugin/SendActivityDestinationBase.php \Drupal\activity_send\Plugin\SendActivityDestinationBase
- 8.6 modules/custom/activity_send/src/Plugin/SendActivityDestinationBase.php \Drupal\activity_send\Plugin\SendActivityDestinationBase
- 8.7 modules/custom/activity_send/src/Plugin/SendActivityDestinationBase.php \Drupal\activity_send\Plugin\SendActivityDestinationBase
- 8.8 modules/custom/activity_send/src/Plugin/SendActivityDestinationBase.php \Drupal\activity_send\Plugin\SendActivityDestinationBase
- 10.3.x modules/custom/activity_send/src/Plugin/SendActivityDestinationBase.php \Drupal\activity_send\Plugin\SendActivityDestinationBase
- 10.0.x modules/custom/activity_send/src/Plugin/SendActivityDestinationBase.php \Drupal\activity_send\Plugin\SendActivityDestinationBase
- 10.1.x modules/custom/activity_send/src/Plugin/SendActivityDestinationBase.php \Drupal\activity_send\Plugin\SendActivityDestinationBase
- 10.2.x modules/custom/activity_send/src/Plugin/SendActivityDestinationBase.php \Drupal\activity_send\Plugin\SendActivityDestinationBase
Base class for Activity send destination plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\activity_creator\Plugin\ActivityDestinationBase implements ActivityDestinationInterface
- class \Drupal\activity_send\Plugin\SendActivityDestinationBase
- class \Drupal\activity_creator\Plugin\ActivityDestinationBase implements ActivityDestinationInterface
Expanded class hierarchy of SendActivityDestinationBase
1 file declares its use of SendActivityDestinationBase
- EmailActivityDestination.php in modules/
custom/ activity_send/ modules/ activity_send_email/ src/ Plugin/ ActivityDestination/ EmailActivityDestination.php
File
- modules/
custom/ activity_send/ src/ Plugin/ SendActivityDestinationBase.php, line 10
Namespace
Drupal\activity_send\PluginView source
class SendActivityDestinationBase extends ActivityDestinationBase {
/**
* Returns message templates for which given destination is enabled.
*/
public static function getSendMessageTemplates($destination) {
$email_message_templates = [];
/** @var \Drupal\message\MessageTemplateInterface[] $message_templates */
$message_templates = \Drupal::entityTypeManager()
->getStorage('message_template')
->loadMultiple();
foreach ($message_templates as $message_template) {
$destinations = $message_template
->getThirdPartySetting('activity_logger', 'activity_destinations', NULL);
if (is_array($destinations) && in_array($destination, $destinations)) {
$email_message_templates[$message_template
->id()] = $message_template
->getDescription();
}
}
return $email_message_templates;
}
/**
* Returns notification settings of given user.
*/
public static function getSendUserSettings($destination, $account) {
$query = \Drupal::database()
->select('user_activity_send', 'uas');
$query
->fields('uas', [
'message_template',
'frequency',
]);
$query
->condition('uas.uid', $account
->id());
$query
->condition('uas.destination', $destination);
return $query
->execute()
->fetchAllKeyed();
}
/**
* Set notification settings for given user.
*/
public static function setSendUserSettings($destination, $account, $values) {
if (is_object($account) && !empty($values)) {
foreach ($values as $message_template => $frequency) {
$query = \Drupal::database()
->merge('user_activity_send');
$query
->fields([
'uid' => $account
->id(),
'destination' => $destination,
'message_template' => $message_template,
'frequency' => $frequency,
]);
$query
->keys([
'uid' => $account
->id(),
'destination' => $destination,
'message_template' => $message_template,
]);
$query
->execute();
}
}
}
/**
* Returns target account.
*/
public static function getSendTargetUser($activity) {
// Get target account.
if (isset($activity->field_activity_recipient_user) && !empty($activity->field_activity_recipient_user->target_id)) {
$target_id = $activity->field_activity_recipient_user->target_id;
$target_account = \Drupal::entityTypeManager()
->getStorage('user')
->load($target_id);
return $target_account;
}
}
/**
* Check if user last activity was more than few minutes ago.
*/
public static function isUserOffline($account) {
$query = \Drupal::database()
->select('sessions', 's');
$query
->addField('s', 'timestamp');
$query
->condition('s.uid', $account
->id());
$last_activity_time = $query
->execute()
->fetchField();
$offline_window = \Drupal::config('activity_send.settings')
->get('activity_send_offline_window');
$current_time = \Drupal::time()
->getRequestTime() - $offline_window;
return empty($last_activity_time) || $last_activity_time < $current_time;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ActivityDestinationBase:: |
public | function |
Returns a view mode for the entity. Overrides ActivityDestinationInterface:: |
|
ActivityDestinationBase:: |
public | function |
True or false if the activity destination is set. Overrides ActivityDestinationInterface:: |
|
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. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
SendActivityDestinationBase:: |
public static | function | Returns message templates for which given destination is enabled. | |
SendActivityDestinationBase:: |
public static | function | Returns target account. | |
SendActivityDestinationBase:: |
public static | function | Returns notification settings of given user. | |
SendActivityDestinationBase:: |
public static | function | Check if user last activity was more than few minutes ago. | |
SendActivityDestinationBase:: |
public static | function | Set notification settings for given user. |