You are here

function mandrill_reports_dashboard_page in Mandrill 7

Same name and namespace in other branches
  1. 7.2 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 118
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'],
    );
  }

  // Url table.
  $rows = array();
  $header = array(
    t('URL'),
    t('Delivered'),
    t('Unique clicks'),
    t('Total Clicks'),
  );
  foreach ($data['urls'] as $url) {
    $percent = number_format($url['unique_clicks'] / $url['sent'], 2) * 100;
    $rows[] = array(
      l($url['url'], $url['url']),
      $url['sent'],
      $url['unique_clicks'] . "({$percent}%)",
      $url['clicks'],
    );
  }
  $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>',
    ),
    'urls' => array(
      '#prefix' => '<h2>' . t('Tracked URLs') . '</h2>',
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $rows,
    ),
  );
  return $render;
}