function quiz_availability in Quiz 7
Same name and namespace in other branches
- 8.4 quiz.module \quiz_availability()
- 6.4 quiz.module \quiz_availability()
- 7.6 quiz.module \quiz_availability()
- 7.4 quiz.module \quiz_availability()
Find out if a quiz is available for taking or not
Parameters
$quiz: The quiz node
Return value
TRUE if available Error message(String) if not available
Related topics
3 calls to quiz_availability()
- quiz_take_access in ./
quiz.module - Does the current user have access to take the quiz?
- quiz_take_quiz in ./
quiz.module - Handles quiz taking.
- quiz_view in ./
quiz.module
File
- ./
quiz.module, line 2651 - Quiz Module
Code
function quiz_availability($quiz) {
global $user;
if ($user->uid == 0 && $quiz->takes > 0) {
return t('This quiz only allows %num_attempts attempts. Anonymous users can only access quizzes that allows an unlimited number of attempts.', array(
'%num_attempts' => $quiz->takes,
));
}
$user_is_admin = user_access('edit any quiz') || user_access('edit own quiz') && $quiz->uid == $user->uid;
if ($user_is_admin || $quiz->quiz_always == 1) {
return TRUE;
}
// Compare current GMT time to the open and close dates (which should still be
// in GMT time).
$now = gmmktime();
if ($now >= $quiz->quiz_close || $now < $quiz->quiz_open) {
return t('This quiz is closed');
}
return TRUE;
}