public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/classes/unitfrontend.php
/**
		 * In paging mode, check the answers that have been provided and update the status in the
		 * database if we're still progressing through getting answers to all questions.
		 *
		 * @param Array $potentialAnswers The potential answers that need checking.
		 *
		 * @return Boolean Returns true when we have all of our answers, and we're allowed to carry on for grading.
		 */
In paging mode, check the answers that have been provided and update the status in the
database if we're still progressing through getting answers to all questions.

@param Array $potentialAnswers The potential answers that need checking.

@return Boolean Returns true when we have all of our answers, and we're allowed to carry on for grading.
In paging mode check the answers that have been provided and update the status in the database if we ' re still progressing through getting answers to all questions . @param Array $potentialAnswers The potential answers that need checking . @return Boolean Returns true when we have all of our answers and we ' re allowed to carry on for grading .
public function check_quizzes_canWeContinue_checkAnswersFromPaging( $potentialAnswers, $skipAnswer = false ) {
			global $wpdb, $wpcwdb;
			$wpdb->show_errors();
			$resultsList = $this->check_quizzes_canWeContinue_extractAnswerData( $potentialAnswers );
			$possibleAnswers = $resultsList['all_answer_list'];
			$data            = array();
			$data['user_id'] = $this->currentUserID;
			$data['unit_id'] = $this->unitPost->ID;
			$data['quiz_id'] = $this->unitQuizDetails->quiz_id;
			$data['quiz_completed_date']    = current_time( 'mysql' );
			$data['quiz_correct_questions'] = 0;
			$data['quiz_question_total']    = count( $this->unitQuizDetails->questions );
			$data['quiz_paging_incomplete'] = $data['quiz_question_total'] - 1;
			if ( ! $skipAnswer ) {
				$data['quiz_paging_next_q'] = 1;
			}
			$data['quiz_paging_status'] = 'incomplete';
			$data['quiz_data'] = false;
			$SQL = $wpdb->prepare( "
			SELECT * 
			FROM $wpcwdb->user_progress_quiz
			WHERE user_id = %d
			  AND unit_id = %d
			  AND quiz_id = %d
			ORDER BY quiz_attempt_id DESC 
			LIMIT 1
		", $this->currentUserID, $this->unitPost->ID, $this->unitQuizDetails->quiz_id );
			$updateExistingProgress = false;
			if ( $existingProgress = $wpdb->get_row( $SQL ) ) {
				if ( 'incomplete' == $existingProgress->quiz_paging_status ) {
					$updateExistingProgress = true;
					if ( ! $skipAnswer ) {
						$data['quiz_paging_next_q'] = $this->check_paging_find_next_unanswered_question();
					}
					foreach ( $existingProgress as $fieldName => $fieldDetails ) {
						if ( ! isset( $data[ $fieldName ] ) ) {
							$data[ $fieldName ] = $fieldDetails;
						}
					}
					if ( $this->check_timers_doWeHaveAnActiveTimer_thatHasExpired() ) {
						$data['quiz_paging_next_q'] = $existingProgress->quiz_question_total;
					}
				} 
				else {
					$SQL = $wpdb->prepare( "
					UPDATE $wpcwdb->user_progress_quiz
					SET quiz_is_latest = ''
					WHERE user_id = %d
					  AND unit_id = %d
					  AND quiz_id = %d
				", $this->currentUserID, $this->unitPost->ID, $this->unitQuizDetails->quiz_id );
					$wpdb->query( $SQL );
					$data['quiz_is_latest']  = 'latest';
					$data['quiz_attempt_id'] = $existingProgress->quiz_attempt_id + 1;
				}
			}
			if ( $updateExistingProgress ) {
				$data['quiz_data'] = maybe_unserialize( $existingProgress->quiz_data );
				if ( ! empty( $data['quiz_data'] ) ) {
					$newData = $this->fetch_quizzes_extractQuizStatusFromAnswers( $resultsList['answer_list'], $possibleAnswers );
					if ( ! empty( $newData ) ) {
						foreach ( $newData as $thisQuestionID => $thisAnswerDetails ) {
							if ( $thisAnswerDetails['is_incomplete'] == 0 ) {
								$data['quiz_data'][ $thisQuestionID ] = $thisAnswerDetails;
								if ( $skipAnswer ) {
									$data['quiz_data'][ $thisQuestionID ]['is_incomplete'] = true;
								}
							}
						}
					}
					$data['quiz_paging_incomplete'] = 0;
					foreach ( $data['quiz_data'] as $thisQuestionID => $thisAnswerDetails ) {
						if ( $thisAnswerDetails['is_incomplete'] == 1 ) {
							++ $data['quiz_paging_incomplete'];
						}
					}
				} 
				else {
					$data['quiz_data'] = $this->fetch_quizzes_extractQuizStatusFromAnswers( $resultsList['answer_list'], $possibleAnswers );
				}
				$data['quiz_data'] = serialize( $data['quiz_data'] );
				$SQL = arrayToSQLUpdate( $wpcwdb->user_progress_quiz, $data, array( 'user_id', 'unit_id', 'quiz_id', 'quiz_attempt_id' ) );
			} else {
				$data['quiz_data'] = serialize( $this->fetch_quizzes_extractQuizStatusFromAnswers( $resultsList['answer_list'], $possibleAnswers ) );
				$SQL = arrayToSQLInsert( $wpcwdb->user_progress_quiz, $data );
			}
			$wpdb->query( $SQL );
			if ( $skipAnswer ) {
				return;
			}
			$this->unitQuizProgress = WPCW_quizzes_getUserResultsForQuiz( $this->currentUserID, $this->unitPost->ID, $this->unitQuizDetails->quiz_id );
			$this->updateInternalVariable_quizzes_getIncompleteQuestions();
			$this->fetch_quizzes_loadRawAnswersSoFarForThisQuiz( $data['quiz_data'] );
			return $this->unitQuizProgress->quiz_paging_incomplete == 0 && ! $this->check_paging_shouldWeShowReviewPage();
		}
public function check_quizzes_canWeContinue_checkAnswersFromPaging ( $ potentialAnswers , $ skipAnswer = false ) { global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; $ resultsList = $ this -> check_quizzes_canWeContinue_extractAnswerData ( $ potentialAnswers ) ; $ possibleAnswers = $ resultsList [ 'all_answer_list' ] ; $ data = array ( ) ; $ data [ 'user_id' ] = $ this -> currentUserID ; $ data [ 'unit_id' ] = $ this -> unitPost -> ID ; $ data [ 'quiz_id' ] = $ this -> unitQuizDetails -> quiz_id ; $ data [ 'quiz_completed_date' ] = current_time ( 'mysql' ) ; $ data [ 'quiz_correct_questions' ] = 0 ; $ data [ 'quiz_question_total' ] = count ( $ this -> unitQuizDetails -> questions ) ; $ data [ 'quiz_paging_incomplete' ] = $ data [ 'quiz_question_total' ] - 1 ; if ( ! $ skipAnswer ) { $ data [ 'quiz_paging_next_q' ] = 1 ; } $ data [ 'quiz_paging_status' ] = 'incomplete' ; $ data [ 'quiz_data' ] = false ; $ SQL = $ wpdb -> prepare ( " 
			SELECT * 
			FROM  $ wpcwdb -> user_progress_quiz 
			WHERE user_id = %d
			  AND unit_id = %d
			  AND quiz_id = %d
			ORDER BY quiz_attempt_id DESC 
			LIMIT 1
		 " , $ this -> currentUserID , $ this -> unitPost -> ID , $ this -> unitQuizDetails -> quiz_id ) ; $ updateExistingProgress = false ; if ( $ existingProgress = $ wpdb -> get_row ( $ SQL ) ) { if ( 'incomplete' == $ existingProgress -> quiz_paging_status ) { $ updateExistingProgress = true ; if ( ! $ skipAnswer ) { $ data [ 'quiz_paging_next_q' ] = $ this -> check_paging_find_next_unanswered_question ( ) ; } foreach ( $ existingProgress as $ fieldName => $ fieldDetails ) { if ( ! isset ( $ data [ $ fieldName ] ) ) { $ data [ $ fieldName ] = $ fieldDetails ; } } if ( $ this -> check_timers_doWeHaveAnActiveTimer_thatHasExpired ( ) ) { $ data [ 'quiz_paging_next_q' ] = $ existingProgress -> quiz_question_total ; } } else { $ SQL = $ wpdb -> prepare ( " 
					UPDATE  $ wpcwdb -> user_progress_quiz 
					SET quiz_is_latest = ''
					WHERE user_id = %d
					  AND unit_id = %d
					  AND quiz_id = %d
				 " , $ this -> currentUserID , $ this -> unitPost -> ID , $ this -> unitQuizDetails -> quiz_id ) ; $ wpdb -> query ( $ SQL ) ; $ data [ 'quiz_is_latest' ] = 'latest' ; $ data [ 'quiz_attempt_id' ] = $ existingProgress -> quiz_attempt_id + 1 ; } } if ( $ updateExistingProgress ) { $ data [ 'quiz_data' ] = maybe_unserialize ( $ existingProgress -> quiz_data ) ; if ( ! empty ( $ data [ 'quiz_data' ] ) ) { $ newData = $ this -> fetch_quizzes_extractQuizStatusFromAnswers ( $ resultsList [ 'answer_list' ] , $ possibleAnswers ) ; if ( ! empty ( $ newData ) ) { foreach ( $ newData as $ thisQuestionID => $ thisAnswerDetails ) { if ( $ thisAnswerDetails [ 'is_incomplete' ] == 0 ) { $ data [ 'quiz_data' ] [ $ thisQuestionID ] = $ thisAnswerDetails ; if ( $ skipAnswer ) { $ data [ 'quiz_data' ] [ $ thisQuestionID ] [ 'is_incomplete' ] = true ; } } } } $ data [ 'quiz_paging_incomplete' ] = 0 ; foreach ( $ data [ 'quiz_data' ] as $ thisQuestionID => $ thisAnswerDetails ) { if ( $ thisAnswerDetails [ 'is_incomplete' ] == 1 ) { ++ $ data [ 'quiz_paging_incomplete' ] ; } } } else { $ data [ 'quiz_data' ] = $ this -> fetch_quizzes_extractQuizStatusFromAnswers ( $ resultsList [ 'answer_list' ] , $ possibleAnswers ) ; } $ data [ 'quiz_data' ] = serialize ( $ data [ 'quiz_data' ] ) ; $ SQL = arrayToSQLUpdate ( $ wpcwdb -> user_progress_quiz , $ data , array ( 'user_id' , 'unit_id' , 'quiz_id' , 'quiz_attempt_id' ) ) ; } else { $ data [ 'quiz_data' ] = serialize ( $ this -> fetch_quizzes_extractQuizStatusFromAnswers ( $ resultsList [ 'answer_list' ] , $ possibleAnswers ) ) ; $ SQL = arrayToSQLInsert ( $ wpcwdb -> user_progress_quiz , $ data ) ; } $ wpdb -> query ( $ SQL ) ; if ( $ skipAnswer ) { return ; } $ this -> unitQuizProgress = WPCW_quizzes_getUserResultsForQuiz ( $ this -> currentUserID , $ this -> unitPost -> ID , $ this -> unitQuizDetails -> quiz_id ) ; $ this -> updateInternalVariable_quizzes_getIncompleteQuestions ( ) ; $ this -> fetch_quizzes_loadRawAnswersSoFarForThisQuiz ( $ data [ 'quiz_data' ] ) ; return $ this -> unitQuizProgress -> quiz_paging_incomplete == 0 && ! $ this -> check_paging_shouldWeShowReviewPage ( ) ; }
In paging mode, check the answers that have been provided and update the status in the
 database if we're still progressing through getting answers to all questions.
In paging mode check the answers that have been provided and update the status in the database if we ' re still progressing through getting answers to all questions .
// Check the raw data to see what questions we have. // Get all answers possible // Need to build the data for the quiz progress, which should show that the quiz hasn't been graded as yet. // Total number of incomplete questions matches one less than question count (-1 to remove this Q). // Showing the next question if we've got here. // We're still working on this quiz, so it's incomplete. // Set to false, we'll fill it in later. // Do we have a progress item already? Such as a prior attempt or previous question (when paging). // Already exists, so we just need to update the progress with where we're at. // If it doesn't exist, we'll just use the database default of 0. // Got an existing incomplete paging progress, carry on working with it. // Navigate to next unanswered question // Migrate data from the existing progress that's important. // Set the quiz_paging_next_q to total questions if timer has expired // Got an existing complete paging progress, so we need to unmark it as the latest. // We're now going to insert a new record that is the latest. // Mark all previous progress items as not being the latest. // Ensure this new progress marked as the latest. // Do Insert or Update as needed. // Fetch the existing quiz data, as we need to merge the new complete data with // the existing data. // We're assuming that if the new data is complete, then we overwrite the old // data, as that should be incomplete. // Got a new complete item, so overwrite details // Count up the total number of incomplete questions left. // Found another question that's not complete, so add 1 to count of incomplete questions. // Not no prior data, so use all of the defaults. // Need to reserialize the data // Extract all quiz data including placeholders for questions not yet answered. // Update internal store of results once saved to database. // Try to work out which questions are still incomplete. // Reload any raw answers that we have into the internal raw answer object. // We can only continue if we no longer have any incomplete questions.