You are here

function simplenews_statistics_handler_opens::render in Simplenews Statistics 7

Same name and namespace in other branches
  1. 7.2 includes/views/handlers/simplenews_statistics_handler_opens.inc \simplenews_statistics_handler_opens::render()

Renders the field handler.

Overrides views_handler_field::render

File

includes/views/handlers/simplenews_statistics_handler_opens.inc, line 66
Definition of simplenews_statistics_handler_opens.

Class

simplenews_statistics_handler_opens
Description.

Code

function render($values) {
  $field = $this->real_field;
  $precision = intval($this->options['open_rate_precision']);
  $sent_count = $values->simplenews_newsletter_sent_subscriber_count;
  if ($field == 'total_opens') {
    $open_count = simplenews_statistics_count_opens($values->nid);
  }
  else {
    $open_count = simplenews_statistics_count_opens($values->nid, TRUE);
  }
  if ($field == 'open_rate' && $sent_count > 0) {
    return round($open_count / $sent_count * 100, $precision) . '%';
  }
  elseif ($field == 'open_rate' && $sent_count == 0) {
    return t('N/A');
  }
  return $open_count;
}