public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/functions.php
/**
 * Function to get all of the quiz details.
 *
 * @since 1.0.0
 *
 * @param integer $quizID The ID of the quiz for which we want to get details.
 * @param boolean $getQuestionsToo If true, get the questions for the quiz too.
 * @param boolean $resolveRandomQuestions If true, convert any randomised questions to live questions.
 * @param integer $userID The ID of the user to resolve the questions to.
 *
 * @return object The details of the quiz as an object.
 */
Function to get all of the quiz details.

@param integer $quizID The ID of the quiz for which we want to get details.
@param boolean $getQuestionsToo If true, get the questions for the quiz too.
@param boolean $resolveRandomQuestions If true, convert any randomised questions to live questions.
@param integer $userID The ID of the user to resolve the questions to.

@return object The details of the quiz as an object.
Function to get all of the quiz details . @param integer $quizID The ID of the quiz for which we want to get details . @param boolean $getQuestionsToo If true get the questions for the quiz too . @param boolean $resolveRandomQuestions If true convert any randomised questions to live questions . @param integer $userID The ID of the user to resolve the questions to . @return object The details of the quiz as an object .
function WPCW_quizzes_getQuizDetails( $quizID, $getQuestionsToo = false, $resolveRandomQuestions = false, $userID ) {
	if ( ! $quizID ) {
		return false;
	}
	global $wpcwdb, $wpdb;
	$wpdb->show_errors();
	$SQL = $wpdb->prepare( "SELECT *
			FROM $wpcwdb->quiz
			WHERE quiz_id = %d
			", $quizID );
	$quizObj = $wpdb->get_row( $SQL );
	if ( ! $quizObj ) {
		return false;
	}
	$quizObj->resolved_random_questions = $resolveRandomQuestions;
	if ( $getQuestionsToo ) {
		$quizObj->questions = WPCW_quizzes_getListOfQuestions( $quizObj->quiz_id );
		if ( $resolveRandomQuestions && $userID > 0 && ! empty( $quizObj->questions ) ) {
			$questionListToRender = array();
			foreach ( $quizObj->questions as $question ) {
				switch ( $question->question_type ) {
					case 'random_selection':
						$quObj    = new WPCW_quiz_RandomSelection( $question );
						$randList = $quObj->questionSelection_getLockedQuestionSelection( $userID, $quizObj->parent_unit_id );
						if ( ! empty( $randList ) ) {
							$questionListToRender += $randList;
						}
						break;
					case 'multi':
					case 'open':
					case 'upload':
					case 'truefalse':
						$questionListToRender[ $question->question_id ] = $question;
						break;
					default:
						die( __( 'Unexpected question type, aborting.', 'wp-courseware' ) );
						break;
				}
			}
			$quizObj->questions = $questionListToRender;
		}
	}
	$quizObj->has_open_questions = false;
	$quizObj->want_uploads = false;
	if ( ! empty( $quizObj->questions ) ) {
		foreach ( $quizObj->questions as $quizID => $quizItem ) {
			if ( 'upload' == $quizItem->question_type ) {
				$quizObj->want_uploads       = true;
				$quizObj->has_open_questions = true;
				break;
			}
		}
		if ( ! $quizObj->has_open_questions ) {
			foreach ( $quizObj->questions as $quizID => $quizItem ) {
				if ( 'open' == $quizItem->question_type ) {
					$quizObj->has_open_questions = true;
					break;
				}
			}
		}
	}
	return $quizObj;
}
function WPCW_quizzes_getQuizDetails ( $ quizID , $ getQuestionsToo = false , $ resolveRandomQuestions = false , $ userID ) { if ( ! $ quizID ) { return false ; } global $ wpcwdb , $ wpdb ; $ wpdb -> show_errors ( ) ; $ SQL = $ wpdb -> prepare ( " SELECT *
			FROM  $ wpcwdb -> quiz 
			WHERE quiz_id = %d
			 " , $ quizID ) ; $ quizObj = $ wpdb -> get_row ( $ SQL ) ; if ( ! $ quizObj ) { return false ; } $ quizObj -> resolved_random_questions = $ resolveRandomQuestions ; if ( $ getQuestionsToo ) { $ quizObj -> questions = WPCW_quizzes_getListOfQuestions ( $ quizObj -> quiz_id ) ; if ( $ resolveRandomQuestions && $ userID > 0 && ! empty ( $ quizObj -> questions ) ) { $ questionListToRender = array ( ) ; foreach ( $ quizObj -> questions as $ question ) { switch ( $ question -> question_type ) { case 'random_selection' : $ quObj = new WPCW_quiz_RandomSelection ( $ question ) ; $ randList = $ quObj -> questionSelection_getLockedQuestionSelection ( $ userID , $ quizObj -> parent_unit_id ) ; if ( ! empty ( $ randList ) ) { $ questionListToRender += $ randList ; } break ; case 'multi' : case 'open' : case 'upload' : case 'truefalse' : $ questionListToRender [ $ question -> question_id ] = $ question ; break ; default : die ( __ ( 'Unexpected question type, aborting.' , 'wp-courseware' ) ) ; break ; } } $ quizObj -> questions = $ questionListToRender ; } } $ quizObj -> has_open_questions = false ; $ quizObj -> want_uploads = false ; if ( ! empty ( $ quizObj -> questions ) ) { foreach ( $ quizObj -> questions as $ quizID => $ quizItem ) { if ( 'upload' == $ quizItem -> question_type ) { $ quizObj -> want_uploads = true ; $ quizObj -> has_open_questions = true ; break ; } } if ( ! $ quizObj -> has_open_questions ) { foreach ( $ quizObj -> questions as $ quizID => $ quizItem ) { if ( 'open' == $ quizItem -> question_type ) { $ quizObj -> has_open_questions = true ; break ; } } } } return $ quizObj ; }
Function to get all of the quiz details.
Function to get all of the quiz details .
// Add flag indicating if random questions are resolved or not. // Something found, so return the questions for this quiz too. // Check if we need to expand any random questions // Got a random selection - extract these questions // Append the random questions. // Got a standard question // Not expecting anything here... so not handling the error case. // Overwrite existing questions // Simple flag to see if we have open questions or not. // Are we expecting any uploads? If so, set a flag to make answer processing faster. // We're searching for an upload anyway, so check for an open question // Not found an open question yet even though we checked for uploads. // Look for an open question (already checked uploads). This s // saves some computation time.