public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/functions.php
/**
 * Function called after a module has been created with the modify module form.
 *
 * @since 1.0.0
 *
 * @param array    $formValues The processed form values.
 * @param array    $originalFormValues The raw form values.
 * @param EasyForm $thisObject The reference to the form object doing the saving.
 */
Function called after a module has been created with the modify module form.

@param array    $formValues The processed form values.
@param array    $originalFormValues The raw form values.
@param EasyForm $thisObject The reference to the form object doing the saving.
Function called after a module has been created with the modify module form . @param array $formValues The processed form values . @param array $originalFormValues The raw form values . @param EasyForm $thisObject The reference to the form object doing the saving .
function WPCW_actions_modules_afterModuleSaved_formHook( $formValues, $originalFormValues, $thisObject ) {
	do_action( 'wpcw_modules_modified', $formValues['parent_course_id'] );
	if ( isset( $_GET['module_id'] ) ) {
		global $wpdb, $wpcwdb;
		$unitList = WPCW_units_getListOfUnits( $formValues['module_id'] );
		if ( $unitList && count( $unitList ) > 0 ) {
			$unit_count = $wpdb->get_var( $wpdb->prepare( "
				SELECT max(unit_order)
				FROM $wpcwdb->units_meta
				WHERE parent_course_id = %d
				", $formValues['parent_course_id'] ) );
			foreach ( $unitList as $unitID => $unitData ) {
				$unitMeta = WPCW_units_getUnitMetaData( $unitID );
				if ( $unitMeta->parent_course_id != $formValues['parent_course_id'] ) {
					$unit_count += 10;
					$SQL = $wpdb->prepare( "
						UPDATE $wpcwdb->units_meta
						SET parent_course_id = %d, unit_order = %d
						WHERE unit_id = %d
					", $formValues['parent_course_id'], $unit_count,
						$unitID );
					$wpdb->query( $SQL );
					$quizData = WPCW_quizzes_getListOfQuizzes( $unitID );
					if ( $quizData ) {
						foreach ( $quizData as $quizID => $quizObj ) {
							$SQL = $wpdb->prepare( "
							UPDATE $wpcwdb->quiz
						   	SET parent_unit_id = %d, parent_course_id = %d
							WHERE quiz_id = %d
							", $unitID, $formValues['parent_course_id'], $quizID );
							$wpdb->query( $SQL );
						}
					}
				}
			}
		}
	}
}
function WPCW_actions_modules_afterModuleSaved_formHook ( $ formValues , $ originalFormValues , $ thisObject ) { do_action ( 'wpcw_modules_modified' , $ formValues [ 'parent_course_id' ] ) ; if ( isset ( $ _GET [ 'module_id' ] ) ) { global $ wpdb , $ wpcwdb ; $ unitList = WPCW_units_getListOfUnits ( $ formValues [ 'module_id' ] ) ; if ( $ unitList && count ( $ unitList ) > 0 ) { $ unit_count = $ wpdb -> get_var ( $ wpdb -> prepare ( " 
				SELECT max(unit_order)
				FROM  $ wpcwdb -> units_meta 
				WHERE parent_course_id = %d
				 " , $ formValues [ 'parent_course_id' ] ) ) ; foreach ( $ unitList as $ unitID => $ unitData ) { $ unitMeta = WPCW_units_getUnitMetaData ( $ unitID ) ; if ( $ unitMeta -> parent_course_id != $ formValues [ 'parent_course_id' ] ) { $ unit_count += 10 ; $ SQL = $ wpdb -> prepare ( " 
						UPDATE  $ wpcwdb -> units_meta 
						SET parent_course_id = %d, unit_order = %d
						WHERE unit_id = %d
					 " , $ formValues [ 'parent_course_id' ] , $ unit_count , $ unitID ) ; $ wpdb -> query ( $ SQL ) ; $ quizData = WPCW_quizzes_getListOfQuizzes ( $ unitID ) ; if ( $ quizData ) { foreach ( $ quizData as $ quizID => $ quizObj ) { $ SQL = $ wpdb -> prepare ( " 
							UPDATE  $ wpcwdb -> quiz 
						   	SET parent_unit_id = %d, parent_course_id = %d
							WHERE quiz_id = %d
							 " , $ unitID , $ formValues [ 'parent_course_id' ] , $ quizID ) ; $ wpdb -> query ( $ SQL ) ; } } } } } } }
Function called after a module has been created with the modify module form.
Function called after a module has been created with the modify module form .
// Modules have been modified. Call action to update module numbers. // Run only if modifying module // Check units associated with this module in order to update parent course ID // Get max unit order value // Need to adjust each unit's metadata with in the module // Check if parent course ID is different // Set unit meta data for new course ID and unit order // Check quizzes associated with this unit in order to update parent course ID