public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/classes/export.php
/**
		 * Handle exporting the XML for all of the questions.
		 *
		 * @param String The XML for the quiz in this unit.
		 */
Handle exporting the XML for all of the questions.
@param String The XML for the quiz in this unit.
Handle exporting the XML for all of the questions . @param String The XML for the quiz in this unit .
public function export_content_handleQuestionsAndTags() {
			$xml = false;
			if ( empty( $this->questionList ) ) {
				return $xml;
			}
			$questionIDListForExpanding = $this->questionList;
			foreach ( $questionIDListForExpanding as $questionID => $singleQuestionDetails ) {
				if ( 'random_selection' == $singleQuestionDetails->question_type ) {
					$decodedTags = WPCW_quiz_RandomSelection::decodeTagSelection( $singleQuestionDetails->question_question );
					if ( ! empty( $decodedTags ) ) {
												$questionsForTag = WPCW_quiz_RandomSelection::questionSelection_getAllQuestionsFromTags( $decodedTags );
						if ( ! empty( $questionsForTag ) ) {
							$this->questionList = $this->questionList + $questionsForTag;
						}
					}
					unset( $this->questionList[ $questionID ] );
				} 
			}
			global $fieldsToProcess_quizzes, $fieldsToProcess_quiz_questions;
			$questionParentPath = '/questions';
			$newQuestionIndex = 1;
			foreach ( $this->questionList as $questionID => $singleQuestionDetails ) {
				$questionDetails = WPCW_questions_getQuestionDetails( $questionID, true );
				if ( ! $questionDetails ) {
					continue;
				}
				$this->questionList[ $questionID ]->question_hash = $questionDetails->question_hash = 'wpcwqid_' . $newQuestionIndex;
				$newQuestionIndex                                 += 2; 
				$xml .= $this->export_objectToXML( 'question', false, $questionDetails, $fieldsToProcess_quiz_questions, $questionParentPath, false );
				$questionDetails->question_data_answers = maybe_unserialize( $questionDetails->question_data_answers );
				$questionidx = 1;
				if ( ! empty( $questionDetails->question_data_answers ) && is_array( $questionDetails->question_data_answers ) ) {
					$dataToBeExported = array();
					foreach ( $questionDetails->question_data_answers as $idx => $details ) {
						$dataToBeExported[ 'possible_answer_' . $questionidx ] = $details['answer'];
						if ( isset( $details['image'] ) ) {
							$dataToBeExported[ 'possible_answer_' . $questionidx . '_image' ] = $details['image'];
						}
						$questionidx ++;
					}
					$xml .= $this->export_arrayToXML( 'question_data_answers', false, $dataToBeExported, false, $questionParentPath . '/question', '/question_data_answers' );
				}
				if ( ! empty( $questionDetails->tags ) ) {
					$tagParentPath = $questionParentPath . '/question';
					$xml           .= $this->export_startBlock( $tagParentPath, 'tags' );
					foreach ( $questionDetails->tags as $singleTag ) {
						$xml .= $this->export_textData( 'tag', $singleTag->question_tag_name, $tagParentPath . '/tags/' );
					}
					$xml .= $this->export_endBlock( $questionParentPath . '/question', 'tags' );
				}
				$xml .= $this->export_endBlock( $questionParentPath, 'question' );
				flush();
			}
			return $xml;
		}
public function export_content_handleQuestionsAndTags ( ) { $ xml = false ; if ( empty ( $ this -> questionList ) ) { return $ xml ; } $ questionIDListForExpanding = $ this -> questionList ; foreach ( $ questionIDListForExpanding as $ questionID => $ singleQuestionDetails ) { if ( 'random_selection' == $ singleQuestionDetails -> question_type ) { $ decodedTags = WPCW_quiz_RandomSelection :: decodeTagSelection ( $ singleQuestionDetails -> question_question ) ; if ( ! empty ( $ decodedTags ) ) { $ questionsForTag = WPCW_quiz_RandomSelection :: questionSelection_getAllQuestionsFromTags ( $ decodedTags ) ; if ( ! empty ( $ questionsForTag ) ) { $ this -> questionList = $ this -> questionList + $ questionsForTag ; } } unset ( $ this -> questionList [ $ questionID ] ) ; } } global $ fieldsToProcess_quizzes , $ fieldsToProcess_quiz_questions ; $ questionParentPath = '/questions' ; $ newQuestionIndex = 1 ; foreach ( $ this -> questionList as $ questionID => $ singleQuestionDetails ) { $ questionDetails = WPCW_questions_getQuestionDetails ( $ questionID , true ) ; if ( ! $ questionDetails ) { continue ; } $ this -> questionList [ $ questionID ] -> question_hash = $ questionDetails -> question_hash = 'wpcwqid_' . $ newQuestionIndex ; $ newQuestionIndex += 2 ; $ xml .= $ this -> export_objectToXML ( 'question' , false , $ questionDetails , $ fieldsToProcess_quiz_questions , $ questionParentPath , false ) ; $ questionDetails -> question_data_answers = maybe_unserialize ( $ questionDetails -> question_data_answers ) ; $ questionidx = 1 ; if ( ! empty ( $ questionDetails -> question_data_answers ) && is_array ( $ questionDetails -> question_data_answers ) ) { $ dataToBeExported = array ( ) ; foreach ( $ questionDetails -> question_data_answers as $ idx => $ details ) { $ dataToBeExported [ 'possible_answer_' . $ questionidx ] = $ details [ 'answer' ] ; if ( isset ( $ details [ 'image' ] ) ) { $ dataToBeExported [ 'possible_answer_' . $ questionidx . '_image' ] = $ details [ 'image' ] ; } $ questionidx ++ ; } $ xml .= $ this -> export_arrayToXML ( 'question_data_answers' , false , $ dataToBeExported , false , $ questionParentPath . '/question' , '/question_data_answers' ) ; } if ( ! empty ( $ questionDetails -> tags ) ) { $ tagParentPath = $ questionParentPath . '/question' ; $ xml .= $ this -> export_startBlock ( $ tagParentPath , 'tags' ) ; foreach ( $ questionDetails -> tags as $ singleTag ) { $ xml .= $ this -> export_textData ( 'tag' , $ singleTag -> question_tag_name , $ tagParentPath . '/tags/' ) ; } $ xml .= $ this -> export_endBlock ( $ questionParentPath . '/question' , 'tags' ) ; } $ xml .= $ this -> export_endBlock ( $ questionParentPath , 'question' ) ; flush ( ) ; } return $ xml ; }
Handle exporting the XML for all of the questions.
Handle exporting the XML for all of the questions .
// Copied so we can update the master list only without adding to the work that this loop does. // ### Expand Random Questions - If we have any random questions - we need all questions that they use. // We've got a random selection, so we need to get all questions that fall into this // particular selection, and remove this random selection before it's exported. // Expand the tags into an array. // Got any questions for these tags?
 // Yep, so add them to the list, ignoring duplicates. // If we have a whole pool flag, then we need to get all questions that exist. But this code // doesn't check for the whole pool flag, as this export is an expensive process anyway, so // for simplicity, we're not checking for the single exception. // Now remove this question, as it's a random question that can't be exported. // end if random selection check // Check question is valid - just in case. // Create a new hash for this question ID for the XML file so that we can map // questions to quizzes. Intentionally using odd numbers only, to help with spotting // any potential errors with import. // Increment by 2, to allow us to spot issues. // ### Question - Start // Debug - check we have all the right fields for this question //$this->debug_courseCheckFieldsWeHave($questionDetails, $fieldsToProcess_quiz_questions); // ### Questions - question_data_answers // Handle the serialized 'question_data_answers' field e.g. /*
				 [question_data_answers] => Array
					 (
						[1] => Array
						(
							[answer] => RHJpenpsZQ==
						)

							[2] => Array
								(
									[answer] => RHJpcA==
								)

							[3] => Array
								(
									[answer] => Q2xvdWRidXJzdA==
								)

							[4] => Array
								(
									[answer] => Q2F0cyAmIERvZ3M=
								)

						)
					 */ // Use this to numerically order the answers // Do we have an image for this answer? If so, then add it with it's own tag for simplcity. // ###�Question - Tags - Start // Render tags as question->tags->tag // ###�Question - Tags - End // ### Question - End