class SendGridReportsController in SendGrid Integration 8
Same name and namespace in other branches
- 8.2 modules/sendgrid_integration_reports/src/Controller/SendGridReportsController.php \Drupal\sendgrid_integration_reports\Controller\SendGridReportsController
Class for rendering sendgrid reports page.
@package Drupal\sendgrid_integration_reports\Controller
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\sendgrid_integration_reports\Controller\SendGridReportsController
Expanded class hierarchy of SendGridReportsController
File
- modules/
sendgrid_integration_reports/ src/ Controller/ SendGridReportsController.php, line 16
Namespace
Drupal\sendgrid_integration_reports\ControllerView source
class SendGridReportsController extends ControllerBase {
/**
* Include the messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Logger service.
*
* @var \Drupal\Core\Logger\LoggerChannelFactory
*/
protected $loggerFactory;
/**
* Api service.
*
* @var \Drupal\sendgrid_integration_reports\Api
*/
protected $api;
/**
* SendGridReportsController constructor.
*
* @param \Drupal\sengrid_integration_reports\Api $api
* The sendgrid api service.
*/
public function __construct(Api $api) {
$this->api = $api;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('sendgrid_integration_reports.api'));
}
/**
* Returns stats categories.
*
* @param array $categories
* Array of categories.
* @param string|null $start_date
* Start date.
* @param string|null $end_date
* End date.
* @param bool $refresh
* Flag is cache should be refreshed.
*
* @return array|bool
* Array of stats data.
*/
public function getStatsCategories(array $categories, $start_date = NULL, $end_date = NULL, $refresh = FALSE) {
$cid = 'sendgrid_reports_categories';
// Sanitize the categories array and generate the cache ID.
if ($categories && is_array($categories)) {
$categories = array_values($categories);
$cid .= '_' . implode('_', $categories);
}
else {
$categories = NULL;
}
return $this->api
->getStats($cid, $categories, $start_date, $end_date, $refresh);
}
/**
* Returns reports.
*/
public function getReports() {
$stats = $this->api
->getStats('sendgrid_reports_global');
$settings = [];
$stats['global'] = isset($stats['global']) ? $stats['global'] : [];
foreach ($stats['global'] as $items) {
$settings['global'][] = [
'date' => $items['date'],
'opens' => $items['opens'],
'clicks' => $items['clicks'],
'delivered' => $items['delivered'],
'spam_reports' => $items['spam_reports'],
'spam_report_drops' => $items['spam_report_drops'],
];
}
$render = [
'#attached' => [
'library' => [
'sendgrid_integration_reports/googlejsapi',
'sendgrid_integration_reports/main',
],
'drupalSettings' => [
'sendgrid_integration_reports' => $settings,
],
],
'message' => [
'#markup' => t('The following reports are the from the Global Statistics provided by SendGrid. For more comprehensive data, please visit your @dashboard. @cache to ensure the data is current. @settings to alter the time frame of this data.', [
'@dashboard' => Link::fromTextAndUrl(t('SendGrid Dashboard'), Url::fromUri('//app.sendgrid.com/'))
->toString(),
'@cache' => Link::createFromRoute(t('Clear your cache'), 'system.performance_settings')
->toString(),
'@settings' => Link::createFromRoute(t('Change your settings'), 'sendgrid_integration_reports.settings_form')
->toString(),
]),
],
'volume' => [
'#prefix' => '<h2>' . t('Sending Volume') . '</h2>',
'#markup' => '<div id="sendgrid-global-volume-chart"></div>',
],
'spam' => [
'#prefix' => '<h2>' . t('Spam Reports') . '</h2>',
'#markup' => '<div id="sendgrid-global-spam-chart"></div>',
],
];
$browserstats = $this->api
->getStatsBrowser();
$rows = [];
foreach ($browserstats as $key => $value) {
$rows[] = [
$key,
$value,
];
}
$headerbrowser = [
t('Browser'),
t('Click Count'),
];
$render['browsers'] = [
'#prefix' => '<h2>' . t('Browser Statistics') . '</h2>',
'#theme' => 'table',
'#header' => $headerbrowser,
'#rows' => $rows,
'attributes' => [
'width' => '75%',
],
];
$devicestats = $this->api
->getStatsDevices();
$rowsdevices = [];
foreach ($devicestats as $key => $value) {
$rowsdevices[] = [
$key,
$value,
];
}
$headerdevices = [
t('Device'),
t('Open Count'),
];
$render['devices'] = [
'#prefix' => '<h2>' . t('Device Statistics') . '</h2>',
'#theme' => 'table',
'#header' => $headerdevices,
'#rows' => $rowsdevices,
'attributes' => [
'width' => '75%',
],
];
return $render;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
SendGridReportsController:: |
protected | property | Api service. | |
SendGridReportsController:: |
protected | property |
Logger service. Overrides LoggerChannelTrait:: |
|
SendGridReportsController:: |
protected | property |
Include the messenger service. Overrides MessengerTrait:: |
|
SendGridReportsController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
SendGridReportsController:: |
public | function | Returns reports. | |
SendGridReportsController:: |
public | function | Returns stats categories. | |
SendGridReportsController:: |
public | function | SendGridReportsController constructor. | |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |