In drupal 6, I had a requirement to enable the users to take the quiz on the next day if they failed and from somewhere I got the following code to make that work. They added one more variables, time_end
and used strtotime('today')
But now I upgraded to Drupal 7 and code for the same a little bit changed and I couldn't make that work. I am looking forward to getting help to achieve it. I am using quiz quiz-7.x-4.0-rc1
Drupal 6 Original lines
// Check to see if this user is allowed to take the quiz again:
if ($quiz->takes > 0) {
// $query = "SELECT COUNT(*) AS takes FROM {quiz_node_results} WHERE uid = %d AND nid = %d";
// $taken = db_result(db_query($query, $user->uid, $quiz->nid));
Drupal 6 Changed lines (only first two lines. after that code remains the same except drupal_set_message.)
$query = "SELECT COUNT(*) AS takes FROM {quiz_node_results} WHERE uid = %d AND nid = %d AND time_end > %d";
$taken = db_result(db_query($query, $user->uid, $quiz->nid, strtotime('today')));
$allowed_times = format_plural($quiz->takes, '1 time', '@count times');
$taken_times = format_plural($taken, '1 time', '@count times');
Drupal 7 Original lines.
// Check to see if this user is allowed to take the quiz again:
if ($quiz->takes > 0) {
$taken = db_query("SELECT COUNT(*) AS takes FROM {quiz_node_results} WHERE uid = :uid AND nid = :nid", array(':uid' => $user->uid, ':nid' => $quiz->nid))->fetchField();
$allowed_times = format_plural($quiz->takes, '1 time', '@count times');
$taken_times = format_plural($taken, '1 time', '@count times');
Full drupal 7 code is available here DrupalContrib
print_r($quiz);
just aboveif ($quiz->takes > 0)