function quiz_availability in Quiz 7.6
Same name and namespace in other branches
- 8.4 quiz.module \quiz_availability()
- 6.4 quiz.module \quiz_availability()
- 7 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_page in ./
quiz.module - Page to either resume a quiz or display a start quiz form.
- quiz_view in ./
quiz.module - Implements hook_view().
File
- ./
quiz.module, line 2379 - quiz.module Main file for the 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,
'@quiz' => QUIZ_NAME,
));
}
$user_is_admin = user_access('edit any quiz content') || user_access('edit own quiz content') && $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 = REQUEST_TIME;
if ($now >= $quiz->quiz_close || $now < $quiz->quiz_open) {
return t('This @quiz is closed.', array(
'@quiz' => QUIZ_NAME,
));
}
return TRUE;
}