Skip to content

v1.2.0

Compare
Choose a tag to compare
@harishdurga harishdurga released this 02 Feb 15:40
· 12 commits to main since this release
69b6e3a

The validate() on the QuizAttempt model fetched answers from the first QuizAttempt rather than the correct QuizAttempt when there are multiple QuizAttempts for the same Quiz. The same was the issue with render methods for the three types of questions. This issue got fixed in this release. The render method signature got updated by passing the QuizAttempt as the second argument and the mixed optional data as the third argument.

Example

public static function renderQuestionType1Answers(QuizQuestion $quizQuestion,QuizAttempt $quizAttempt,mixed $data=null)
    {
        /**
         * @var Question $actualQuestion
         */
        $actualQuestion = $quizQuestion->question;
        $answers = $quizQuestion->answers->where('quiz_attempt_id', $quizAttempt->id);
        $questionOptions = $actualQuestion->options;
        $correctAnswer = $actualQuestion->correct_options()->first()?->option;
        $givenAnswer = $answers->first()?->question_option_id;
        foreach ($questionOptions as $questionOption) {
            if ($questionOption->id == $givenAnswer) {
                $givenAnswer = $questionOption->option;
                break;
            }
        }
        return [$correctAnswer, $givenAnswer];
    }