You are here

function forward_tracking in Forward 7.2

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

Callback function for the Forward Tracking Page

1 string reference to 'forward_tracking'
forward_menu in ./forward.module
Implements hook_menu().

File

./forward.module, line 1174

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>' . t('Most Forwarded Nodes') . '</h2>',
  );
  $rows = array();
  $header = array(
    array(
      'data' => t('Title'),
    ),
    array(
      'data' => t('Path'),
    ),
    array(
      'data' => t('Forwards'),
    ),
    array(
      'data' => t('Clickthroughs'),
    ),
  );
  $query = db_select('forward_statistics', 'f', array(
    'target' => 'slave',
  ))
    ->extend('PagerDefault')
    ->element(0);
  $query
    ->innerJoin('node', 'n', 'f.nid = n.nid');
  $query
    ->fields('f', array(
    'nid',
    'last_forward_timestamp',
    'forward_count',
    'clickthrough_count',
  ))
    ->fields('n', array(
    'title',
  ))
    ->limit(10)
    ->orderBy('f.forward_count', 'DESC');
  $result = $query
    ->execute();
  $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',
    '#element' => 0,
  );

  /**
   * Most Clickthroughs
   */
  $output['forward_clickthroughs_heading'] = array(
    '#markup' => '<h2>' . t('Most Clickthroughs To Nodes') . '</h2>',
  );
  $rows = array();
  $header = array(
    array(
      'data' => t('Title'),
    ),
    array(
      'data' => t('Path'),
    ),
    array(
      'data' => t('Forwards'),
    ),
    array(
      'data' => t('Clickthroughs'),
    ),
  );
  $query = db_select('forward_statistics', 'f', array(
    'target' => 'slave',
  ))
    ->extend('PagerDefault')
    ->element(1);
  $query
    ->innerJoin('node', 'n', 'f.nid = n.nid');
  $query
    ->fields('f', array(
    'nid',
    'last_forward_timestamp',
    'forward_count',
    'clickthrough_count',
  ))
    ->fields('n', array(
    'title',
  ))
    ->limit(10)
    ->orderBy('f.clickthrough_count', 'DESC');
  $result = $query
    ->execute();
  $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',
    '#element' => 1,
  );

  /**
   * Recently Forwarded Pages
   */
  $output['forward_recent_heading'] = array(
    '#markup' => '<h2>' . t('Recent Forward Activity') . '</h2><p>' . t('SENT = email sent, REF = email clickthrough') . '</p>',
  );
  $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')
    ->element(2);
  $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',
    '#element' => 2,
  );
  drupal_set_title(t('Forward Tracking'));
  return $output;
}