function simplenews_statistics_count_opens in Simplenews Statistics 7
Same name and namespace in other branches
- 7.2 simplenews_statistics.module \simplenews_statistics_count_opens()
 
Get open count for the given node.
3 calls to simplenews_statistics_count_opens()
- simplenews_statistics_cron in ./
simplenews_statistics.module  - Implements hook_cron().
 - simplenews_statistics_handler_clicks::render in includes/
views/ handlers/ simplenews_statistics_handler_clicks.inc  - Renders the field handler.
 - simplenews_statistics_handler_opens::render in includes/
views/ handlers/ simplenews_statistics_handler_opens.inc  - Renders the field handler.
 
File
- ./
simplenews_statistics.module, line 398  - Main simplenews statistics file.
 
Code
function simplenews_statistics_count_opens($nid, $distinct = FALSE) {
  // Check if newsletter is archived.
  if (simplenews_statistics_is_archived($nid)) {
    // Select and return aggregated count.
    $query = db_select('simplenews_statistics', 'ss')
      ->fields('ss', array(
      'unique_opens',
      'total_opens',
    ))
      ->condition('ss.nid', $nid);
    $record = $query
      ->execute()
      ->fetchObject();
    if ($distinct) {
      return $record->unique_opens;
    }
    return $record->total_opens;
  }
  // Manual count.
  $query = db_select('simplenews_statistics_open', 'sso')
    ->condition('sso.nid', $nid);
  if ($distinct) {
    $query
      ->fields('sso', array(
      'snid',
    ))
      ->distinct();
  }
  return $query
    ->countQuery()
    ->execute()
    ->fetchField();
}