public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/classes/import.php
/**
		 * Create the associations of the questions
		 *
		 * @param Object $singleQuiz The quiz details to check for questions.
		 */
Create the associations of the questions
@param Object $singleQuiz The quiz details to check for questions.
Create the associations of the questions @param Object $singleQuiz The quiz details to check for questions .
public function loadQuizData_addQuestionsAssociations( $singleQuiz ) {
			if ( ! isset( $singleQuiz['questions'] ) || empty( $singleQuiz['questions'] ) ) {
				return false;
			}
			usort( $singleQuiz['questions'], array( $this, 'sortQuestionsByOrder' ) );
			global $wpdb, $wpcwdb;
			$wpdb->show_errors();
			$questionOrder = 0;
			foreach ( $singleQuiz['questions'] as $singleQuestionToAdd ) {
				if ( 'fixed' == $singleQuestionToAdd['question_type'] ) {
					if ( $singleQuestionToAdd['question_real_id'] ) {
						$wpdb->query( $wpdb->prepare( "
						INSERT INTO $wpcwdb->quiz_qs_mapping
						(question_id, parent_quiz_id, question_order)
						VALUES (%d, %d, %d)
					", $singleQuestionToAdd['question_real_id'], $singleQuiz['quiz_id'], $questionOrder ++ ) );
						WPCW_questions_updateUsageCount( $singleQuestionToAdd['question_real_id'] );
											}
				}
				else {
					$toSaveList = array();
					if ( ! empty( $singleQuestionToAdd['tag_selections'] ) ) {
						$totalNumberOfSelections = 0;
						foreach ( $singleQuestionToAdd['tag_selections'] as $tagName => $selectionCount ) {
							if ( 'whole_pool' == $tagName ) {
								$toSaveList[ $tagName ] = $selectionCount;
								$totalNumberOfSelections += $selectionCount;
							} 
							else {
								$tagDetails = WPCW_questions_tags_getTagDetails_byName( $tagName );
								if ( $tagDetails ) {
									$toSaveList[ 'tag_' . $tagDetails->question_tag_id ] = $selectionCount;
									$totalNumberOfSelections += $selectionCount;
								}
							} 
						} 
						$wpdb->query( $wpdb->prepare( "
						INSERT INTO $wpcwdb->quiz_qs
						(question_type, question_question, question_usage_count, question_expanded_count)
						VALUES ('random_selection', %s, 1, %d)
					", json_encode( $toSaveList ), $totalNumberOfSelections ) );
						$newSelectionQuestionID = $wpdb->insert_id;
						$wpdb->query( $wpdb->prepare( "
						INSERT INTO $wpcwdb->quiz_qs_mapping
						(question_id, parent_quiz_id, question_order)
						VALUES (%d, %d, %d)
					", $newSelectionQuestionID, $singleQuiz['quiz_id'], $questionOrder ++ ) );
					} 
				} 
			}
		}
public function loadQuizData_addQuestionsAssociations ( $ singleQuiz ) { if ( ! isset ( $ singleQuiz [ 'questions' ] ) || empty ( $ singleQuiz [ 'questions' ] ) ) { return false ; } usort ( $ singleQuiz [ 'questions' ] , array ( $ this , 'sortQuestionsByOrder' ) ) ; global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; $ questionOrder = 0 ; foreach ( $ singleQuiz [ 'questions' ] as $ singleQuestionToAdd ) { if ( 'fixed' == $ singleQuestionToAdd [ 'question_type' ] ) { if ( $ singleQuestionToAdd [ 'question_real_id' ] ) { $ wpdb -> query ( $ wpdb -> prepare ( " 
						INSERT INTO  $ wpcwdb -> quiz_qs_mapping 
						(question_id, parent_quiz_id, question_order)
						VALUES (%d, %d, %d)
					 " , $ singleQuestionToAdd [ 'question_real_id' ] , $ singleQuiz [ 'quiz_id' ] , $ questionOrder ++ ) ) ; WPCW_questions_updateUsageCount ( $ singleQuestionToAdd [ 'question_real_id' ] ) ; } } else { $ toSaveList = array ( ) ; if ( ! empty ( $ singleQuestionToAdd [ 'tag_selections' ] ) ) { $ totalNumberOfSelections = 0 ; foreach ( $ singleQuestionToAdd [ 'tag_selections' ] as $ tagName => $ selectionCount ) { if ( 'whole_pool' == $ tagName ) { $ toSaveList [ $ tagName ] = $ selectionCount ; $ totalNumberOfSelections += $ selectionCount ; } else { $ tagDetails = WPCW_questions_tags_getTagDetails_byName ( $ tagName ) ; if ( $ tagDetails ) { $ toSaveList [ 'tag_' . $ tagDetails -> question_tag_id ] = $ selectionCount ; $ totalNumberOfSelections += $ selectionCount ; } } } $ wpdb -> query ( $ wpdb -> prepare ( " 
						INSERT INTO  $ wpcwdb -> quiz_qs 
						(question_type, question_question, question_usage_count, question_expanded_count)
						VALUES ('random_selection', %s, 1, %d)
					 " , json_encode ( $ toSaveList ) , $ totalNumberOfSelections ) ) ; $ newSelectionQuestionID = $ wpdb -> insert_id ; $ wpdb -> query ( $ wpdb -> prepare ( " 
						INSERT INTO  $ wpcwdb -> quiz_qs_mapping 
						(question_id, parent_quiz_id, question_order)
						VALUES (%d, %d, %d)
					 " , $ newSelectionQuestionID , $ singleQuiz [ 'quiz_id' ] , $ questionOrder ++ ) ) ; } } } }
Create the associations of the questions
 @param Object $singleQuiz The quiz details to check for questions.
Create the associations of the questions @param Object $singleQuiz The quiz details to check for questions .
// No questons to worry about // ### 1 - Ensure the questions are ordered correctly. // ### 2 - Need to now do the question mapping for this quiz. // ### 3 - Fixed - questions are a simple association. // Only do association if ID is valid // ### 4 - Update the mapping counts now that we've added all of the questions. // DEFERRED - Report an error here if real ID is invalid?
 // ### 4 - Random - questions need a little more work to create these. We essentially // add a new question, then map it to the parent quiz. // ### 5 - Check each selection // This is the simple one. Assume that selection counts are valid. // Need to keep track of how many questions there might be. // Right, we have a tag. We need to get it's ID. // Effectively we'll validate the tags here. // Need to create tag_11 => count // Need to keep track of how many questions there might be. // end of selection type // end of loop for tag selections // ### 6 - Now add the question to the database. Usage count is always 1, as we're only //         creating this for this quiz. // ### 7 - Now associate with the parent quiz. // end of check for tag selections // end check of question type.