public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/functions.php
/**
 * Update the user progress count based on units completed.
 *
 * @since 1.0.0
 *
 * @param integer $courseID ID of course.
 * @param integer $userID ID of user.
 * @param integer $totalUnitCount The total number of units for this course.
 */
Update the user progress count based on units completed.

@param integer $courseID ID of course.
@param integer $userID ID of user.
@param integer $totalUnitCount The total number of units for this course.
Update the user progress count based on units completed . @param integer $courseID ID of course . @param integer $userID ID of user . @param integer $totalUnitCount The total number of units for this course .
function WPCW_users_updateUserUnitProgress( $courseID, $userID, $totalUnitCount ) {
	global $wpdb, $wpcwdb;
	$wpdb->show_errors();
	$completed = $wpdb->get_var( $wpdb->prepare(
		"SELECT COUNT(*)
    	 FROM $wpcwdb->user_progress up
      	 LEFT JOIN $wpcwdb->units_meta um ON up.unit_id = um.unit_id
    	 WHERE user_id = %d
    	 AND parent_course_id = %d
    	 AND unit_completed_status = 'complete'",
		$userID,
		$courseID
	) );
	$progress = 0;
	if ( $totalUnitCount > 0 ) {
		$progress = floor( ( $completed / $totalUnitCount ) * 100 );
	}
	$wpdb->query( $wpdb->prepare(
		"UPDATE $wpcwdb->user_courses
		 SET course_progress = %d
    	 WHERE user_id = %d
    	 AND course_id = %d",
		$progress,
		$userID,
		$courseID
	) );
}
function WPCW_users_updateUserUnitProgress ( $ courseID , $ userID , $ totalUnitCount ) { global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; $ completed = $ wpdb -> get_var ( $ wpdb -> prepare ( " SELECT COUNT(*)
    	 FROM  $ wpcwdb -> user_progress  up
      	 LEFT JOIN  $ wpcwdb -> units_meta  um ON up.unit_id = um.unit_id
    	 WHERE user_id = %d
    	 AND parent_course_id = %d
    	 AND unit_completed_status = 'complete' " , $ userID , $ courseID ) ) ; $ progress = 0 ; if ( $ totalUnitCount > 0 ) { $ progress = floor ( ( $ completed / $ totalUnitCount ) * 100 ) ; } $ wpdb -> query ( $ wpdb -> prepare ( " UPDATE  $ wpcwdb -> user_courses 
		 SET course_progress = %d
    	 WHERE user_id = %d
    	 AND course_id = %d " , $ progress , $ userID , $ courseID ) ) ; }
Update the user progress count based on units completed.
Update the user progress count based on units completed .
// Get number of completed units // Calculate progress as a percentage // Update database with the completed progress