You are here

static function QuizUtil::resultOrTemp in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 src/Util/QuizUtil.php \Drupal\quiz\Util\QuizUtil::resultOrTemp()
  2. 6.x src/Util/QuizUtil.php \Drupal\quiz\Util\QuizUtil::resultOrTemp()

Use in the case where a quiz may have ended and the temporary result ID must be used instead.

Parameters

Quiz $quiz:

Return value

QuizResult

2 calls to QuizUtil::resultOrTemp()
QuizQuestionController::numberToQuestionResultAnswer in src/Controller/QuizQuestionController.php
Translate the numeric question index to a question result answer.
QuizQuestionFeedbackForm::buildForm in src/Form/QuizQuestionFeedbackForm.php
Show feedback for a question response.

File

src/Util/QuizUtil.php, line 109

Class

QuizUtil
Utility functions that don't belong anywhere else.

Namespace

Drupal\quiz\Util

Code

static function resultOrTemp(Quiz $quiz) {
  if (isset($_SESSION['quiz'][$quiz
    ->id()]['result_id'])) {
    return QuizResult::load($_SESSION['quiz'][$quiz
      ->id()]['result_id']);
  }
  elseif (isset($_SESSION['quiz']['temp']['result_id'])) {
    return QuizResult::load($_SESSION['quiz']['temp']['result_id']);
  }
  return NULL;
}