function quiz_feedback_can_review in Quiz 7.5
Same name and namespace in other branches
- 7.6 quiz.module \quiz_feedback_can_review()
Can the quiz taker view the requested review?
There's a workaround in here: @kludge
When review for the question is enabled, and it is the last question, technically it is the end of the quiz, and the "end of quiz" review settings apply. So we check to make sure that we are in question taking and the feedback is viewed within 5 seconds of completing the question/quiz.
Parameters
string $option: An option key.
QuizResult $quiz_result: A Quiz result.
Return value
bool TRUE if the quiz taker can view this quiz option at this time, FALSE otherwise.
2 calls to quiz_feedback_can_review()
- QuizQuestionResponse::canReview in question_types/
quiz_question/ quiz_question.core.inc - Can the quiz taker view the requested review?
- QuizResultController::buildContent in includes/
QuizResultController.class.inc - Implements EntityAPIControllerInterface.
File
- ./
quiz.module, line 3756 - quiz.module Main file for the Quiz module.
Code
function quiz_feedback_can_review($option, QuizResult $quiz_result) {
$quiz = node_load($quiz_result->nid, $quiz_result->vid);
$admin = node_access('update', $quiz);
if ($admin) {
// Admin user uses the global feedback options.
$review_options['end'] = variable_get('quiz_admin_review_options_end');
$review_options['question'] = variable_get('quiz_admin_review_options_question');
}
else {
// Use this Quiz's feedback options.
$review_options = $quiz->review_options;
}
$all_shows = array();
if (module_exists('rules')) {
foreach ($review_options as $time_key => $shows) {
// Loop through all the feedback times and check conditions.
if ($set = rules_config_load("quiz_feedback_{$time_key}")) {
$rule_passed = $set
->execute($quiz_result);
if (in_array($time_key, array(
'question',
'end',
))) {
// Special handling for built in conditions.
if ($rule_passed && $time_key == 'end') {
if ($quiz_result->time_end && arg(2) != 'take') {
$all_shows += array_filter($shows);
}
}
if ($rule_passed && $time_key == 'question' && arg(2) == 'take') {
// Special handling for after question.
if (!$quiz_result->time_end || $quiz_result->time_end >= REQUEST_TIME - 5) {
$all_shows += array_filter($shows);
}
}
}
else {
if ($rule_passed) {
// Not one of the above two, add all shows.
$all_shows += array_filter($shows);
}
}
}
}
}
return !empty($all_shows[$option]);
}