public function parseFeedback($opts){
        $parsedQuestions = [];
        $scoreMax = 0;
        $scoreRaw = 0;

        foreach ($opts['questions'] as $item => $question) {
            // Find the response to the current question
            $currentResponse = null;
            foreach ($opts['attempt']->responses as $responseId => $response) {
                if (!empty($response->item) && $response->item == $item) {
                    $currentResponse = $response;
                }
            }

            if (is_null($currentResponse)) {
                // Perhaps a label or the learner did not answer this question - don't add to the array.
                break;
            }

            // Parse the current question
            $parsedQuestion = (object)[
                'question' => $question,
                'options' => $this->parseQuestionPresentation($question->presentation, $question->typ),
                'score' => (object) [
                    'max' => 0,
                    'raw' => 0
                ],
                'response' => null
            ];

            $parsedQuestion->response = $currentResponse->id;

            // Add scores and response
            foreach ($parsedQuestion->options as $optionIndex => $option) {
                if (isset($option->value) && $option->value > $parsedQuestion->score->max) {
                    $parsedQuestion->score->max = $option->value;
                }

                // Find the option the learner selected
                if ($optionIndex == $currentResponse->id){
                    if (isset($option->value)) {
                        $parsedQuestion->score->raw = $option->value;
                    }
                }
            }

            $scoreMax += $parsedQuestion->score->max;
            $scoreRaw += $parsedQuestion->score->raw;

            if ($parsedQuestion->score->max == 0) {
                $parsedQuestion->score->max = null;
                $parsedQuestion->score->raw = null;
            }
            else {
                $parsedQuestion->score->min = 0;
                $parsedQuestion->score->scaled = $parsedQuestion->score->raw / $parsedQuestion->score->max;
            }

            array_push(
                $parsedQuestions, 
                $parsedQuestion
            );
        }

        $scoreMin = null;
        $scoreScaled = null;
        if ($scoreMax == 0){
            $scoreMax = null;
            $scoreRaw = null;
        }
        else {
            $scoreScaled = $scoreRaw / $scoreMax;
            $scoreMin = 0;
        }

        return (object)[
            'questions' => $parsedQuestions,
            'score' => (object) [
                'max' => $scoreMax,
                'raw' => $scoreRaw,
                'min' => $scoreMin,
                'scaled' => $scoreScaled
            ] 
        ];
    }
public function parseFeedback($opts){
        $parsedQuestions = [];
        $scoreMax = 0;
        $scoreRaw = 0;

        foreach ($opts['questions'] as $item => $question) {
            // Find the response to the current question
            $currentResponse = null;
            foreach ($opts['attempt']->responses as $responseId => $response) {
                if (!empty($response->item) && $response->item == $item) {
                    $currentResponse = $response;
                }
            }

            if (is_null($currentResponse)) {
                // Perhaps a label or the learner did not answer this question - don't add to the array.
                break;
            }

            // Parse the current question
            $parsedQuestion = (object)[
                'question' => $question,
                'options' => $this->parseQuestionPresentation($question->presentation, $question->typ),
                'score' => (object) [
                    'max' => 0,
                    'raw' => 0
                ],
                'response' => null
            ];

            $parsedQuestion->response = $currentResponse->id;

            // Add scores and response
            foreach ($parsedQuestion->options as $optionIndex => $option) {
                if (isset($option->value) && $option->value > $parsedQuestion->score->max) {
                    $parsedQuestion->score->max = $option->value;
                }

                // Find the option the learner selected
                if ($optionIndex == $currentResponse->id){
                    if (isset($option->value)) {
                        $parsedQuestion->score->raw = $option->value;
                    }
                }
            }

            $scoreMax += $parsedQuestion->score->max;
            $scoreRaw += $parsedQuestion->score->raw;

            if ($parsedQuestion->score->max == 0) {
                $parsedQuestion->score->max = null;
                $parsedQuestion->score->raw = null;
            }
            else {
                $parsedQuestion->score->min = 0;
                $parsedQuestion->score->scaled = $parsedQuestion->score->raw / $parsedQuestion->score->max;
            }

            array_push(
                $parsedQuestions, 
                $parsedQuestion
            );
        }

        $scoreMin = null;
        $scoreScaled = null;
        if ($scoreMax == 0){
            $scoreMax = null;
            $scoreRaw = null;
        }
        else {
            $scoreScaled = $scoreRaw / $scoreMax;
            $scoreMin = 0;
        }

        return (object)[
            'questions' => $parsedQuestions,
            'score' => (object) [
                'max' => $scoreMax,
                'raw' => $scoreRaw,
                'min' => $scoreMin,
                'scaled' => $scoreScaled
            ] 
        ];
    }
public function parseFeedback ( $ opts ) { $ parsedQuestions = [ ] ; $ scoreMax = 0 ; $ scoreRaw = 0 ; foreach ( $ opts [ 'questions' ] as $ item => $ question ) { // Find the response to the current question $ currentResponse = null ; foreach ( $ opts [ 'attempt' ] -> responses as $ responseId => $ response ) { if ( ! empty ( $ response -> item ) && $ response -> item == $ item ) { $ currentResponse = $ response ; } } if ( is_null ( $ currentResponse ) ) { // Perhaps a label or the learner did not answer this question - don't add to the array. break ; } // Parse the current question $ parsedQuestion = ( object ) [ 'question' => $ question , 'options' => $ this -> parseQuestionPresentation ( $ question -> presentation , $ question -> typ ) , 'score' => ( object ) [ 'max' => 0 , 'raw' => 0 ] , 'response' => null ] ; $ parsedQuestion -> response = $ currentResponse -> id ; // Add scores and response foreach ( $ parsedQuestion -> options as $ optionIndex => $ option ) { if ( isset ( $ option -> value ) && $ option -> value > $ parsedQuestion -> score -> max ) { $ parsedQuestion -> score -> max = $ option -> value ; } // Find the option the learner selected if ( $ optionIndex == $ currentResponse -> id ) { if ( isset ( $ option -> value ) ) { $ parsedQuestion -> score -> raw = $ option -> value ; } } } $ scoreMax += $ parsedQuestion -> score -> max ; $ scoreRaw += $ parsedQuestion -> score -> raw ; if ( $ parsedQuestion -> score -> max == 0 ) { $ parsedQuestion -> score -> max = null ; $ parsedQuestion -> score -> raw = null ; } else { $ parsedQuestion -> score -> min = 0 ; $ parsedQuestion -> score -> scaled = $ parsedQuestion -> score -> raw / $ parsedQuestion -> score -> max ; } array_push ( $ parsedQuestions , $ parsedQuestion ) ; } $ scoreMin = null ; $ scoreScaled = null ; if ( $ scoreMax == 0 ) { $ scoreMax = null ; $ scoreRaw = null ; } else { $ scoreScaled = $ scoreRaw / $ scoreMax ; $ scoreMin = 0 ; } return ( object ) [ 'questions' => $ parsedQuestions , 'score' => ( object ) [ 'max' => $ scoreMax , 'raw' => $ scoreRaw , 'min' => $ scoreMin , 'scaled' => $ scoreScaled ] ] ; }
Converts a outputs feedback question and result data in a more manageable format
@param [Array => Mixed] $opts
@return [PHPObj => Mixed]
Converts a outputs feedback question and result data in a more manageable format