You are here

function yandex_metrics_reports_report in Yandex.Metrics 8.3

Same name and namespace in other branches
  1. 6.2 yandex_metrics_reports/yandex_metrics_reports.module \yandex_metrics_reports_report()
  2. 7.3 yandex_metrics_reports/yandex_metrics_reports.module \yandex_metrics_reports_report()
  3. 7.2 yandex_metrics_reports/yandex_metrics_reports.module \yandex_metrics_reports_report()

Menu callback; displays a Summary page containing reports and charts.

1 string reference to 'yandex_metrics_reports_report'
yandex_metrics_reports_menu in yandex_metrics_reports/yandex_metrics_reports.module
Implements hook_menu().

File

yandex_metrics_reports/yandex_metrics_reports.module, line 195
The main code of Yandex.Metrics Reports module.

Code

function yandex_metrics_reports_report($filter = 'week') {
  $counter_id = yandex_metrics_reports_get_counter_for_current_site();
  if (empty($counter_id)) {
    drupal_set_message(t("Couldn't get information about the counter from Yandex.Metrica. See more details in log.") . '<br/>' . t('Also, make sure that you created the counter and authorized your site at Yandex.'), 'error');
    return '';
  }
  $counter_code = variable_get('yandex_metrics_counter_code', '');
  if (empty($counter_code)) {
    drupal_set_message(t('Perhaps you have not yet placed Yandex.Metrica counter code on the site. You can do this !link.', array(
      '!link' => l(t('here'), 'admin/config/system/yandex_metrics'),
    )), 'notice');
  }
  $authorisation_token = yandex_services_auth_info('token');
  if (empty($authorisation_token)) {
    drupal_set_message(t('Please make sure that your application is authorized !link.', array(
      '!link' => l(t('here'), 'admin/config/system/yandex_services_auth'),
    )), 'error');
    return '';
  }
  drupal_add_css(drupal_get_path('module', 'yandex_metrics_reports') . '/css/yandex_metrics_reports.css');
  $output = '';
  $form = drupal_get_form('yandex_metrics_reports_filter_form');
  $output .= drupal_render($form);
  $reports = yandex_metrics_reports_get_active_list();
  $output .= '<input type="hidden" id="yandex_metrics_reports_counter_id" value="' . $counter_id . '" />';
  $output .= '<input type="hidden" id="yandex_metrics_reports_filter" value="' . $filter . '" />';
  foreach ($reports as $report_name => $report_data) {
    $type = 'yandex_metrics_reports_' . $report_name;
    $report_content = yandex_metrics_reports_render_report($counter_id, $filter, $report_name);
    $output .= "<div class=\"yandex_metrics_reports-report\" id=\"{$type}\">";
    $output .= $report_content . '</div>';
  }
  return $output;
}