You are here

function piwik_reports_evolution in Piwik Web Analytics 6

1 string reference to 'piwik_reports_evolution'
piwik_reports_menu in modules/piwik_reports/piwik_reports.module
Implementation of hook_menu().

File

modules/piwik_reports/piwik_reports.pages.inc, line 516
Drupal Module: Piwik Reports

Code

function piwik_reports_evolution() {
  global $user;

  // Get basic configuration variables.
  $piwik_url = variable_get('piwik_url_http', '');
  $piwik_site_id = variable_get('piwik_site_id', '');
  $piwik_auth = $user->piwik['piwik_token_auth'];
  $period = $_SESSION['piwik_reports_period'];
  $now = _piwik_reports_select_period(0);
  if ($period == 1) {

    // Special handling for "yesterday" = 1.
    // Set yesterday date value for "from" and "to" date.
    $date = _piwik_reports_select_period($period);
    $now = $date;
  }
  else {

    // Otherwise it returns the start date value.
    $date = _piwik_reports_select_period($period);
  }
  $period_name = _piwik_reports_get_period_name($period);

  // Granuarity of measuring points in graph.
  switch ($period_name) {
    case 4:
      $period_name = "week";
      break;
    default:
      $period_name = "day";
  }

  // Create an array of data URL parameters for easier maintenance.
  $data1_params = array();
  $data1_params['module'] = 'Referers';
  $data1_params['action'] = 'getRefererType';
  $data1_params['columns[]'] = 'nb_visits';
  $data1_params['moduleToWidgetize'] = 'Referers';
  $data1_params['actionToWidgetize'] = 'getRefererType';
  $data1_params['idSite'] = $piwik_site_id;
  $data1_params['period'] = $period_name;
  $data1_params['date'] = $date . ',' . $now;
  $data1_params['viewDataTable'] = 'generateDataChartEvolution';
  $data1_params['loading'] = t('Loading data...');
  if (!empty($piwik_auth)) {
    $data1_params['token_auth'] = $piwik_auth;
  }

  // Build the data URL with all params and urlencode it.
  // Note: drupal_urlencode() doesn't work with Flash variables!
  $data1_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data1_params));
  $form = piwik_reports_dateselect_form();
  $output = theme('referers_evolution', $piwik_url, $data1_url);
  $form['content'] = array(
    '#type' => 'markup',
    '#value' => $output,
  );
  return $form;
}