You are here

function _quiz_get_results in Quiz 6.5

Same name and namespace in other branches
  1. 5.2 quiz.module \_quiz_get_results()
  2. 5 quiz.module \_quiz_get_results()
  3. 6.6 quiz.module \_quiz_get_results()
  4. 6.2 quiz.module \_quiz_get_results()
  5. 6.3 quiz.module \_quiz_get_results()
  6. 6.4 quiz.module \_quiz_get_results()
  7. 7 quiz.module \_quiz_get_results()

Get a full results list.

Parameters

$nid: Node ID for the quiz.

$uid: Optional user ID to constrain results to just that user.

Return value

A list of results.

2 calls to _quiz_get_results()
quiz_admin in ./quiz.admin.inc
Quiz Admin.
results_export_as_teaser_view in includes/results_export/results_export.admin.inc

File

./quiz.module, line 2499
Quiz Module

Code

function _quiz_get_results($nid = '', $uid = 0) {
  $results = array();
  $args = array();

  /* This seems to have an unnecessary join in here:
    $sql = "SELECT n.nid, n.title, u.name, qnrs.result_id, qnrs.time_start, qnrs.time_end
            FROM {node} n
            INNER JOIN {quiz_node_properties} qnp
            INNER JOIN {quiz_node_results} qnrs
            INNER JOIN {users} u
            WHERE n.type = 'quiz'
              AND n.nid = qnp.nid
              AND qnrs.nid = qnp.nid
              AND u.uid = qnrs.uid";
    */
  $sql = "SELECT n.nid, n.title, u.name, qnrs.result_id, qnrs.score, qnrs.time_start, qnrs.time_end\n          FROM {node} n\n          INNER JOIN {quiz_node_results} qnrs ON qnrs.nid = n.nid\n          INNER JOIN {users} u ON u.uid = qnrs.uid\n          WHERE n.type = 'quiz'";
  if ($nid) {
    $sql .= " AND qnrs.nid = %d";
    $args[] = $nid;
  }
  if ($uid != 0) {
    $sql .= " AND qnrs.uid = %d";
    $args[] = $uid;
  }
  $sql .= " ORDER BY qnrs.result_id DESC";
  $dbresult = db_query($sql, $args);
  while ($line = db_fetch_array($dbresult)) {
    $results[$line['result_id']] = $line;
  }
  return $results;
}