public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/classes/import.php
/**
		 * Try to add the quizzes to the database.
		 *
		 * @param Array   $quizData The list of quizzes to add
		 * @param Integer $unitID The ID of the parent unit.
		 *
		 * @return Integer The number of quizzes added.
		 */
Try to add the quizzes to the database.
@param Array   $quizData The list of quizzes to add
@param Integer $unitID The ID of the parent unit.

@return Integer The number of quizzes added.
Try to add the quizzes to the database . @param Array $quizData The list of quizzes to add @param Integer $unitID The ID of the parent unit . @return Integer The number of quizzes added .
private function loadQuizData_addQuizzesToDatabase( $quizData, $unitID ) {
			if ( ! $quizData || empty( $quizData ) ) {
				return 0;
			}
			global $wpdb, $wpcwdb;
			$wpdb->show_errors();
			$quizCount = 0;
			foreach ( $quizData as $singleQuiz ) {
				$quizCount ++;
				$quizDetailsToAdd = array(
					'parent_unit_id'   => $unitID,
					'parent_course_id' => $this->course_id,
				);
				global $fieldsToProcess_quizzes;
				foreach ( $fieldsToProcess_quizzes as $expectedFieldName ) {
					$quizDetailsToAdd[ $expectedFieldName ] = WPCW_arrays_getValue( $singleQuiz, $expectedFieldName );
				}
				$quizDetailsToAdd['show_answers_settings']            = serialize( $singleQuiz['show_answers_settings'] );
				$quizDetailsToAdd['quiz_paginate_questions_settings'] = serialize( $singleQuiz['quiz_paginate_questions_settings'] );
				$quizDetailsToAdd['quiz_author']                      = ( isset( $singleQuiz['quiz_author'] ) && $singleQuiz['quiz_author'] ) ? $singleQuiz['quiz_author'] : get_current_user_id();
				$queryResult = $wpdb->query( arrayToSQLInsert( $wpcwdb->quiz, $quizDetailsToAdd ) );
				$currentQuizID = $wpdb->insert_id;
				if ( $queryResult === false ) {
					return $this->returnErrorList( __( 'There was a problem adding the quiz into the database.', 'wp-courseware' ) );
				}
				$singleQuiz['quiz_id'] = $currentQuizID;
				$this->loadQuizData_addQuestionsAssociations( $singleQuiz );
				if ( ! empty( $singleQuiz['custom_feedback'] ) ) {
					foreach ( $singleQuiz['custom_feedback'] as $singleMessage ) {
						$singleMessage['qfeedback_quiz_id'] = $currentQuizID;
						$wpdb->query( arrayToSQLInsert( $wpcwdb->quiz_feedback, $singleMessage ) );
					}
				}
			}
			return $quizCount;
		}
private function loadQuizData_addQuizzesToDatabase ( $ quizData , $ unitID ) { if ( ! $ quizData || empty ( $ quizData ) ) { return 0 ; } global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; $ quizCount = 0 ; foreach ( $ quizData as $ singleQuiz ) { $ quizCount ++ ; $ quizDetailsToAdd = array ( 'parent_unit_id' => $ unitID , 'parent_course_id' => $ this -> course_id , ) ; global $ fieldsToProcess_quizzes ; foreach ( $ fieldsToProcess_quizzes as $ expectedFieldName ) { $ quizDetailsToAdd [ $ expectedFieldName ] = WPCW_arrays_getValue ( $ singleQuiz , $ expectedFieldName ) ; } $ quizDetailsToAdd [ 'show_answers_settings' ] = serialize ( $ singleQuiz [ 'show_answers_settings' ] ) ; $ quizDetailsToAdd [ 'quiz_paginate_questions_settings' ] = serialize ( $ singleQuiz [ 'quiz_paginate_questions_settings' ] ) ; $ quizDetailsToAdd [ 'quiz_author' ] = ( isset ( $ singleQuiz [ 'quiz_author' ] ) && $ singleQuiz [ 'quiz_author' ] ) ? $ singleQuiz [ 'quiz_author' ] : get_current_user_id ( ) ; $ queryResult = $ wpdb -> query ( arrayToSQLInsert ( $ wpcwdb -> quiz , $ quizDetailsToAdd ) ) ; $ currentQuizID = $ wpdb -> insert_id ; if ( $ queryResult === false ) { return $ this -> returnErrorList ( __ ( 'There was a problem adding the quiz into the database.' , 'wp-courseware' ) ) ; } $ singleQuiz [ 'quiz_id' ] = $ currentQuizID ; $ this -> loadQuizData_addQuestionsAssociations ( $ singleQuiz ) ; if ( ! empty ( $ singleQuiz [ 'custom_feedback' ] ) ) { foreach ( $ singleQuiz [ 'custom_feedback' ] as $ singleMessage ) { $ singleMessage [ 'qfeedback_quiz_id' ] = $ currentQuizID ; $ wpdb -> query ( arrayToSQLInsert ( $ wpcwdb -> quiz_feedback , $ singleMessage ) ) ; } } } return $ quizCount ; }
Try to add the quizzes to the database.
Try to add the quizzes to the database .
// ### 1 - Initialise with details we need to add dymaically. // ### 2 - Copy details from the fields as we expect to find them // Copy detail - if it exists or not. // ### 3 - Handle the insert of the special arrays that need serialising. We know these exist // as we have specifically validated them. // ### 4 - Insert details of this particular quiz into the database. // Store the ID of the newly inserted ID // Check query succeeded. // ### 5 - Now associate the detailed questions data with the quizzes. // ### 6 - Now any custom feedback messages. // Add this quiz ID // Now add the feedback to the database