public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/admin/functions.php
/**
 * This function removes the user progress for the specified list of users and units.
 *
 * @since 1.0.0
 *
 * @param array   $userList The list of users to reset.
 * @param array   $unitList The list of units to remove from their progress.
 * @param object  $courseDetails The details of the course.
 * @param integer $totalUnitCount The total number of units in this course.
 */
This function removes the user progress for the specified list of users and units.

@param array   $userList The list of users to reset.
@param array   $unitList The list of units to remove from their progress.
@param object  $courseDetails The details of the course.
@param integer $totalUnitCount The total number of units in this course.
This function removes the user progress for the specified list of users and units . @param array $userList The list of users to reset . @param array $unitList The list of units to remove from their progress . @param object $courseDetails The details of the course . @param integer $totalUnitCount The total number of units in this course .
function WPCW_users_resetProgress( $userList, $unitList, $courseDetails, $totalUnitCount ) {
	global $wpcwdb, $wpdb;
	$wpdb->show_errors();
	if ( empty( $userList ) || empty( $unitList ) ) {
		return;
	}
	$SQL_units = '(' . implode( ',', $unitList ) . ')';
	$SQL_users = '(' . implode( ',', $userList ) . ')';
	$SQL = "DELETE FROM $wpcwdb->user_progress
			WHERE user_id IN $SQL_users
			  AND unit_id IN $SQL_units
			";
	$wpdb->query( $SQL );
	$SQL = "DELETE FROM $wpcwdb->user_progress_quiz
			WHERE user_id IN $SQL_users
			  AND unit_id IN $SQL_units
			";
	$wpdb->query( $SQL );
	$SQL = "DELETE FROM $wpcwdb->question_rand_lock
			WHERE question_user_id IN $SQL_users
			  AND parent_unit_id IN $SQL_units
			";
	$wpdb->query( $SQL );
	foreach ( $userList as $aUser ) {
		$progressExists = $wpdb->get_row( $wpdb->prepare( "
			SELECT *
			FROM $wpcwdb->user_courses
			WHERE user_id = %d
			 AND course_id = %d
		", $aUser, $courseDetails->course_id ) );
		if ( $progressExists ) {
			$wpdb->query( $wpdb->prepare( "
		    	UPDATE $wpcwdb->user_courses
		    	   SET course_final_grade_sent = ''
		    	WHERE user_id = %d
		    	  AND course_id = %d
		    ", $aUser, $courseDetails->course_id ) );
		}
		$wpdb->query( $wpdb->prepare( "
			DELETE
			FROM $wpcwdb->certificates
			WHERE cert_user_id = %d
			 AND cert_course_id = %d
		", $aUser, $courseDetails->course_id ) );
		WPCW_users_updateUserUnitProgress( $courseDetails->course_id, $aUser, $courseDetails->course_unit_count );
	}
}
function WPCW_users_resetProgress ( $ userList , $ unitList , $ courseDetails , $ totalUnitCount ) { global $ wpcwdb , $ wpdb ; $ wpdb -> show_errors ( ) ; if ( empty ( $ userList ) || empty ( $ unitList ) ) { return ; } $ SQL_units = '(' . implode ( ',' , $ unitList ) . ')' ; $ SQL_users = '(' . implode ( ',' , $ userList ) . ')' ; $ SQL = " DELETE FROM  $ wpcwdb -> user_progress 
			WHERE user_id IN  $ SQL_users 
			  AND unit_id IN  $ SQL_units " ; $ wpdb -> query ( $ SQL ) ; $ SQL = " DELETE FROM  $ wpcwdb -> user_progress_quiz 
			WHERE user_id IN  $ SQL_users 
			  AND unit_id IN  $ SQL_units " ; $ wpdb -> query ( $ SQL ) ; $ SQL = " DELETE FROM  $ wpcwdb -> question_rand_lock 
			WHERE question_user_id IN  $ SQL_users 
			  AND parent_unit_id IN  $ SQL_units " ; $ wpdb -> query ( $ SQL ) ; foreach ( $ userList as $ aUser ) { $ progressExists = $ wpdb -> get_row ( $ wpdb -> prepare ( " 
			SELECT *
			FROM  $ wpcwdb -> user_courses 
			WHERE user_id = %d
			 AND course_id = %d
		 " , $ aUser , $ courseDetails -> course_id ) ) ; if ( $ progressExists ) { $ wpdb -> query ( $ wpdb -> prepare ( " 
		    	UPDATE  $ wpcwdb -> user_courses 
		    	   SET course_final_grade_sent = ''
		    	WHERE user_id = %d
		    	  AND course_id = %d
		     " , $ aUser , $ courseDetails -> course_id ) ) ; } $ wpdb -> query ( $ wpdb -> prepare ( " 
			DELETE
			FROM  $ wpcwdb -> certificates 
			WHERE cert_user_id = %d
			 AND cert_course_id = %d
		 " , $ aUser , $ courseDetails -> course_id ) ) ; WPCW_users_updateUserUnitProgress ( $ courseDetails -> course_id , $ aUser , $ courseDetails -> course_unit_count ) ; } }
This function removes the user progress for the specified list of users and units.
This function removes the user progress for the specified list of users and units .
// Nothing to do! // Delete all data in user progress in one hit // Delete all quiz data in one hit // Delete all user locks // Now update the user progress. // DJH 2015-09-09 // Fixed reset grade sent flag. // Going to assume that if we're resetting any progress, then we're undoing the course completion. // DJH 2015-09-09 // Try to delete the certificate, if we've already created one. // Going to assume that if we're resetting any progress, then we're undoing the course completion. // DJH 2015-11-01 // Ensure that the progress status matches the actual progress, rather than always resetting to 0 // like this code did before.