You are here

function piwik_reports_overview in Piwik Reports 6

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

File

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

Code

function piwik_reports_overview() {
  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);
  }

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

  // Create an array of URL parameters for easier maintenance.
  $data1_params = array();
  $data1_params['module'] = 'VisitsSummary';
  $data1_params['action'] = 'getEvolutionGraph';
  $data1_params['columns[]'] = 'nb_visits';
  $data1_params['moduleToWidgetize'] = 'VisitsSummary';
  $data1_params['actionToWidgetize'] = 'getEvolutionGraph';
  $data1_params['idSite'] = $piwik_site_id;
  $data1_params['period'] = $period;
  $data1_params['date'] = $date . ',' . $now;
  $data1_params['disableLink'] = 1;
  $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 here!
  $data1_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data1_params));

  // Render HTML code.
  $output = theme('visitors_overview', $piwik_url, $data1_url, $period);
  $form = piwik_reports_dateselect_form();
  $form['content'] = array(
    '#type' => 'markup',
    '#value' => $output,
  );
  return $form;
}