public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/functions.php
/**
 * Course Details Updated.
 *
 * This will update the metrics associated with the course such as the total number of units.
 *
 * @since 1.0.0
 *
 * @param Array $courseDetails The course details that have just been updated.
 */
Course Details Updated.
This will update the metrics associated with the course such as the total number of units.



@param Array $courseDetails The course details that have just been updated.
Course Details Updated . This will update the metrics associated with the course such as the total number of units . @param Array $courseDetails The course details that have just been updated .
function WPCW_actions_courses_courseDetailsUpdated( $courseDetails ) {
	if ( ! $courseDetails ) {
		return;
	}
	global $wpdb, $wpcwdb;
	$wpdb->show_errors();
	$SQL = $wpdb->prepare(
		"SELECT COUNT(*)
    	 FROM $wpcwdb->units_meta
    	 WHERE parent_course_id = %d",
		$courseDetails->course_id
	);
	$totalUnitCount = $wpdb->get_var( $SQL );
	$wpdb->query( $wpdb->prepare(
		"UPDATE $wpcwdb->courses
    	 SET course_unit_count = %d
    	 WHERE course_id = %d",
		$totalUnitCount,
		$courseDetails->course_id
	) );
	$SQL = $wpdb->prepare( "SELECT * FROM $wpcwdb->user_courses WHERE course_id = %d", $courseDetails->course_id );
	$users = $wpdb->get_results( $SQL );
	if ( $users ) {
		foreach ( $users as $userCourseDetails ) {
			WPCW_users_updateUserUnitProgress( $userCourseDetails->course_id, $userCourseDetails->user_id, $totalUnitCount );
		}
	}
}
function WPCW_actions_courses_courseDetailsUpdated ( $ courseDetails ) { if ( ! $ courseDetails ) { return ; } global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; $ SQL = $ wpdb -> prepare ( " SELECT COUNT(*)
    	 FROM  $ wpcwdb -> units_meta 
    	 WHERE parent_course_id = %d " , $ courseDetails -> course_id ) ; $ totalUnitCount = $ wpdb -> get_var ( $ SQL ) ; $ wpdb -> query ( $ wpdb -> prepare ( " UPDATE  $ wpcwdb -> courses 
    	 SET course_unit_count = %d
    	 WHERE course_id = %d " , $ totalUnitCount , $ courseDetails -> course_id ) ) ; $ SQL = $ wpdb -> prepare ( " SELECT * FROM  $ wpcwdb -> user_courses  WHERE course_id = %d " , $ courseDetails -> course_id ) ; $ users = $ wpdb -> get_results ( $ SQL ) ; if ( $ users ) { foreach ( $ users as $ userCourseDetails ) { WPCW_users_updateUserUnitProgress ( $ userCourseDetails -> course_id , $ userCourseDetails -> user_id , $ totalUnitCount ) ; } } }
Course Details Updated.
Course Details Updated .
// Get a total count of units in this course // Update database with actual count // User progress counts will now be out of sync too, particularly with new or deleted units. // Get Users. // Update User Unit Progress.