function quiz_availability in Quiz 8.4
Same name and namespace in other branches
- 6.4 quiz.module \quiz_availability()
- 7.6 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
3 calls to quiz_availability()
- quiz_node_view in ./
quiz.module - Implements hook_node_view().
- 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.
File
- ./
quiz.module, line 1215 - Quiz Module
Code
function quiz_availability(EntityInterface $quiz) {
$user = \Drupal::currentUser();
if ($user
->id() == 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
->hasPermission('edit any quiz content') || $user
->hasPermission('edit own quiz content') && $quiz
->id() == $user
->id();
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;
}