public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/functions.php
/**
 * Given a frontend object with user progress data, replace the tags with quiz-related information
 * based on the tags that have been found in the email.
 *
 * @since 1.0.0
 *
 * @param WPCW_UnitFrontend $feObj The frontend object with details.
 * @param array             $tagList The list of tags found in the template.
 * @param string            $emailData The data to replace the strings with.
 * @param string            $additionalData Any additional data triggered from the trainer.
 *
 * @return The modified email data ready for sending.
 */
Given a frontend object with user progress data, replace the tags with quiz-related information
based on the tags that have been found in the email.



@param WPCW_UnitFrontend $feObj The frontend object with details.
@param array             $tagList The list of tags found in the template.
@param string            $emailData The data to replace the strings with.
@param string            $additionalData Any additional data triggered from the trainer.

@return The modified email data ready for sending.
Given a frontend object with user progress data replace the tags with quiz - related information based on the tags that have been found in the email . @param WPCW_UnitFrontend $feObj The frontend object with details . @param array $tagList The list of tags found in the template . @param string $emailData The data to replace the strings with . @param string $additionalData Any additional data triggered from the trainer . @return The modified email data ready for sending .
function WPCW_email_replaceTags_quizData( $feObj, $tagList, $emailData, $additionalData = false ) {
	if ( ! $feObj || empty( $tagList ) ) {
		return $emailData;
	}
	$quizDetails  = $feObj->fetch_getUnitQuizDetails();
	$progressData = $feObj->fetch_getQuizProgressDetails();
	foreach ( $tagList as $tagToReplace ) {
		switch ( $tagToReplace ) {
			case '{QUIZ_TITLE}':
				$emailData = str_replace( '{QUIZ_TITLE}', $quizDetails->quiz_title, $emailData );
				break;
			case '{QUIZ_GRADE}':
				$emailData = str_replace( '{QUIZ_GRADE}', $progressData->quiz_grade . '%', $emailData );
				break;
			case '{QUIZ_ATTEMPTS}':
				$emailData = str_replace( '{QUIZ_ATTEMPTS}', $progressData->attempt_count, $emailData );
				break;
			case '{QUIZ_TIME}':
				$timeToShare = __( '-', 'wp-courseware' );
				if ( $progressData->quiz_completion_time_seconds > 0 ) {
					$timeToShare = WPCW_time_convertSecondsToHumanLabel( $progressData->quiz_completion_time_seconds );
				}
				$emailData = str_replace( '{QUIZ_TIME}', $timeToShare, $emailData );
				break;
			case '{QUIZ_RESULT_DETAIL}':
				$emailData = str_replace( '{QUIZ_RESULT_DETAIL}', $additionalData, $emailData );
				break;
			case '{QUIZ_GRADES_BY_TAG}':
				$msgList    = $feObj->fetch_quizzes_questionResultsByTag();
				$msgSummary = false;
				if ( ! empty( $msgList ) ) {
					foreach ( $msgList as $tagDetails ) {
						if ( $tagDetails['question_open_count'] > 0 ) {
							$msgSummary .= sprintf( "%s: %s\n", $tagDetails['tag_details']->question_tag_name,
								sprintf( __( 'Your grade is %d%%', 'wp-courseware' ), $tagDetails['score_total'] )
							);
						} else {
							$msgSummary .= sprintf( "%s: %s\n", $tagDetails['tag_details']->question_tag_name,
								sprintf( __( '%d out of %d correct (%d%%)', 'wp-courseware' ),
									$tagDetails['score_correct_questions'],
									$tagDetails['question_count'],
									$tagDetails['score_total'] )
							);
						}
					}
				}
				$emailData = str_replace( '{QUIZ_GRADES_BY_TAG}', $msgSummary, $emailData );
				break;
			case '{CUSTOM_FEEDBACK}':
				$customFeedback = false;
				$msgList        = $feObj->fetch_customFeedbackMessage_calculateMessages();
				if ( ! empty( $msgList ) ) {
					$customFeedback = apply_filters( 'wpcw_email_feedback_separator_top', "\n\n------\n\n" );
					foreach ( $msgList as $singleMsg ) {
						$customFeedback .= $singleMsg . apply_filters( 'wpcw_email_feedback_separator', "\n\n------\n\n" );
					}
				}
				$emailData = str_replace( '{CUSTOM_FEEDBACK}', $customFeedback, $emailData );
				break;
		}
	}
	return $emailData;
}
function WPCW_email_replaceTags_quizData ( $ feObj , $ tagList , $ emailData , $ additionalData = false ) { if ( ! $ feObj || empty ( $ tagList ) ) { return $ emailData ; } $ quizDetails = $ feObj -> fetch_getUnitQuizDetails ( ) ; $ progressData = $ feObj -> fetch_getQuizProgressDetails ( ) ; foreach ( $ tagList as $ tagToReplace ) { switch ( $ tagToReplace ) { case '{QUIZ_TITLE}' : $ emailData = str_replace ( '{QUIZ_TITLE}' , $ quizDetails -> quiz_title , $ emailData ) ; break ; case '{QUIZ_GRADE}' : $ emailData = str_replace ( '{QUIZ_GRADE}' , $ progressData -> quiz_grade . '%' , $ emailData ) ; break ; case '{QUIZ_ATTEMPTS}' : $ emailData = str_replace ( '{QUIZ_ATTEMPTS}' , $ progressData -> attempt_count , $ emailData ) ; break ; case '{QUIZ_TIME}' : $ timeToShare = __ ( '-' , 'wp-courseware' ) ; if ( $ progressData -> quiz_completion_time_seconds > 0 ) { $ timeToShare = WPCW_time_convertSecondsToHumanLabel ( $ progressData -> quiz_completion_time_seconds ) ; } $ emailData = str_replace ( '{QUIZ_TIME}' , $ timeToShare , $ emailData ) ; break ; case '{QUIZ_RESULT_DETAIL}' : $ emailData = str_replace ( '{QUIZ_RESULT_DETAIL}' , $ additionalData , $ emailData ) ; break ; case '{QUIZ_GRADES_BY_TAG}' : $ msgList = $ feObj -> fetch_quizzes_questionResultsByTag ( ) ; $ msgSummary = false ; if ( ! empty ( $ msgList ) ) { foreach ( $ msgList as $ tagDetails ) { if ( $ tagDetails [ 'question_open_count' ] > 0 ) { $ msgSummary .= sprintf ( " %s: %s \n " , $ tagDetails [ 'tag_details' ] -> question_tag_name , sprintf ( __ ( 'Your grade is %d%%' , 'wp-courseware' ) , $ tagDetails [ 'score_total' ] ) ) ; } else { $ msgSummary .= sprintf ( " %s: %s \n " , $ tagDetails [ 'tag_details' ] -> question_tag_name , sprintf ( __ ( '%d out of %d correct (%d%%)' , 'wp-courseware' ) , $ tagDetails [ 'score_correct_questions' ] , $ tagDetails [ 'question_count' ] , $ tagDetails [ 'score_total' ] ) ) ; } } } $ emailData = str_replace ( '{QUIZ_GRADES_BY_TAG}' , $ msgSummary , $ emailData ) ; break ; case '{CUSTOM_FEEDBACK}' : $ customFeedback = false ; $ msgList = $ feObj -> fetch_customFeedbackMessage_calculateMessages ( ) ; if ( ! empty ( $ msgList ) ) { $ customFeedback = apply_filters ( 'wpcw_email_feedback_separator_top' , " \n \n ------ \n \n " ) ; foreach ( $ msgList as $ singleMsg ) { $ customFeedback .= $ singleMsg . apply_filters ( 'wpcw_email_feedback_separator' , " \n \n ------ \n \n " ) ; } } $ emailData = str_replace ( '{CUSTOM_FEEDBACK}' , $ customFeedback , $ emailData ) ; break ; } } return $ emailData ; }
Given a frontend object with user progress data, replace the tags with quiz-related information
 based on the tags that have been found in the email.
Given a frontend object with user progress data replace the tags with quiz - related information based on the tags that have been found in the email .
// Replace each tag for quiz-related data. // Use existing frontend code to get the list of messages relating to tags. // Got open questions // Use existing frontend code to get the list of custom feedback messages. // Separate each custom feedback message slightly