public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/functions.php
/**
 * Calculates the cumulative grade for a course and user.
 *
 * @since 1.0.0
 *
 * @param integer $courseID The ID of the course.
 * @param integer $userID The ID of the user.
 *
 * @return string The progress for the course/user, or n/a if there's nothing to report.
 */
Calculates the cumulative grade for a course and user.

@param integer $courseID The ID of the course.
@param integer $userID The ID of the user.

@return string The progress for the course/user, or n/a if there's nothing to report.
Calculates the cumulative grade for a course and user . @param integer $courseID The ID of the course . @param integer $userID The ID of the user . @return string The progress for the course / user or n / a if there ' s nothing to report .
function WPCW_courses_getCourseCumulativeGrade( $courseID, $userID ) {
	$quizIDList       = array();
	$quizIDListForSQL = false;
	$quizzesForCourse = WPCW_quizzes_getAllQuizzesForCourse( $courseID );
	if ( $quizzesForCourse ) {
		foreach ( $quizzesForCourse as $singleQuiz ) {
			$quizIDList[ $singleQuiz->quiz_id ] = $singleQuiz;
		}
		$quizIDListForSQL = '(' . implode( ',', array_keys( $quizIDList ) ) . ')';
	} else { 
		return __( 'N/A', 'wp-courseware' );
	}
	$quizResults = WPCW_quizzes_getQuizResultsForUser( $userID, $quizIDListForSQL );
	$quizScoresSoFar       = 0;
	$quizScoresSoFar_count = 0;
	foreach ( $quizIDList as $aQuizID => $singleQuiz ) {
		if ( isset( $quizResults[ $aQuizID ] ) ) {
			$theResults            = $quizResults[ $aQuizID ];
			$theResults->quiz_data = maybe_unserialize( $theResults->quiz_data );
			if ( $theResults->quiz_needs_marking == 0 && 'incomplete' != $theResults->quiz_paging_status ) {
				$score           = $theResults->quiz_grade;
				$quizScoresSoFar += $score;
				$quizScoresSoFar_count ++;
			}
		}
	}
	return ( $quizScoresSoFar_count > 0 ? number_format( ( $quizScoresSoFar / $quizScoresSoFar_count ), 2 ) : __( '-', 'wp-courseware' ) );
}
function WPCW_courses_getCourseCumulativeGrade ( $ courseID , $ userID ) { $ quizIDList = array ( ) ; $ quizIDListForSQL = false ; $ quizzesForCourse = WPCW_quizzes_getAllQuizzesForCourse ( $ courseID ) ; if ( $ quizzesForCourse ) { foreach ( $ quizzesForCourse as $ singleQuiz ) { $ quizIDList [ $ singleQuiz -> quiz_id ] = $ singleQuiz ; } $ quizIDListForSQL = '(' . implode ( ',' , array_keys ( $ quizIDList ) ) . ')' ; } else { return __ ( 'N/A' , 'wp-courseware' ) ; } $ quizResults = WPCW_quizzes_getQuizResultsForUser ( $ userID , $ quizIDListForSQL ) ; $ quizScoresSoFar = 0 ; $ quizScoresSoFar_count = 0 ; foreach ( $ quizIDList as $ aQuizID => $ singleQuiz ) { if ( isset ( $ quizResults [ $ aQuizID ] ) ) { $ theResults = $ quizResults [ $ aQuizID ] ; $ theResults -> quiz_data = maybe_unserialize ( $ theResults -> quiz_data ) ; if ( $ theResults -> quiz_needs_marking == 0 && 'incomplete' != $ theResults -> quiz_paging_status ) { $ score = $ theResults -> quiz_grade ; $ quizScoresSoFar += $ score ; $ quizScoresSoFar_count ++ ; } } } return ( $ quizScoresSoFar_count > 0 ? number_format ( ( $ quizScoresSoFar / $ quizScoresSoFar_count ) , 2 ) : __ ( '-' , 'wp-courseware' ) ) ; }
Calculates the cumulative grade for a course and user.
Calculates the cumulative grade for a course and user .
// Get all the quizzes for this course // Create a simple list of IDs to use in SQL queries // Convert list of IDs into an SQL list // (!$quizzesForCourse) Break here if there are no quizzes for this course. // Get quiz results for this user // Track cumulative data // Now render results for each quiz // Got progress data, process the result // Extract results and unserialise the data array. // We've got something that needs grading. // Calculate score, and use for cumulative. // Calculate the cumulative grade