You are here

function simplenews_statistics_handler_opens::render in Simplenews Statistics 7.2

Same name and namespace in other branches
  1. 7 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 61
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']);
  if (!($nid = $this
    ->get_value($values, 'nid'))) {
    return;
  }
  $sent_count = simplenews_issue_sent_count('node', node_load($nid));
  if ($field == 'total_opens') {
    $open_count = simplenews_statistics_count_opens($nid);
  }
  else {
    $open_count = simplenews_statistics_count_opens($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;
}