You are here

function QuizResultAnswer::getPrevious in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 src/Entity/QuizResultAnswer.php \Drupal\quiz\Entity\QuizResultAnswer::getPrevious()
  2. 6.x src/Entity/QuizResultAnswer.php \Drupal\quiz\Entity\QuizResultAnswer::getPrevious()

Get the previous question.

Return value

QuizResultAnswer The next question in the layout or NULL.

File

src/Entity/QuizResultAnswer.php, line 141

Class

QuizResultAnswer
Defines the Quiz entity class.

Namespace

Drupal\quiz\Entity

Code

function getPrevious() {
  $result = $this
    ->get('result_id')
    ->referencedEntities()[0];
  foreach ($result
    ->getLayout() as $idx => $qra) {
    if ($qra == $this) {
      if (isset($result
        ->getLayout()[$idx - 1])) {
        return $result
          ->getLayout()[$idx - 1];
      }
    }
  }
}