You are here

function quiz_update_7518 in Quiz 7.5

Number all the existing attempts.

File

./quiz.install, line 1138
Quiz install schema for installing the quiz module.

Code

function quiz_update_7518() {
  db_add_field('quiz_node_results', 'attempt', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 1,
    'description' => 'The number of this attempt.',
  ));
  $sql = "SELECT * FROM {quiz_node_results} qnr ORDER BY nid,uid,time_start";
  $result = db_query($sql);
  $cur = '';
  while ($row = $result
    ->fetch()) {
    $key = "{$row->nid}_{$row->uid}";
    if ($cur != $key) {
      $attempt = 1;
      $cur = $key;
    }
    db_query('UPDATE {quiz_node_results} SET attempt = :attempt WHERE result_id = :result_id', array(
      ':attempt' => $attempt,
      ':result_id' => $row->result_id,
    ));
    $attempt++;
  }
}