You are here

function _get_date_vs_takeup_count_chart in Quiz 8.4

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.5 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 212
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";
  $sql_args[':vid'] = $vid;
  if ($uid != 0) {
    $sql .= " AND uid = :uid";
    $sql_args[':uid'] = $uid;
  }
  $sql .= " GROUP BY date ORDER BY time_start DESC";
  $days = _quiz_get_last_days($end);
  $results = db_query($sql, $sql_args);
  $res_o = $results
    ->fetch();
  if (!is_object($res_o)) {
    return FALSE;
  }
  foreach ($days as $date => &$value) {
    if (isset($res_o->date) && $date == $res_o->date) {
      $value->value = $res_o->count;
      if ($res_o->count > 0) {
        $valid_data = TRUE;
      }
      $res_o = $results
        ->fetch();
    }
  }
  if (!$valid_data) {
    return FALSE;
  }
  $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' => $days,
  ));

  // 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 the last !days days.', array(
      '!days' => $end,
    )),
  );
}