You are here

function _quiz_get_summary_text in Quiz 7.5

Same name and namespace in other branches
  1. 8.4 quiz.module \_quiz_get_summary_text()
  2. 5.2 quiz.module \_quiz_get_summary_text()
  3. 5 quiz.module \_quiz_get_summary_text()
  4. 6.6 quiz.module \_quiz_get_summary_text()
  5. 6.2 quiz.module \_quiz_get_summary_text()
  6. 6.3 quiz.module \_quiz_get_summary_text()
  7. 6.4 quiz.module \_quiz_get_summary_text()
  8. 6.5 quiz.module \_quiz_get_summary_text()
  9. 7.6 quiz.module \_quiz_get_summary_text()
  10. 7 quiz.module \_quiz_get_summary_text()
  11. 7.4 quiz.module \_quiz_get_summary_text()

Get the summary message for a completed quiz.

Summary is determined by whether we are using the pass / fail options, how the user did, and where the method is called from.

@todo Need better feedback for when a user is viewing their quiz results from the results list (and possibily when revisiting a quiz they can't take again).

Parameters

$quiz: The quiz node object.

$score: The score information as returned by quiz_calculate_score().

Return value

Filtered summary text or null if we are not displaying any summary.

1 call to _quiz_get_summary_text()
QuizResultController::buildContent in includes/QuizResultController.class.inc
Implements EntityAPIControllerInterface.

File

./quiz.module, line 2712
quiz.module Main file for the Quiz module.

Code

function _quiz_get_summary_text($quiz_result) {
  $quiz = node_load($quiz_result->nid);
  $account = user_load($quiz_result->uid);
  $token_types = array(
    'global' => NULL,
    'node' => $quiz,
    'user' => $account,
    'quiz_result' => $quiz_result,
  );
  $summary = array();
  if ($result_option = _quiz_pick_result_option($quiz->nid, $quiz->vid, $quiz_result->score)) {

    // Range option.
    $summary['result'] = check_markup(token_replace($result_option->option_summary, $token_types), $result_option->option_summary_format);
  }
  if (variable_get('quiz_use_passfail', 1) && $quiz->pass_rate > 0) {
    if ($quiz_result->score >= $quiz->pass_rate) {

      // Pass/fail is enabled and user passed.
      $summary['passfail'] = check_markup(token_replace($quiz->summary_pass, $token_types), $quiz->summary_pass_format);
    }
    else {

      // User failed.
      $summary['passfail'] = check_markup(token_replace($quiz->summary_default, $token_types), $quiz->summary_default_format);
    }
  }
  else {

    // Pass/fail is not being used so display the default.
    $summary['passfail'] = check_markup(token_replace($quiz->summary_default, $token_types), $quiz->summary_default_format);
  }
  return $summary;
}