You are here

function _get_date_vs_takeup_count_chart in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 modules/quiz_stats/quiz_stats.admin.inc \_get_date_vs_takeup_count_chart()
  2. 8.4 modules/quiz_stats/quiz_stats.admin.inc \_get_date_vs_takeup_count_chart()
  3. 6.6 includes/quiz_dashboard/quiz_dashboard.admin.inc \_get_date_vs_takeup_count_chart()
  4. 6.4 includes/quiz_stats/quiz_stats.admin.inc \_get_date_vs_takeup_count_chart()
  5. 7.6 modules/quiz_stats/quiz_stats.admin.inc \_get_date_vs_takeup_count_chart()
  6. 7 includes/quiz_stats/quiz_stats.admin.inc \_get_date_vs_takeup_count_chart()
  7. 7.4 includes/quiz_stats/quiz_stats.admin.inc \_get_date_vs_takeup_count_chart()
  8. 7.5 modules/quiz_stats/quiz_stats.admin.inc \_get_date_vs_takeup_count_chart()
  9. 6.x modules/quiz_stats/quiz_stats.admin.inc \_get_date_vs_takeup_count_chart()

Generates chart showing how often the quiz has been taken the last days.

Parameters

$uid: user id.

$vid: revision id of quiz.

Return value

HTML to display chart.

1 call to _get_date_vs_takeup_count_chart()
quiz_stats_get_adv_stats in modules/quiz_stats/quiz_stats.admin.inc
Get stats for a single quiz. Maybe also for a single user.

File

modules/quiz_stats/quiz_stats.admin.inc, line 230
Administration file for Quiz stats Module.

Code

function _get_date_vs_takeup_count_chart($vid, $uid = 0) {
  $start = 0;
  $end = 30;
  $takeup = array();
  $sql = "SELECT COUNT(result_id) AS count,\n            DATE_FORMAT(FROM_UNIXTIME(time_start), '%Y-%m-%e') AS date\n            FROM {quiz_node_results}\n            WHERE vid = :vid AND time_start > (UNIX_TIMESTAMP(NOW()) - (86400*{$end}))";
  $sql_args[':vid'] = $vid;
  if ($uid != 0) {
    $sql .= " AND uid = :uid";
    $sql_args[':uid'] = $uid;
  }
  $sql .= " GROUP BY date ORDER BY time_start ASC";
  $results = db_query($sql, $sql_args);
  $res_o = $results
    ->fetchAll();
  if ($res_o) {
    $chart = '<div id="date_vs_takeup_count" class="quiz-stats-chart-space">';

    // Wrapping the chart output with div for custom theming.
    $chart .= theme('date_vs_takeup_count', array(
      'takeup' => $res_o,
    ));

    // Generate date vs takeup count line chart.
    $chart .= '</div>';
    return array(
      'chart' => $chart,
      'title' => t('Activity'),
      'explanation' => t('This chart shows how many times the quiz has been taken each day over the last !days days.', array(
        '!days' => $end,
      )),
    );
  }
}