public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/functions.php
/**
 * Function that upgrades quiz questions to use the new structure for storage
 * so that they can also contain images too.
 *
 * @since 1.0.0
 */
Function that upgrades quiz questions to use the new structure for storage
so that they can also contain images too.


Function that upgrades quiz questions to use the new structure for storage so that they can also contain images too .
function WPCW_database_upgrade_quizQuestions() {
	global $wpdb, $wpcwdb;
	$listOfQuestions = $wpdb->get_results( "
		SELECT *
		FROM $wpcwdb->quiz_qs
		WHERE question_type = 'multi'
		  AND question_data_answers = ''
	" );
	if ( ! empty( $listOfQuestions ) ) {
		foreach ( $listOfQuestions as $questionItem ) {
			$answerListRaw = explode( "\n", $questionItem->question_answers );
			$dataToSave = array();
			if ( ! empty( $answerListRaw ) ) {
				foreach ( $answerListRaw as $idx => $data ) {
					$dataToSave[ $idx + 1 ] = array( 'answer' => base64_encode( $data ) );
				}
			}
			$dataToSave = serialize( $dataToSave );
			$wpdb->query( $wpdb->prepare( "
				UPDATE $wpcwdb->quiz_qs
				   SET question_data_answers = %s
				 WHERE question_id = %d
			", $dataToSave, $questionItem->question_id ) );
		}
	}
}
function WPCW_database_upgrade_quizQuestions ( ) { global $ wpdb , $ wpcwdb ; $ listOfQuestions = $ wpdb -> get_results ( " 
		SELECT *
		FROM  $ wpcwdb -> quiz_qs 
		WHERE question_type = 'multi'
		  AND question_data_answers = ''
	 " ) ; if ( ! empty ( $ listOfQuestions ) ) { foreach ( $ listOfQuestions as $ questionItem ) { $ answerListRaw = explode ( " \n " , $ questionItem -> question_answers ) ; $ dataToSave = array ( ) ; if ( ! empty ( $ answerListRaw ) ) { foreach ( $ answerListRaw as $ idx => $ data ) { $ dataToSave [ $ idx + 1 ] = array ( 'answer' => base64_encode ( $ data ) ) ; } } $ dataToSave = serialize ( $ dataToSave ) ; $ wpdb -> query ( $ wpdb -> prepare ( " 
				UPDATE  $ wpcwdb -> quiz_qs 
				   SET question_data_answers = %s
				 WHERE question_id = %d
			 " , $ dataToSave , $ questionItem -> question_id ) ) ; } } }
Function that upgrades quiz questions to use the new structure for storage
 so that they can also contain images too.
Function that upgrades quiz questions to use the new structure for storage so that they can also contain images too .
// Turn list into an array // Base64 encode each item in case we have HTML to worry about. // Check if list is empty. If it is, that's fine. We just save an empty array to the database. // Creates the following // [1] => array('answer' => 'data') // [2] => array('answer' => 'data') // Serialise the data