public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/admin/functions.php
/**
 * Function that completely re-orders the units in a course to clear out orphans.
 *
 * @since 1.0.0
 *
 * @param integer $course_id The ID of the course to update.
 */
Function that completely re-orders the units in a course to clear out orphans.

@param integer $course_id The ID of the course to update.
Function that completely re - orders the units in a course to clear out orphans . @param integer $course_id The ID of the course to update .
function WPCW_courses_reorderUnitNumbers( $course_id ) {
	global $wpdb, $wpcwdb;
	$wpdb->show_errors();
	$unitList = $wpdb->get_results( $wpdb->prepare( "
		SELECT *
		FROM $wpcwdb->units_meta
		WHERE parent_course_id = %d
		ORDER BY unit_order ASC
	", $course_id ) );
	$lastModule       = - 1;
	$targetUnitNumber = 0;
	if ( ! empty( $unitList ) ) {
		foreach ( $unitList as $singleUnit ) {
			if ( $singleUnit->parent_module_id != $lastModule ) {
				$lastModule       = $singleUnit->parent_module_id;
				$targetUnitNumber = 1;
			} 
			else {
				$targetUnitNumber ++;
			}
			if ( $targetUnitNumber != $singleUnit->unit_number ) {
				$wpdb->query( $wpdb->prepare( "
					UPDATE $wpcwdb->units_meta
					   SET unit_number = %d
					WHERE parent_course_id = %d
					  AND unit_id = %d
				", $targetUnitNumber, $course_id, $singleUnit->unit_id ) );
			}
		}
	}
}
function WPCW_courses_reorderUnitNumbers ( $ course_id ) { global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; $ unitList = $ wpdb -> get_results ( $ wpdb -> prepare ( " 
		SELECT *
		FROM  $ wpcwdb -> units_meta 
		WHERE parent_course_id = %d
		ORDER BY unit_order ASC
	 " , $ course_id ) ) ; $ lastModule = - 1 ; $ targetUnitNumber = 0 ; if ( ! empty ( $ unitList ) ) { foreach ( $ unitList as $ singleUnit ) { if ( $ singleUnit -> parent_module_id != $ lastModule ) { $ lastModule = $ singleUnit -> parent_module_id ; $ targetUnitNumber = 1 ; } else { $ targetUnitNumber ++ ; } if ( $ targetUnitNumber != $ singleUnit -> unit_number ) { $ wpdb -> query ( $ wpdb -> prepare ( " 
					UPDATE  $ wpcwdb -> units_meta 
					   SET unit_number = %d
					WHERE parent_course_id = %d
					  AND unit_id = %d
				 " , $ targetUnitNumber , $ course_id , $ singleUnit -> unit_id ) ) ; } } } }
Function that completely re-orders the units in a course to clear out orphans.
Function that completely re - orders the units in a course to clear out orphans .
// Get a list of all units for this course in absolute order // Just update unit numbers, don't worry about ordering, as that should be preserved. // New module, so reset the unit number. // Same module, so increase unit number. // Only update units that need fixing.