You are here

function forward_tracking in Forward 7

Same name and namespace in other branches
  1. 5 forward.module \forward_tracking()
  2. 6 forward.module \forward_tracking()
  3. 7.2 forward.module \forward_tracking()

Forward Tracking Page

1 string reference to 'forward_tracking'
forward_menu in ./forward.module
Menu Hooks

File

./forward.module, line 1315

Code

function forward_tracking() {
  $output = array();
  $output['forward_totals'] = array(
    '#markup' => '<p><strong>' . variable_get('forward_total', 0) . '</strong> ' . t('emails sent to') . ' <strong>' . variable_get('forward_recipients', 0) . '</strong> ' . t('recipients') . '</p>',
  );

  /**
   * Most Forwarded Nodes
   */
  $output['forward_most_heading'] = array(
    '#markup' => '<h2>Most Forwarded Nodes</h2>',
  );
  $rows = array();
  $header = array(
    array(
      'data' => t('Title'),
    ),
    array(
      'data' => t('Path'),
    ),
    array(
      'data' => t('Forwards'),
    ),
    array(
      'data' => t('Clickthroughs'),
    ),
  );
  $result = db_query_range('SELECT n.title, f.* FROM {forward_statistics} f LEFT JOIN {node} n ON f.nid = n.nid ORDER BY f.forward_count DESC', 0, 10);
  $num_rows = FALSE;
  foreach ($result as $log) {
    $num_rows = TRUE;
    $_path = drupal_get_path_alias('node/' . $log->nid);
    $title = $log->nid ? $log->title : 'Front Page';
    $rows[] = array(
      l(_forward_column_width($title), $_path),
      l($_path, $_path),
      $log->forward_count,
      $log->clickthrough_count,
    );
  }
  $output['forward_most_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No statistics available.'),
  );
  $output['forward_most_pager'] = array(
    '#theme' => 'pager',
  );

  /**
   * Most Clickthroughs
   */
  $output['forward_clickthroughs_heading'] = array(
    '#markup' => '<h2>Most Clickthroughs (nodes only)</h2>',
  );
  $rows = array();
  $header = array(
    array(
      'data' => t('Title'),
    ),
    array(
      'data' => t('Path'),
    ),
    array(
      'data' => t('Forwards'),
    ),
    array(
      'data' => t('Clickthroughs'),
    ),
  );
  $result = db_query_range('SELECT n.title, f.* FROM {forward_statistics} f LEFT JOIN {node} n ON f.nid = n.nid ORDER BY f.clickthrough_count DESC', 0, 10);
  $num_rows = FALSE;
  foreach ($result as $log) {
    $num_rows = TRUE;
    $_path = drupal_get_path_alias('node/' . $log->nid);
    $title = $log->nid ? $log->title : 'Front Page';
    $rows[] = array(
      l(_forward_column_width($title), $_path),
      l($_path, $_path),
      $log->forward_count,
      $log->clickthrough_count,
    );
  }
  $output['forward_clickthroughs_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No statistics available.'),
  );
  $output['forward_clickthroughs_pager'] = array(
    '#theme' => 'pager',
  );

  /**
   * Recently Forwarded Pages
   */
  $output['forward_recent_heading'] = array(
    '#markup' => '<h2>Recently Forwarded Pages</h2>',
  );
  $rows = array();
  $header = array(
    array(
      'data' => t('Time'),
      'field' => 'timestamp',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Type'),
      'field' => 'type',
    ),
    array(
      'data' => t('Path'),
      'field' => 'path',
    ),
    array(
      'data' => t('User ID'),
      'field' => 'uid',
    ),
    array(
      'data' => t('Hostname'),
      'field' => 'hostname',
    ),
  );
  $query = db_select('forward_log', 'f', array(
    'target' => 'slave',
  ))
    ->extend('PagerDefault')
    ->extend('TableSort');
  $query
    ->innerJoin('users', 'u', 'f.uid = u.uid');
  $query
    ->fields('f', array(
    'timestamp',
    'type',
    'path',
    'uid',
    'hostname',
  ))
    ->fields('u', array(
    'name',
  ))
    ->limit(30)
    ->orderByHeader($header);
  $result = $query
    ->execute();
  $num_rows = FALSE;
  foreach ($result as $log) {
    $num_rows = TRUE;
    $_path = drupal_get_path_alias($log->path);
    $rows[] = array(
      array(
        'data' => format_date($log->timestamp, 'short'),
        'nowrap' => 'nowrap',
      ),
      $log->type,
      l($_path, $_path),
      l($log->name, 'user/' . $log->uid),
      $log->hostname,
    );
  }
  $output['forward_recent_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No statistics available.'),
  );
  $output['forward_recent_pager'] = array(
    '#theme' => 'pager',
  );

  // TODO Please change this theme call as discussed at http://drupal.org/node/224333#theme_page.
  // print theme('page', $output);
  drupal_set_title(t('Forward Tracking'));
  return $output;
}