plugin/exo/Manager/Item/ItemManager.php
public function calculateScore(Item $question, Answer $answer)
    {
        // Let the question correct the answer
        $definition = $this->itemDefinitions->get($question->getMimeType());
        /** @var AnswerableItemDefinitionInterface $definition */
        $corrected = $definition->correctAnswer($question->getInteraction(), json_decode($answer->getData(), true));
        if (!$corrected instanceof CorrectedAnswer) {
            $corrected = new CorrectedAnswer();
        }

        // Add hints
        foreach ($answer->getUsedHints() as $hintId) {
            // Get hint definition from question data
            $hint = null;
            foreach ($question->getHints() as $questionHint) {
                if ($hintId === $questionHint->getUuid()) {
                    $hint = $questionHint;
                    break;
                }
            }
            if ($hint) {
                $corrected->addPenalty($hint);
            }
        }

        return $this->scoreManager->calculate(json_decode($question->getScoreRule(), true), $corrected);
    }
public function calculateScore(Item $question, Answer $answer)
    {
        // Let the question correct the answer
        $definition = $this->itemDefinitions->get($question->getMimeType());
        /** @var AnswerableItemDefinitionInterface $definition */
        $corrected = $definition->correctAnswer($question->getInteraction(), json_decode($answer->getData(), true));
        if (!$corrected instanceof CorrectedAnswer) {
            $corrected = new CorrectedAnswer();
        }

        // Add hints
        foreach ($answer->getUsedHints() as $hintId) {
            // Get hint definition from question data
            $hint = null;
            foreach ($question->getHints() as $questionHint) {
                if ($hintId === $questionHint->getUuid()) {
                    $hint = $questionHint;
                    break;
                }
            }
            if ($hint) {
                $corrected->addPenalty($hint);
            }
        }

        return $this->scoreManager->calculate(json_decode($question->getScoreRule(), true), $corrected);
    }
public function calculateScore ( Item $ question , Answer $ answer ) { // Let the question correct the answer $ definition = $ this -> itemDefinitions -> get ( $ question -> getMimeType ( ) ) ; /** @var AnswerableItemDefinitionInterface $definition */ $ corrected = $ definition -> correctAnswer ( $ question -> getInteraction ( ) , json_decode ( $ answer -> getData ( ) , true ) ) ; if ( ! $ corrected instanceof CorrectedAnswer ) { $ corrected = new CorrectedAnswer ( ) ; } // Add hints foreach ( $ answer -> getUsedHints ( ) as $ hintId ) { // Get hint definition from question data $ hint = null ; foreach ( $ question -> getHints ( ) as $ questionHint ) { if ( $ hintId === $ questionHint -> getUuid ( ) ) { $ hint = $ questionHint ; break ; } } if ( $ hint ) { $ corrected -> addPenalty ( $ hint ) ; } } return $ this -> scoreManager -> calculate ( json_decode ( $ question -> getScoreRule ( ) , true ) , $ corrected ) ; }
Calculates the score of an answer to a question.

@param Item   $question
@param Answer $answer

@return float
Calculates the score of an answer to a question .