You are here

function quiz_access_my_results in Quiz 7

Same name and namespace in other branches
  1. 8.4 quiz.module \quiz_access_my_results()
  2. 6.4 quiz.module \quiz_access_my_results()
  3. 7.6 quiz.module \quiz_access_my_results()
  4. 7.4 quiz.module \quiz_access_my_results()
  5. 7.5 quiz.module \quiz_access_my_results()

Helper function to determine if a user has access to view his quiz results

Parameters

object $quiz: The Quiz node

1 string reference to 'quiz_access_my_results'
quiz_menu in ./quiz.module
Implements hook_menu().

File

./quiz.module, line 211
Quiz Module

Code

function quiz_access_my_results($quiz) {
  global $user;
  if ($quiz->type !== 'quiz') {
    return FALSE;
  }
  if (user_access('view own quiz results') && !quiz_access_results($quiz)) {
    $answered = db_query('SELECT 1 FROM {quiz_node_results} WHERE nid = :nid AND uid = :uid AND is_evaluated = :is_evaluated', array(
      ':nid' => $quiz->nid,
      ':uid' => $user->uid,
      ':is_evaluated' => 1,
    ))
      ->fetchField();
    if ($answered) {
      return TRUE;
    }
  }
}