public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/classes/export.php
/**
		 * Handle exporting the XML for a quiz within a single unit.
		 *
		 * @param Object $unitObj The unit with a quiz to export.
		 * @param String $unitParentPath The parent path for the unit.
		 *
		 * @param        String          The XML for the quiz in this unit.
		 */
Handle exporting the XML for a quiz within a single unit.
@param Object $unitObj The unit with a quiz to export.
@param String $unitParentPath The parent path for the unit.

@param        String          The XML for the quiz in this unit.
Handle exporting the XML for a quiz within a single unit . @param Object $unitObj The unit with a quiz to export . @param String $unitParentPath The parent path for the unit . @param String The XML for the quiz in this unit .
public function export_content_handleQuizzes( $unitObj, $unitParentPath ) {
			$xml = false;
			global $fieldsToProcess_quizzes, $fieldsToProcess_quiz_questions;
			if ( isset( $unitObj->extradata_quiz_details ) && ! empty( $unitObj->extradata_quiz_details ) ) {
				$quizObj = $unitObj->extradata_quiz_details;
				$quizzesParentPath = $unitParentPath . '/quizzes';
				$xml               .= $this->export_startBlock( $quizzesParentPath, 'quizzes' );
				$quizParentPath = $quizzesParentPath . '/quiz';
				$xml .= $this->export_objectToXML( 'quiz', false, $quizObj, $fieldsToProcess_quizzes, $quizParentPath, false );
				$quizObj->show_answers_settings = maybe_unserialize( $quizObj->show_answers_settings );
				if ( ! empty( $quizObj->show_answers_settings ) && is_array( $quizObj->show_answers_settings ) ) {
					$innerPath = $quizParentPath . '/show_answers_settings';
					$xml       .= $this->export_arrayToXML( 'show_answers_settings', false, $quizObj->show_answers_settings, false, $innerPath, '/show_answers_settings' );
				}
				$quizObj->quiz_paginate_questions_settings = maybe_unserialize( $quizObj->quiz_paginate_questions_settings );
				if ( ! empty( $quizObj->quiz_paginate_questions_settings ) && is_array( $quizObj->quiz_paginate_questions_settings ) ) {
					$innerPath = $quizParentPath . '/quiz_paginate_questions_settings';
					$xml       .= $this->export_arrayToXML( 'quiz_paginate_questions_settings', false, $quizObj->quiz_paginate_questions_settings, false, $innerPath, '/quiz_paginate_questions_settings' );
				}
				$questionsParentPath = $quizParentPath . '/questions';
				$xml                 .= $this->export_startBlock( $questionsParentPath, 'questions' );
				$questionParentPath = $questionsParentPath . '/question';
				$tagSelectionsPath  = $questionParentPath . '/tag_selections/';
				$tagSelectionPath   = $tagSelectionsPath . '/tag_selection';
				if ( ! empty( $quizObj->questions ) ) {
					$questionOrder = 1;
					foreach ( $quizObj->questions as $singleQuestion ) {
						if ( 'random_selection' == $singleQuestion->question_type ) {
							$questionDetailsByHash = array(
								'question_type'  => 'random_selection',
								'question_order' => $questionOrder ++,
							);
							$xml .= $this->export_arrayToXML( 'question', false, $questionDetailsByHash, false, $questionsParentPath . '/', false );
							$xml .= $this->export_startBlock( $questionParentPath . '/', 'tag_selections' );
							$decodedTags = WPCW_quiz_RandomSelection::decodeTagSelection( $singleQuestion->question_question );
							if ( ! empty( $decodedTags ) ) {
								foreach ( $decodedTags as $tagType => $tagDetails ) {
									if ( 'whole_pool' == $tagType ) {
										$xml .= $this->export_textDataWithAttributes( 'tag_selection', 'whole_pool', $tagSelectionPath, array( 'count' => $tagDetails['count'] ) );
									} 
									else {
										$xml .= $this->export_textDataWithAttributes( 'tag_selection', $tagDetails['name'], $tagSelectionPath, array( 'count' => $tagDetails['count'] ) );
									}
								}
							}
							$xml .= $this->export_endBlock( $questionParentPath . '/', 'tag_selections' );
							$xml .= $this->export_endBlock( $questionsParentPath . '/', 'question' );
						} 
						else {
							if ( isset( $this->questionList[ $singleQuestion->question_id ] ) ) {
								$storedQuestionDetails = $this->questionList[ $singleQuestion->question_id ];
								$questionDetailsByHash = array(
									'question_type'  => 'fixed',
									'question_hash'  => $storedQuestionDetails->question_hash,
									'question_order' => $questionOrder ++,
								);
								$xml .= $this->export_arrayToXML( 'question', false, $questionDetailsByHash, false, $questionParentPath, '/question' );
							} 
							else {
								error_log( __( 'Error exporting question in quiz.', 'wp-courseware' ) . '(' . print_r( $singleQuestion, true ) . ')' );
							}
						} 
					} 
				}
				$xml .= $this->export_endBlock( $questionsParentPath, 'questions' );
				$xml .= $this->export_content_handleQuizzes_customFeedbackMessages( $quizObj, $quizParentPath );
				$xml .= $this->export_endBlock( $quizParentPath, 'quiz' );
				$xml .= $this->export_endBlock( $quizzesParentPath, 'quizzes' );
			}
			return $xml;
		}
public function export_content_handleQuizzes ( $ unitObj , $ unitParentPath ) { $ xml = false ; global $ fieldsToProcess_quizzes , $ fieldsToProcess_quiz_questions ; if ( isset ( $ unitObj -> extradata_quiz_details ) && ! empty ( $ unitObj -> extradata_quiz_details ) ) { $ quizObj = $ unitObj -> extradata_quiz_details ; $ quizzesParentPath = $ unitParentPath . '/quizzes' ; $ xml .= $ this -> export_startBlock ( $ quizzesParentPath , 'quizzes' ) ; $ quizParentPath = $ quizzesParentPath . '/quiz' ; $ xml .= $ this -> export_objectToXML ( 'quiz' , false , $ quizObj , $ fieldsToProcess_quizzes , $ quizParentPath , false ) ; $ quizObj -> show_answers_settings = maybe_unserialize ( $ quizObj -> show_answers_settings ) ; if ( ! empty ( $ quizObj -> show_answers_settings ) && is_array ( $ quizObj -> show_answers_settings ) ) { $ innerPath = $ quizParentPath . '/show_answers_settings' ; $ xml .= $ this -> export_arrayToXML ( 'show_answers_settings' , false , $ quizObj -> show_answers_settings , false , $ innerPath , '/show_answers_settings' ) ; } $ quizObj -> quiz_paginate_questions_settings = maybe_unserialize ( $ quizObj -> quiz_paginate_questions_settings ) ; if ( ! empty ( $ quizObj -> quiz_paginate_questions_settings ) && is_array ( $ quizObj -> quiz_paginate_questions_settings ) ) { $ innerPath = $ quizParentPath . '/quiz_paginate_questions_settings' ; $ xml .= $ this -> export_arrayToXML ( 'quiz_paginate_questions_settings' , false , $ quizObj -> quiz_paginate_questions_settings , false , $ innerPath , '/quiz_paginate_questions_settings' ) ; } $ questionsParentPath = $ quizParentPath . '/questions' ; $ xml .= $ this -> export_startBlock ( $ questionsParentPath , 'questions' ) ; $ questionParentPath = $ questionsParentPath . '/question' ; $ tagSelectionsPath = $ questionParentPath . '/tag_selections/' ; $ tagSelectionPath = $ tagSelectionsPath . '/tag_selection' ; if ( ! empty ( $ quizObj -> questions ) ) { $ questionOrder = 1 ; foreach ( $ quizObj -> questions as $ singleQuestion ) { if ( 'random_selection' == $ singleQuestion -> question_type ) { $ questionDetailsByHash = array ( 'question_type' => 'random_selection' , 'question_order' => $ questionOrder ++ , ) ; $ xml .= $ this -> export_arrayToXML ( 'question' , false , $ questionDetailsByHash , false , $ questionsParentPath . '/' , false ) ; $ xml .= $ this -> export_startBlock ( $ questionParentPath . '/' , 'tag_selections' ) ; $ decodedTags = WPCW_quiz_RandomSelection :: decodeTagSelection ( $ singleQuestion -> question_question ) ; if ( ! empty ( $ decodedTags ) ) { foreach ( $ decodedTags as $ tagType => $ tagDetails ) { if ( 'whole_pool' == $ tagType ) { $ xml .= $ this -> export_textDataWithAttributes ( 'tag_selection' , 'whole_pool' , $ tagSelectionPath , array ( 'count' => $ tagDetails [ 'count' ] ) ) ; } else { $ xml .= $ this -> export_textDataWithAttributes ( 'tag_selection' , $ tagDetails [ 'name' ] , $ tagSelectionPath , array ( 'count' => $ tagDetails [ 'count' ] ) ) ; } } } $ xml .= $ this -> export_endBlock ( $ questionParentPath . '/' , 'tag_selections' ) ; $ xml .= $ this -> export_endBlock ( $ questionsParentPath . '/' , 'question' ) ; } else { if ( isset ( $ this -> questionList [ $ singleQuestion -> question_id ] ) ) { $ storedQuestionDetails = $ this -> questionList [ $ singleQuestion -> question_id ] ; $ questionDetailsByHash = array ( 'question_type' => 'fixed' , 'question_hash' => $ storedQuestionDetails -> question_hash , 'question_order' => $ questionOrder ++ , ) ; $ xml .= $ this -> export_arrayToXML ( 'question' , false , $ questionDetailsByHash , false , $ questionParentPath , '/question' ) ; } else { error_log ( __ ( 'Error exporting question in quiz.' , 'wp-courseware' ) . '(' . print_r ( $ singleQuestion , true ) . ')' ) ; } } } } $ xml .= $ this -> export_endBlock ( $ questionsParentPath , 'questions' ) ; $ xml .= $ this -> export_content_handleQuizzes_customFeedbackMessages ( $ quizObj , $ quizParentPath ) ; $ xml .= $ this -> export_endBlock ( $ quizParentPath , 'quiz' ) ; $ xml .= $ this -> export_endBlock ( $ quizzesParentPath , 'quizzes' ) ; } return $ xml ; }
Handle exporting the XML for a quiz within a single unit.
Handle exporting the XML for a quiz within a single unit .
// Show the quiz for this unit here... (if there are any). // ### Quizzes - Start // Expecting just 1 quiz per unit, no more. // ### Quiz - Start // ### Quiz Detail - show_answers_settings (serialized data) // ### Quiz Detail - quiz_paginate_questions_settings (serialized data) // ### Questions // Get the hash and the order of the question // Render the details as a single question. // ### Start tag selections // Decode the tags and add them // Whole pool - use this as a single string. // Just a normal tag // ### End tag selections // Normal question // Get the hash details for the question so we can use the hash rather than quiz details. // Get the hash and the order of the question // Render the details as a single question. // Should never be false, but check anyway and log so that we can debug in case it occurs. // end question type // end foreach // ### Questions // End the 'Quizzes' wrapper // ### Quiz - End // ### Quizzes - End