You are here

function _quiz_get_summary_text in Quiz 8.4

Same name and namespace in other branches
  1. 5.2 quiz.module \_quiz_get_summary_text()
  2. 5 quiz.module \_quiz_get_summary_text()
  3. 6.6 quiz.module \_quiz_get_summary_text()
  4. 6.2 quiz.module \_quiz_get_summary_text()
  5. 6.3 quiz.module \_quiz_get_summary_text()
  6. 6.4 quiz.module \_quiz_get_summary_text()
  7. 6.5 quiz.module \_quiz_get_summary_text()
  8. 7.6 quiz.module \_quiz_get_summary_text()
  9. 7 quiz.module \_quiz_get_summary_text()
  10. 7.4 quiz.module \_quiz_get_summary_text()
  11. 7.5 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.

3 calls to _quiz_get_summary_text()
quiz_admin_results in ./quiz.admin.inc
Quiz result report page for the quiz admin section
quiz_take_quiz in ./quiz.module
Handles quiz taking.
quiz_user_results in ./quiz.pages.inc
Show result page for a given result id

File

./quiz.module, line 2662
Quiz Module

Code

function _quiz_get_summary_text($quiz, $score) {
  $summary = array();
  $admin = arg(0) == 'admin';
  if (!$admin) {
    if (!empty($score['result_option'])) {

      // Unscored quiz, return the proper result option.
      $summary['result'] = check_markup($score['result_option'], $quiz->body['und'][0]['format']);
    }
    else {
      $result_option = _quiz_pick_result_option($quiz
        ->id(), $quiz
        ->getRevisionId(), $score['percentage_score']);
      $summary['result'] = is_object($result_option) ? check_markup($result_option->option_summary, $result_option->option_summary_format) : '';
    }
  }

  // If we are using pass/fail, and they passed.
  if ($quiz->pass_rate > 0 && $score['percentage_score'] >= $quiz->pass_rate) {

    // If we are coming from the admin view page.
    if ($admin) {
      $summary['passfail'] = t('The user passed this quiz.');
    }
    elseif (\Drupal::config('quiz.settings')
      ->get('quiz_use_passfail') == 0) {

      // If there is only a single summary text, use this.
      if (trim($quiz->summary_default) != '') {
        $summary['passfail'] = check_markup($quiz->summary_default, $quiz->body['und'][0]['format']);
      }
    }
    elseif (trim($quiz->summary_pass) != '') {

      // If there is a pass summary text, use this.
      $summary['passfail'] = check_markup($quiz->summary_pass, $quiz->summary_pass_format);
    }
  }
  else {

    // If we are coming from the admin view page, only show a summary if we are
    // using pass/fail.
    if ($admin) {
      if ($quiz->pass_rate > 0) {
        $summary['passfail'] = t('The user failed this quiz.');
      }
      else {
        $summary['passfail'] = t('the user completed this quiz.');
      }
    }
    elseif (trim($quiz->summary_default) != '') {
      $summary['passfail'] = check_markup($quiz->summary_default, $quiz->summary_default_format);
    }
  }
  return $summary;
}