public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/quiz/multi.php
/**
		 * Determine if the answers need to be randomized.
		 */
Determine if the answers need to be randomized.
Determine if the answers need to be randomized .
public function processAnswersWithRandomOption( $unit_id, $quiz_id ) {
			global $wpcwdb, $wpdb;
			$wpdb->show_errors();
			if ( ! $this->quizItem->question_multi_random_enable ) {
				return;
			}
			$currentUserID = get_current_user_id();
			$unitQuizProgress = WPCW_quizzes_getUserResultsForQuiz( $currentUserID, $unit_id, $quiz_id );
			$possibleAnswers = false;
						if ( $unitQuizProgress && $unitQuizProgress->quiz_grade < 0 ) {
				$possibleAnswers = $unitQuizProgress->quiz_data[ $this->quizItem->question_id ]['possible_answers'];
			}
			if ( $possibleAnswers ) {
				$possibleAnswers = maybe_unserialize( $possibleAnswers );
				$listCopy   = $this->answerListRaw;
				$newRawList = array();
				foreach ( $possibleAnswers as $key => $value ) {
					if ( isset( $listCopy[ $value ] ) ) {
						$newRawList[ $value ] = $listCopy[ $value ];
						unset( $listCopy[ $value ] );
					}
				}
				$this->answerListRaw = $newRawList;
			} else {
				$listCopy   = $this->answerListRaw;
				$newRawList = array();
				$correctAnswerIndexArray = @unserialize( $this->quizItem->question_correct_answer );
				if ( ! $correctAnswerIndexArray ) {
					$correctAnswerIndexArray = array( $this->quizItem->question_correct_answer );
				}
				foreach ( $correctAnswerIndexArray as $key => $value ) {
					if ( isset( $listCopy[ $value ] ) ) {
						$newRawList[ $value ] = $listCopy[ $value ];
						unset( $listCopy[ $value ] );
					}
				}
				srand( time() );
				while ( count( $newRawList ) < $this->quizItem->question_multi_random_count && ! empty( $listCopy ) ) {
					$randomKey = array_rand( $listCopy, 1 );
					$newRawList[ $randomKey ] = $listCopy[ $randomKey ];
					unset( $listCopy[ $randomKey ] );
				}
				srand();
				$newRawList = WPCW_arrays_shuffle_assoc( $newRawList );
				$this->answerListRaw = $newRawList;
			}
		}
public function processAnswersWithRandomOption ( $ unit_id , $ quiz_id ) { global $ wpcwdb , $ wpdb ; $ wpdb -> show_errors ( ) ; if ( ! $ this -> quizItem -> question_multi_random_enable ) { return ; } $ currentUserID = get_current_user_id ( ) ; $ unitQuizProgress = WPCW_quizzes_getUserResultsForQuiz ( $ currentUserID , $ unit_id , $ quiz_id ) ; $ possibleAnswers = false ; if ( $ unitQuizProgress && $ unitQuizProgress -> quiz_grade < 0 ) { $ possibleAnswers = $ unitQuizProgress -> quiz_data [ $ this -> quizItem -> question_id ] [ 'possible_answers' ] ; } if ( $ possibleAnswers ) { $ possibleAnswers = maybe_unserialize ( $ possibleAnswers ) ; $ listCopy = $ this -> answerListRaw ; $ newRawList = array ( ) ; foreach ( $ possibleAnswers as $ key => $ value ) { if ( isset ( $ listCopy [ $ value ] ) ) { $ newRawList [ $ value ] = $ listCopy [ $ value ] ; unset ( $ listCopy [ $ value ] ) ; } } $ this -> answerListRaw = $ newRawList ; } else { $ listCopy = $ this -> answerListRaw ; $ newRawList = array ( ) ; $ correctAnswerIndexArray = @ unserialize ( $ this -> quizItem -> question_correct_answer ) ; if ( ! $ correctAnswerIndexArray ) { $ correctAnswerIndexArray = array ( $ this -> quizItem -> question_correct_answer ) ; } foreach ( $ correctAnswerIndexArray as $ key => $ value ) { if ( isset ( $ listCopy [ $ value ] ) ) { $ newRawList [ $ value ] = $ listCopy [ $ value ] ; unset ( $ listCopy [ $ value ] ) ; } } srand ( time ( ) ) ; while ( count ( $ newRawList ) < $ this -> quizItem -> question_multi_random_count && ! empty ( $ listCopy ) ) { $ randomKey = array_rand ( $ listCopy , 1 ) ; $ newRawList [ $ randomKey ] = $ listCopy [ $ randomKey ] ; unset ( $ listCopy [ $ randomKey ] ) ; } srand ( ) ; $ newRawList = WPCW_arrays_shuffle_assoc ( $ newRawList ) ; $ this -> answerListRaw = $ newRawList ; } }
Determine if the answers need to be randomized.
Determine if the answers need to be randomized .
// Randomization is not needed. // Get current user ID // Get Quiz Details // Do we have progress yet?
 // Force the possible answers to be retrieved instead of providing a new random set //Need list copy to manipulate, as we don't want to modify the raw list just yet. // Need list copy to manipulate, as we don't want to modify the raw list just yet. // Extract the correct answer from the serialised array of the answers // Copy the right answer, and then remove from the source list // Set seed to the current user ID so that sequence is predictable. Don't really need a // lock for this. //srand(time() + get_current_user_id()); // Now we need to copy all the answers that the user wants. // Get a random item from the copy // Copy the right answer, and then remove from the source list // Randomize the ordering (reset the seed to something new) //srand(time()); // And update the raw list for rendering.