You are here

function mandrill_reports_dashboard_page in Mandrill 7.2

Same name and namespace in other branches
  1. 7 modules/mandrill_reports/mandrill_reports.module \mandrill_reports_dashboard_page()

Page callback for rendering stats.

Return value

array Render array.

1 string reference to 'mandrill_reports_dashboard_page'
mandrill_reports_menu in modules/mandrill_reports/mandrill_reports.module
Implements hook_menu().

File

modules/mandrill_reports/mandrill_reports.module, line 80
Main module functions for mandrill_reports.

Code

function mandrill_reports_dashboard_page() {
  $data = mandrill_reports_data();
  $settings = array();

  // All time series chart data.
  foreach ($data['all_time_series'] as $series) {
    $settings['mandrill_reports']['volume'][] = array(
      'date' => $series['time'],
      'sent' => $series['sent'],
      'bounced' => $series['hard_bounces'] + $series['soft_bounces'],
      'rejected' => $series['rejects'],
    );
    $settings['mandrill_reports']['engagement'][] = array(
      'date' => $series['time'],
      'open_rate' => $series['sent'] == 0 ? 0 : $series['unique_opens'] / $series['sent'],
      'click_rate' => $series['sent'] == 0 ? 0 : $series['unique_clicks'] / $series['sent'],
    );
  }
  $path = drupal_get_path('module', 'mandrill_reports');
  $render = array(
    '#attached' => array(
      'js' => array(
        array(
          'data' => 'https://www.google.com/jsapi',
          'type' => 'external',
        ),
        $path . '/mandrill_reports.js',
        array(
          'data' => $settings,
          'type' => 'setting',
        ),
      ),
    ),
    'message' => array(
      '#markup' => t('The following reports are based on Mandrill data from the last 30 days. For more comprehensive data, please visit your !dashboard. !cache to ensure the data is current.', array(
        '!dashboard' => l(t('Mandrill Dashboard'), 'https://mandrillapp.com/'),
        '!cache' => l(t('Clear your cache'), 'admin/config/development/performance'),
      )),
    ),
    'volume' => array(
      '#prefix' => '<h2>' . t('Sending Volume') . '</h2>',
      '#markup' => '<div id="mandrill-volume-chart"></div>',
    ),
    'engagement' => array(
      '#prefix' => '<h2>' . t('Average Open and Click Rate') . '</h2>',
      '#markup' => '<div id="mandrill-engage-chart"></div>',
    ),
  );
  return $render;
}