public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/quiz/random.php
/**
		 * Randomly choose from all of the questions available based on these tags, limited by how many
		 * is requested per tag based on selections in dialog box.
		 *
		 * @param Array $tagDetails The list of tag details that we want to use.
		 *
		 * @return Array The list of questions to render for as part of a random selection.
		 */
Randomly choose from all of the questions available based on these tags, limited by how many
is requested per tag based on selections in dialog box.

@param Array $tagDetails The list of tag details that we want to use.

@return Array The list of questions to render for as part of a random selection.
Randomly choose from all of the questions available based on these tags limited by how many is requested per tag based on selections in dialog box . @param Array $tagDetails The list of tag details that we want to use . @return Array The list of questions to render for as part of a random selection .
public static function questionSelection_getRandomQuestionsFromTags( $tagDetails ) {
			$questionsToUse = array();
			if ( ! empty( $tagDetails ) ) {
				global $wpcwdb, $wpdb;
				$wpdb->show_errors();
				foreach ( $tagDetails as $singleTag => $singleTagDetails ) {
					$questionList = false;
					if ( 'whole_pool' == $singleTag ) {
						$questionList = $wpdb->get_results( $wpdb->prepare( "
						SELECT *
						FROM $wpcwdb->quiz_qs qq
						WHERE qq.question_type != 'random_selection'
						ORDER BY RAND()
						LIMIT %d
					", $singleTagDetails['count'] ) );
					} 
					else {
						$questionList = $wpdb->get_results( $wpdb->prepare( "
						SELECT *
						FROM $wpcwdb->quiz_qs qq
							LEFT JOIN $wpcwdb->question_tag_mapping qtm ON qtm.question_id = qq.question_id
						WHERE tag_id = %d
						AND qq.question_type != 'random_selection'
						ORDER BY RAND()
						LIMIT %d
					", $singleTagDetails['tag_id'], $singleTagDetails['count'] ) );
					}
					if ( ! empty( $questionList ) ) {
						foreach ( $questionList as $questionDetails ) {
							$questionsToUse[ $questionDetails->question_id ] = $questionDetails;
						}
					}
				}
				if ( ! empty( $questionsToUse ) ) {
					$shuffleKeys = array_keys( $questionsToUse );
					shuffle( $shuffleKeys );
					$questionsToUse_shuffled = array();
					foreach ( $shuffleKeys as $key ) {
						$questionsToUse_shuffled[ $key ] = $questionsToUse[ $key ];
					}
					$questionsToUse = $questionsToUse_shuffled;
				}
			} 
			return $questionsToUse;
		}
public static function questionSelection_getRandomQuestionsFromTags ( $ tagDetails ) { $ questionsToUse = array ( ) ; if ( ! empty ( $ tagDetails ) ) { global $ wpcwdb , $ wpdb ; $ wpdb -> show_errors ( ) ; foreach ( $ tagDetails as $ singleTag => $ singleTagDetails ) { $ questionList = false ; if ( 'whole_pool' == $ singleTag ) { $ questionList = $ wpdb -> get_results ( $ wpdb -> prepare ( " 
						SELECT *
						FROM  $ wpcwdb -> quiz_qs  qq
						WHERE qq.question_type != 'random_selection'
						ORDER BY RAND()
						LIMIT %d
					 " , $ singleTagDetails [ 'count' ] ) ) ; } else { $ questionList = $ wpdb -> get_results ( $ wpdb -> prepare ( " 
						SELECT *
						FROM  $ wpcwdb -> quiz_qs  qq
							LEFT JOIN  $ wpcwdb -> question_tag_mapping  qtm ON qtm.question_id = qq.question_id
						WHERE tag_id = %d
						AND qq.question_type != 'random_selection'
						ORDER BY RAND()
						LIMIT %d
					 " , $ singleTagDetails [ 'tag_id' ] , $ singleTagDetails [ 'count' ] ) ) ; } if ( ! empty ( $ questionList ) ) { foreach ( $ questionList as $ questionDetails ) { $ questionsToUse [ $ questionDetails -> question_id ] = $ questionDetails ; } } } if ( ! empty ( $ questionsToUse ) ) { $ shuffleKeys = array_keys ( $ questionsToUse ) ; shuffle ( $ shuffleKeys ) ; $ questionsToUse_shuffled = array ( ) ; foreach ( $ shuffleKeys as $ key ) { $ questionsToUse_shuffled [ $ key ] = $ questionsToUse [ $ key ] ; } $ questionsToUse = $ questionsToUse_shuffled ; } } return $ questionsToUse ; }
Randomly choose from all of the questions available based on these tags, limited by how many
 is requested per tag based on selections in dialog box.
Randomly choose from all of the questions available based on these tags limited by how many is requested per tag based on selections in dialog box .
// Whole pool // Get the count number of questions from whole pool // Tags - normal // Get the count number of questions that have the specified tag. // Got some questions in this selection, so add to the main list. // Using question ID, so that any duplicate questions get unified // by using the same question key. // If we have multiple tags, questions will only be random per tag due to the SQL sort, so // randomize the questions here to mix them up between tags. // Shuffle/randomize - but preserving keys (shuffle() doesn't by default). // end if we have tag details.