public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/classes/unitfrontend.php
/**
		 * Extracts the checked answers and saves the question results for this user
		 * so that it can be stored in the database.
		 *
		 * @param Array $checkedAnswerList The list of answers that have been cleaned and checked.
		 *
		 * @return Array The list of status data for progress to store.
		 */
Extracts the checked answers and saves the question results for this user
so that it can be stored in the database.

@param Array $checkedAnswerList The list of answers that have been cleaned and checked.

@return Array The list of status data for progress to store.
Extracts the checked answers and saves the question results for this user so that it can be stored in the database . @param Array $checkedAnswerList The list of answers that have been cleaned and checked . @return Array The list of status data for progress to store .
public function fetch_quizzes_extractQuizStatusFromAnswers( $checkedAnswerList, $possibleAnswers ) {
			$fullDetails = array();
			foreach ( $this->unitQuizDetails->questions as $singleQuestion ) {
				$qItem          = array();
				$qItem['title'] = $singleQuestion->question_question;
				$openEndedQuestion = false;
				if ( ! isset( $possibleAnswers[ $singleQuestion->question_id ] ) ) {
					$qItem['possible_answers'] = false;
				} else {
					$qItem['possible_answers'] = $possibleAnswers[ $singleQuestion->question_id ];
				}
				if ( ! isset( $checkedAnswerList[ $singleQuestion->question_id ] ) ) {
					$qItem['correct']          = false;
					$qItem['got_right']        = false;
					$qItem['their_answer']     = false;
					$qItem['their_answer_raw'] = false;
					$qItem['is_incomplete']    = true;
				} 
				else {
					switch ( $singleQuestion->question_type ) {
						case 'truefalse':
						case 'multi':
							$qItem['their_answer'] = $this->check_quizzes_getCorrectAnswer( $singleQuestion, $checkedAnswerList[ $singleQuestion->question_id ] );
							break;
						case 'upload':
						case 'open':
							$openEndedQuestion     = true;
							$qItem['their_answer'] = $checkedAnswerList[ $singleQuestion->question_id ];
							break;
					}
					$qItem['their_answer_raw'] = $checkedAnswerList[ $singleQuestion->question_id ];
					if ( 'survey' == $this->unitQuizDetails->quiz_type || $openEndedQuestion ) {
						$qItem['correct']   = false;
						$qItem['got_right'] = false;
					} 
					else {
						$qItem['correct'] = $this->check_quizzes_getCorrectAnswer( $singleQuestion );
												if ( is_array( $qItem['correct'] ) ) {
							$isAnsCorrect       = false;
							$diffCorrect        = array_diff( $qItem['correct'], $qItem['their_answer'] );
							$diffTheirAnswer    = array_diff( $qItem['their_answer'], $qItem['correct'] );
							$qItem['got_right'] = ( count( $diffCorrect ) <= 0 && count( $diffTheirAnswer ) <= 0 ? 'yes' : 'no' );
						} else {
							$qItem['got_right'] = ( $qItem['their_answer'] == $qItem['correct'] ? 'yes' : 'no' );
						}
					}
					$qItem['is_incomplete'] = false;
				}
				$fullDetails[ $singleQuestion->question_id ] = $qItem;
			} 
			return $fullDetails;
		}
public function fetch_quizzes_extractQuizStatusFromAnswers ( $ checkedAnswerList , $ possibleAnswers ) { $ fullDetails = array ( ) ; foreach ( $ this -> unitQuizDetails -> questions as $ singleQuestion ) { $ qItem = array ( ) ; $ qItem [ 'title' ] = $ singleQuestion -> question_question ; $ openEndedQuestion = false ; if ( ! isset ( $ possibleAnswers [ $ singleQuestion -> question_id ] ) ) { $ qItem [ 'possible_answers' ] = false ; } else { $ qItem [ 'possible_answers' ] = $ possibleAnswers [ $ singleQuestion -> question_id ] ; } if ( ! isset ( $ checkedAnswerList [ $ singleQuestion -> question_id ] ) ) { $ qItem [ 'correct' ] = false ; $ qItem [ 'got_right' ] = false ; $ qItem [ 'their_answer' ] = false ; $ qItem [ 'their_answer_raw' ] = false ; $ qItem [ 'is_incomplete' ] = true ; } else { switch ( $ singleQuestion -> question_type ) { case 'truefalse' : case 'multi' : $ qItem [ 'their_answer' ] = $ this -> check_quizzes_getCorrectAnswer ( $ singleQuestion , $ checkedAnswerList [ $ singleQuestion -> question_id ] ) ; break ; case 'upload' : case 'open' : $ openEndedQuestion = true ; $ qItem [ 'their_answer' ] = $ checkedAnswerList [ $ singleQuestion -> question_id ] ; break ; } $ qItem [ 'their_answer_raw' ] = $ checkedAnswerList [ $ singleQuestion -> question_id ] ; if ( 'survey' == $ this -> unitQuizDetails -> quiz_type || $ openEndedQuestion ) { $ qItem [ 'correct' ] = false ; $ qItem [ 'got_right' ] = false ; } else { $ qItem [ 'correct' ] = $ this -> check_quizzes_getCorrectAnswer ( $ singleQuestion ) ; if ( is_array ( $ qItem [ 'correct' ] ) ) { $ isAnsCorrect = false ; $ diffCorrect = array_diff ( $ qItem [ 'correct' ] , $ qItem [ 'their_answer' ] ) ; $ diffTheirAnswer = array_diff ( $ qItem [ 'their_answer' ] , $ qItem [ 'correct' ] ) ; $ qItem [ 'got_right' ] = ( count ( $ diffCorrect ) <= 0 && count ( $ diffTheirAnswer ) <= 0 ? 'yes' : 'no' ) ; } else { $ qItem [ 'got_right' ] = ( $ qItem [ 'their_answer' ] == $ qItem [ 'correct' ] ? 'yes' : 'no' ) ; } } $ qItem [ 'is_incomplete' ] = false ; } $ fullDetails [ $ singleQuestion -> question_id ] = $ qItem ; } return $ fullDetails ; }
Extracts the checked answers and saves the question results for this user
 so that it can be stored in the database.
Extracts the checked answers and saves the question results for this user so that it can be stored in the database .
// ### A - We might not have an answer for this question. So set up the defaults. //$qItem['possible_answers'] = false; // ### B - We do have an answer for this question // We know we have enough answers at this point, so know // There's definitely a right or wrong answer, so determine that now. // Uploaded files and open-ended questions need marking, so it's just their raw answer. // Store the possible answers //$qItem['possible_answers'] = $possibleAnswers[$singleQuestion->question_id]; // Store raw answer (used by paging questions to mark later) // If a survey, there are no correct answers. // Normal quiz with multiple-choice. // Get the correct answer // Did the answers match?
 // We have an answer, so it's not incomplete. // Add the details back to the details to return. // end of foreach loop