You are here

function yandex_metrics_reports_popular_content in Yandex.Metrics 8.2

Same name and namespace in other branches
  1. 8.3 yandex_metrics_reports/yandex_metrics_reports.reports.inc \yandex_metrics_reports_popular_content()
  2. 7.3 yandex_metrics_reports/yandex_metrics_reports.reports.inc \yandex_metrics_reports_popular_content()
  3. 7.2 yandex_metrics_reports/yandex_metrics_reports.reports.inc \yandex_metrics_reports_popular_content()

The function generates the table of popular content.

Parameters

string $counter_id:

string $filter:

3 string references to 'yandex_metrics_reports_popular_content'
views_handler_field_ym_title::init in yandex_metrics_reports/views/handlers/views_handler_field_ym_title.inc
yandex_metrics_reports_views_default_views in yandex_metrics_reports/views/yandex_metrics_reports.views.inc
Implements hook_views_default_views().
yandex_metrics_reports_yandex_metrics_reports_list in yandex_metrics_reports/yandex_metrics_reports.module
Implements hook_yandex_metrics_reports_list().

File

yandex_metrics_reports/yandex_metrics_reports.reports.inc, line 216
Report callbacks for Yandex.Metrics Reports module.

Code

function yandex_metrics_reports_popular_content($counter_id, $filter) {
  $output = '';
  $date_range = _yandex_metrics_reports_filter_to_date_range($filter);
  $parameters = array(
    'id' => $counter_id,
    'date1' => $date_range['start_date'],
    'date2' => $date_range['end_date'],
  );
  $report_content = yandex_metrics_reports_retreive_data('/stat/content/popular', $parameters);
  $content = json_decode($report_content
    ->getBody(TRUE));
  if (empty($content->data)) {
    return t('There is no information about popular content for the selected date range.');
  }
  $header = array(
    t('URL'),
    t('Page Views'),
  );
  $data = array();
  $i = 1;
  foreach ($content->data as $value) {
    if ($i > YANDEX_METRICS_REPORTS_POPULAR_CONTENT_COUNT) {
      break;
    }
    $page_views = (int) $value->page_views;
    $data[] = array(
      l($value->url, $value->url, array(
        'attributes' => array(
          'target' => '_blank',
        ),
      )),
      $page_views,
    );
    $i++;
  }
  return theme('table', array(
    'header' => $header,
    'rows' => $data,
    'caption' => t("Popular Content"),
  ));
}