public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/classes/unitfrontend.php
/**
		 * Fetch the answer data and clean it up based on the type of question.
		 *
		 * @param Array $potentialAnswers The potential answers that need checking.
		 *
		 * @return Array A list of the results.
		 */
Fetch the answer data and clean it up based on the type of question.
@param Array $potentialAnswers The potential answers that need checking.

@return Array A list of the results.
Fetch the answer data and clean it up based on the type of question . @param Array $potentialAnswers The potential answers that need checking . @return Array A list of the results .
public function check_quizzes_canWeContinue_extractAnswerData( $potentialAnswers ) {
			$resultsList = array(
				'answer_list'       => array(),
				'wrong_answer_list' => array(),
				'error_answer_list' => array(),
				'all_answer_list'   => array(),
			);
			foreach ( $potentialAnswers as $key => $value ) {
				if ( preg_match( '/^answer_(\d+)_([a-z]+)_(\d+)$/', $key, $matches ) ) {
					$answersID = $matches[3];
					foreach ( $value as $key => $val ) {
						$resultsList['all_answer_list'][ $answersID ][] = WPCW_quiz_MultipleChoice::sanitizeAnswerData( $val );
					}
				}
				if ( preg_match( '/^question_(\d+)_([a-z]+)_(\d+)$/', $key, $matches ) ) {
					$quizID       = $matches[1];
					$questionID   = $matches[3];
					$questionType = $matches[2];
					if ( $quizID != $this->unitQuizDetails->quiz_id ) {
						continue;
					}
					switch ( $questionType ) {
						case 'multi':
							if ( ! is_array( $value ) ) {
								$value = array( $value );
							}
							foreach ( $value as $key => $val ) {
								$resultsList['answer_list'][ $questionID ][] = WPCW_quiz_MultipleChoice::sanitizeAnswerData( $val );
							}
							break;
						case 'truefalse':
							$resultsList['answer_list'][ $questionID ] = WPCW_quiz_TrueFalse::sanitizeAnswerData( $value );
							break;
						case 'open':
							$resultsList['answer_list'][ $questionID ] = WPCW_quiz_OpenEntry::sanitizeAnswerData( $value );
							break;
						case 'upload':
							break;
					}
				} 
			} 
			if ( $this->unitQuizDetails->want_uploads ) {
				$uploadResultList = WPCW_quiz_FileUpload::validateFiles( $_FILES, $this->unitQuizDetails );
				if ( count( $uploadResultList['upload_valid'] ) > 0 ) {
					$resultsList['answer_list'] = $resultsList['answer_list'] + $uploadResultList['upload_valid'];
				}
				if ( count( $uploadResultList['upload_errors'] ) > 0 ) {
					$resultsList['error_answer_list'] = $resultsList['error_answer_list'] + $uploadResultList['upload_errors'];
				}
			}
			return $resultsList;
		}
public function check_quizzes_canWeContinue_extractAnswerData ( $ potentialAnswers ) { $ resultsList = array ( 'answer_list' => array ( ) , 'wrong_answer_list' => array ( ) , 'error_answer_list' => array ( ) , 'all_answer_list' => array ( ) , ) ; foreach ( $ potentialAnswers as $ key => $ value ) { if ( preg_match ( '/^answer_(\d+)_([a-z]+)_(\d+)$/' , $ key , $ matches ) ) { $ answersID = $ matches [ 3 ] ; foreach ( $ value as $ key => $ val ) { $ resultsList [ 'all_answer_list' ] [ $ answersID ] [ ] = WPCW_quiz_MultipleChoice :: sanitizeAnswerData ( $ val ) ; } } if ( preg_match ( '/^question_(\d+)_([a-z]+)_(\d+)$/' , $ key , $ matches ) ) { $ quizID = $ matches [ 1 ] ; $ questionID = $ matches [ 3 ] ; $ questionType = $ matches [ 2 ] ; if ( $ quizID != $ this -> unitQuizDetails -> quiz_id ) { continue ; } switch ( $ questionType ) { case 'multi' : if ( ! is_array ( $ value ) ) { $ value = array ( $ value ) ; } foreach ( $ value as $ key => $ val ) { $ resultsList [ 'answer_list' ] [ $ questionID ] [ ] = WPCW_quiz_MultipleChoice :: sanitizeAnswerData ( $ val ) ; } break ; case 'truefalse' : $ resultsList [ 'answer_list' ] [ $ questionID ] = WPCW_quiz_TrueFalse :: sanitizeAnswerData ( $ value ) ; break ; case 'open' : $ resultsList [ 'answer_list' ] [ $ questionID ] = WPCW_quiz_OpenEntry :: sanitizeAnswerData ( $ value ) ; break ; case 'upload' : break ; } } } if ( $ this -> unitQuizDetails -> want_uploads ) { $ uploadResultList = WPCW_quiz_FileUpload :: validateFiles ( $ _FILES , $ this -> unitQuizDetails ) ; if ( count ( $ uploadResultList [ 'upload_valid' ] ) > 0 ) { $ resultsList [ 'answer_list' ] = $ resultsList [ 'answer_list' ] + $ uploadResultList [ 'upload_valid' ] ; } if ( count ( $ uploadResultList [ 'upload_errors' ] ) > 0 ) { $ resultsList [ 'error_answer_list' ] = $ resultsList [ 'error_answer_list' ] + $ uploadResultList [ 'upload_errors' ] ; } } return $ resultsList ; }
Fetch the answer data and clean it up based on the type of question.
Fetch the answer data and clean it up based on the type of question .
// #### 1 - Extract a list of actual answers from the potential answers. There will // be some noise in that data. Check the raw data to see what questions we have. // Identify all possible answer ID's // Only considering answers to questions. Format of answer field is: // question_16_truefalse_48 (first ID is quiz, 2nd ID is question, middle string // is the question type. // Again, check that answer matches quiz we're expecting. // Probably a little paranoid, but it's worth checking // to ensure there's nothing naughty going on. // Clean up the submitted data based on the type of quiz using the static checks in each // of the questions (to save loading whole class). If the data is valid, add the valid // answer to the list of fully validate danswers. //Added the value to array to validate mulipal answers of the quiz. // Ignore uploads as a $_POST field, simply because the files should be stored in $_FILES // not in $_POST. So if we have a file in $_FILES, that's clearly an issue. // end of question check // end of potential answers loop // ### 2 - Check for file uploads if the quiz requires them. Only check for uploads // if the quiz details say there should be some uploads. // Merge the valid results. // Basically if a file has been uploaded correctly, that answer is marked as being set. // Merge the error results