You are here

function _quiz_delete_results in Quiz 7

Same name and namespace in other branches
  1. 8.4 quiz.admin.inc \_quiz_delete_results()
  2. 6.4 quiz.admin.inc \_quiz_delete_results()
  3. 7.6 quiz.admin.inc \_quiz_delete_results()
  4. 7.4 quiz.admin.inc \_quiz_delete_results()

Delete a single result, or all results for a given user and a given quiz.

Parameters

$rid: result if for the result to be deleted

$nid: Node id for the quiz the result belongs to. If set all the users results for this quiz will be deleted.

1 call to _quiz_delete_results()
quiz_results_mr_form_submit in ./quiz.admin.inc
Submit function for the result browser form

File

./quiz.admin.inc, line 2523
Administrator interface for Quiz module.

Code

function _quiz_delete_results($rid, $nid = NULL) {
  $rids = array();

  // We are to delete all results for a certain user on a certain quiz.
  if (isset($nid)) {

    // TODO: We should be able to rewrite this one to use the DBTNG.
    $res = db_query('SELECT result_id
            FROM {quiz_node_results}
            WHERE nid = :nid AND uid = (
              SELECT uid
              FROM {quiz_node_results}
              WHERE result_id = :result_id
            )', array(
      ':nid' => $nid,
      ':result_id' => $rid,
    ));
    while ($result = $res
      ->fetchField()) {
      $rids[] = $result;
    }
  }
  else {
    $rids[] = $rid;
  }
  quiz_delete_results($rids);
}