Skip to content
Snippets Groups Projects
Commit 4a7b150f authored by Joshua Ellinger's avatar Joshua Ellinger
Browse files

Number of takes was not working as intended

Issue #198848 by ocyrus
parent e01dc9bf
No related branches found
No related tags found
No related merge requests found
......@@ -875,6 +875,16 @@ function quiz_take_quiz() {
if (!$user->uid && arg(4) == NULL) {
drupal_goto('node/'. $quiz->nid .'/quiz/start/'. md5(mt_rand() . time()));
}
if ($user->uid && $quiz->takes != 0) {
$times = db_num_rows(db_query("SELECT result_id " .
"FROM {quiz_node_results} " .
"WHERE nid = %d AND vid = %d AND uid = %d",
$quiz->nid, $quiz->vid, $user->uid));
if ($times >= $quiz->takes) {
drupal_set_message(t('You have already taken this @quiz %d times.', array('@quiz' => QUIZ_NAME, '%d' => $times)), 'status');
return;
}
}
if (!isset($_SESSION['quiz_'. $quiz->nid]['quiz_questions'])) {
// First time running through quiz.
......@@ -1155,17 +1165,6 @@ function quiz_start_actions($quiz) {
}
}
// Validate number of takes if we have a registered user.
if ($user->uid && $quiz->takes != 0) {
$times = db_num_rows(db_query("SELECT result_id " .
"FROM {quiz_node_results} " .
"WHERE nid = %d AND vid = %d AND uid = %d",
$quiz->nid, $quiz->vid, $user->uid));
if ($times >= $quiz->takes) {
drupal_set_message(t('You have already taken this @quiz %d times.', array('@quiz' => QUIZ_NAME, '%d' => $times)), 'status');
}
}
// Insert quiz_node_results record.
$rid = db_next_id('{quiz_node_results}_result_id');
$result = db_query("INSERT INTO {quiz_node_results} " .
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment