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

@return Integer The number of units added.
Try to add the units to the database . @param Array $unitData The list of units to add @param Integer $moduleID The ID of the parent module @return Integer The number of units added .
private function addUnitsToDatabase( $unitData, $moduleID ) {
			if ( ! $unitData || count( $unitData ) < 1 ) {
				return 0;
			}
			global $wpdb, $wpcwdb;
			$wpdb->show_errors();
			$unitCount = 0;
			foreach ( $unitData as $singleUnit ) {
				$unitPost = array(
					'post_title'   => $singleUnit['post_title'],
					'post_name'    => $singleUnit['post_name'],
					'post_status'  => 'publish',
					'post_type'    => 'course_unit',
					'post_author'  => ( isset( $singleUnit['post_author'] ) ) ? $singleUnit['post_author'] : get_current_user_id(),
					'post_content' => addslashes( $singleUnit['post_content'] ),
				);
				$unitID = wp_insert_post( $unitPost );
				if ( ! $unitID ) {
					$this->errorList[] = sprintf( __( 'Could not create course unit "%s". So this was skipped.', 'wp-courseware' ), $singleUnit['post_title'] );
					continue;
				}
				update_post_meta( $unitID, 'wpcw_associated_module', $moduleID );
				update_post_meta( $unitID, WPCW_TEMPLATE_META_ID, $singleUnit['template'] );
				$unitCount ++;
				$this->unit_order += 10;
				$unitmeta                     = array();
				$unitmeta['unit_id']          = $unitID;
				$unitmeta['parent_module_id'] = $moduleID;
				$unitmeta['unit_author']      = $unitPost['post_author'];
				$unitmeta['parent_course_id'] = $this->course_id;
				$unitmeta['unit_order']       = $this->unit_order; 
				$unitmeta['unit_number']      = $unitCount;         
				$unitmeta['unit_drip_type']          = isset( $singleUnit['unit_drip_type'] ) ? $singleUnit['unit_drip_type'] : '';
				$unitmeta['unit_drip_date']          = isset( $singleUnit['unit_drip_date'] ) ? $singleUnit['unit_drip_date'] : '';
				$unitmeta['unit_drip_interval']      = isset( $singleUnit['unit_drip_interval'] ) ? $singleUnit['unit_drip_interval'] : '';
				$unitmeta['unit_drip_interval_type'] = isset( $singleUnit['unit_drip_interval_type'] ) ? $singleUnit['unit_drip_interval_type'] : '';
				$queryResult = $wpdb->query( arrayToSQLUpdate( $wpcwdb->units_meta, $unitmeta, 'unit_id' ) );
				if ( $queryResult === false ) {
					return $this->returnErrorList( __( 'There was a problem adding unit meta data into the database.', 'wp-courseware' ) );
				}
				if ( $unitID ) {
					WPCW_queue_dripfeed::updateQueueItems_unitUpdated( $unitID );
				}
				if ( isset( $singleUnit['quizzes'] ) && ! empty( $singleUnit['quizzes'] ) ) {
					$quizData = $singleUnit['quizzes'];
					unset( $singleUnit['quizzes'] );
					$this->loadQuizData_addQuizzesToDatabase( $quizData, $unitID );
				}
			}
			return $unitCount;
		}
private function addUnitsToDatabase ( $ unitData , $ moduleID ) { if ( ! $ unitData || count ( $ unitData ) < 1 ) { return 0 ; } global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; $ unitCount = 0 ; foreach ( $ unitData as $ singleUnit ) { $ unitPost = array ( 'post_title' => $ singleUnit [ 'post_title' ] , 'post_name' => $ singleUnit [ 'post_name' ] , 'post_status' => 'publish' , 'post_type' => 'course_unit' , 'post_author' => ( isset ( $ singleUnit [ 'post_author' ] ) ) ? $ singleUnit [ 'post_author' ] : get_current_user_id ( ) , 'post_content' => addslashes ( $ singleUnit [ 'post_content' ] ) , ) ; $ unitID = wp_insert_post ( $ unitPost ) ; if ( ! $ unitID ) { $ this -> errorList [ ] = sprintf ( __ ( 'Could not create course unit "%s". So this was skipped.' , 'wp-courseware' ) , $ singleUnit [ 'post_title' ] ) ; continue ; } update_post_meta ( $ unitID , 'wpcw_associated_module' , $ moduleID ) ; update_post_meta ( $ unitID , WPCW_TEMPLATE_META_ID , $ singleUnit [ 'template' ] ) ; $ unitCount ++ ; $ this -> unit_order += 10 ; $ unitmeta = array ( ) ; $ unitmeta [ 'unit_id' ] = $ unitID ; $ unitmeta [ 'parent_module_id' ] = $ moduleID ; $ unitmeta [ 'unit_author' ] = $ unitPost [ 'post_author' ] ; $ unitmeta [ 'parent_course_id' ] = $ this -> course_id ; $ unitmeta [ 'unit_order' ] = $ this -> unit_order ; $ unitmeta [ 'unit_number' ] = $ unitCount ; $ unitmeta [ 'unit_drip_type' ] = isset ( $ singleUnit [ 'unit_drip_type' ] ) ? $ singleUnit [ 'unit_drip_type' ] : '' ; $ unitmeta [ 'unit_drip_date' ] = isset ( $ singleUnit [ 'unit_drip_date' ] ) ? $ singleUnit [ 'unit_drip_date' ] : '' ; $ unitmeta [ 'unit_drip_interval' ] = isset ( $ singleUnit [ 'unit_drip_interval' ] ) ? $ singleUnit [ 'unit_drip_interval' ] : '' ; $ unitmeta [ 'unit_drip_interval_type' ] = isset ( $ singleUnit [ 'unit_drip_interval_type' ] ) ? $ singleUnit [ 'unit_drip_interval_type' ] : '' ; $ queryResult = $ wpdb -> query ( arrayToSQLUpdate ( $ wpcwdb -> units_meta , $ unitmeta , 'unit_id' ) ) ; if ( $ queryResult === false ) { return $ this -> returnErrorList ( __ ( 'There was a problem adding unit meta data into the database.' , 'wp-courseware' ) ) ; } if ( $ unitID ) { WPCW_queue_dripfeed :: updateQueueItems_unitUpdated ( $ unitID ) ; } if ( isset ( $ singleUnit [ 'quizzes' ] ) && ! empty ( $ singleUnit [ 'quizzes' ] ) ) { $ quizData = $ singleUnit [ 'quizzes' ] ; unset ( $ singleUnit [ 'quizzes' ] ) ; $ this -> loadQuizData_addQuizzesToDatabase ( $ quizData , $ unitID ) ; } } return $ unitCount ; }
Try to add the units to the database.
Try to add the units to the database .
// ### 1 - Create unit as a WP Post // Since V2.90. // 2014-05-05 - Added slashes as wp_insert_post removes them on insert. So add extra layer here // before insert to preserve them. // Insert the post into the database // ### 2 - Update the post with the meta of the related module and template // ### 3 - Create the meta data for WPCW for this unit // The order overall in whole course // The number of the unit within module // This is an update, as wp_insert_post will create meta entry. // Check query succeeded. // Let the queuing system know that a change has happened. // ### 4 - Create the meta data for the quiz entry (if there are any) // And add the quizzes for this unit.