simplenews_statistics_handler_opens.inc in Simplenews Statistics 7.2
Same filename and directory in other branches
Definition of simplenews_statistics_handler_opens.
File
includes/views/handlers/simplenews_statistics_handler_opens.incView source
<?php
/**
* @file
* Definition of simplenews_statistics_handler_opens.
*/
/**
* Description.
*/
class simplenews_statistics_handler_opens extends views_handler_field {
/**
* Add some required fields needed on render().
*/
function construct() {
parent::construct();
$this->additional_fields['nid'] = array(
'table' => 'simplenews_statistics',
'field' => 'nid',
);
}
/**
* Loads additional fields.
*/
function query() {
$this
->ensure_my_table();
$this
->add_additional_fields();
}
/**
* Default options form.
*/
function option_definition() {
$options = parent::option_definition();
$options['open_rate_precision'] = array(
'default' => '0',
);
return $options;
}
/**
* Creates the form item for the options added.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
if ($this->real_field == 'open_rate') {
$form['open_rate_precision'] = array(
'#type' => 'textfield',
'#title' => t('Precision'),
'#default_value' => $this->options['open_rate_precision'],
'#description' => t('Number of decimal places to which the open rate should be calculated.'),
);
}
}
/**
* Renders the field handler.
*/
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;
}
}
Classes
Name![]() |
Description |
---|---|
simplenews_statistics_handler_opens | Description. |