public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/shortcodes.php
/**
 * Creates widget that shows off the user's progress on their respective courses.
 *
 *  e.g. [wpcourse_progress courses="2" user_progress="true" user_grade="true" /]
 *
 * @since 1.0.0
 *
 * @param array  $atts The attributes of the shortcode.
 * @param string $content The content of the shortcode.
 *
 * @return string
 */
Creates widget that shows off the user's progress on their respective courses.



@param array  $atts The attributes of the shortcode.
@param string $content The content of the shortcode.

@return string
Creates widget that shows off the user ' s progress on their respective courses . @param array $atts The attributes of the shortcode . @param string $content The content of the shortcode . @return string
function WPCW_shortcodes_showTrainingCourseProgress( $atts, $content ) {
	extract( shortcode_atts( array(
		'courses'              => 'all',
		'course_desc'          => false,
		'course_prerequisites' => false,
		'user_progress'        => true,
		'user_grade'           => true,
		'user_quiz_grade'      => false,
		'certificate'          => true,
		'hide_credit_link'     => false,
	), $atts ) );
	$showCourseDesc          = ( 'true' == strtolower( $course_desc ) );
	$showCoursePrerequisites = ( 'true' == strtolower( $course_prerequisites ) );
	$showUserProgress        = ( 'true' == strtolower( $user_progress ) );
	$showUserGrade           = ( 'true' == strtolower( $user_grade ) );
	$showCertificate         = ( 'true' == strtolower( $certificate ) );
	$user_id = get_current_user_id();
	if ( ! $user_id ) {
		return sprintf( __( '<div class="wpcw_fe_progress_box_wrap"><div class="wpcw_fe_progress_box wpcw_fe_progress_box_error">%s</div></div>', 'wp-courseware' ),
			apply_filters( 'wpcw_front_shortcode_wpcourse_progress_notloggedin', __( 'You need to be logged in to see your course progress.', 'wp-courseware' ) )
		);
	}
	$courseList         = WPCW_users_getUserCourseList( $user_id );
	$selectedCourseList = array();
	if ( ! empty( $courseList ) && 'all' != strtolower( $courses ) ) {
		$selectedCourseList = explode( ',', $courses );
		$chosenListOfCourses = array();
		if ( ! empty( $selectedCourseList ) ) {
			foreach ( $selectedCourseList as $potentialItem ) {
				$potentialItem = trim( $potentialItem );
				if ( preg_match( '/^([0-9]+)$/', $potentialItem ) ) {
					foreach ( $courseList as $idx => $aSingleCourse ) {
						if ( $potentialItem == $aSingleCourse->course_id ) {
							$chosenListOfCourses[] = $aSingleCourse;
							unset( $courseList[ $idx ] );
							break;
						}
					}
				}
			}
		}
		$courseList = $chosenListOfCourses;
	}
	if ( empty( $courseList ) ) {
		$messageToShow = __( 'You are not enrolled in any courses.', 'wp-courseware' );
		if ( ! empty( $selectedCourseList ) ) {
			$messageToShow = __( 'You are not enrolled in any of these courses.', 'wp-courseware' );
		}
		return sprintf( __( '<div class="wpcw_fe_progress_box_wrap"><div class="wpcw_fe_progress_box wpcw_fe_progress_box_error">%s</div></div>', 'wp-courseware' ),
			apply_filters( 'wpcw_front_shortcode_wpcourse_progress_no_courses', $messageToShow, count( $courseList ) )
		);
	}
	$columnCount = 1;
	$html = '<table id="wpcw_fe_course_progress" class="wpcw_fe_table wpcw_fe_summary_course_progress">';
	$html .= '<thead><tr>';
	$html .= sprintf( '<th class="wpcw_fe_course_progress_course">%s</th>', __( 'Course', 'wp-courseware' ) );
	if ( $showUserProgress ) {
		$columnCount ++;
		$html .= sprintf( '<th class="wpcw_fe_course_progress_pc">%s</th>', __( 'Progress', 'wp-courseware' ) );
	}
	if ( $showUserGrade ) {
		$columnCount ++;
		$html .= sprintf( '<th class="wpcw_fe_course_progress_grade">%s</th>', __( 'Overall Grade', 'wp-courseware' ) );
	}
	if ( $showCertificate ) {
		$columnCount ++;
		$html .= sprintf( '<th class="wpcw_fe_course_progress_certificate">%s</th>', __( 'Certificate', 'wp-courseware' ) );
	}
	$html .= '</tr></thead><tbody>';
	foreach ( $courseList as $aSingleCourse ) {
		$html .= '<tr class="wpcw_fe_course_progress_row">';
		$html .= sprintf( __( '<td class="wpcw_fe_course_progress_course"><a href="#" data-toggle="wpcw_fe_course_progress_detail_%d">%s</a></td>', 'wp-courseware' ), $aSingleCourse->course_id, $aSingleCourse->course_title );
		if ( $showUserProgress ) {
			$html .= sprintf( '<td class="wpcw_fe_course_progress_pc">%s</td>', WPCW_content_progressBar( $aSingleCourse->course_progress ) );
		}
		if ( $showUserGrade ) {
			$overallGrade = WPCW_courses_getCourseCumulativeGrade( $aSingleCourse->course_id, $user_id );
			if ( $overallGrade === '-' || $overallGrade === 'N/A' ) {
				$html .= sprintf( '<td class="wpcw_fe_course_progress_grade">%s</td>', $overallGrade );
			} else {
				$html .= sprintf( '<td class="wpcw_fe_course_progress_grade">%s%%</td>', $overallGrade );
			}
		}
		if ( $showCertificate ) {
			$courseDetails     = WPCW_courses_getCourseDetails( $aSingleCourse->course_id );
			$usingCertificates = ( 'use_certs' == $courseDetails->course_opt_use_certificate );
			if ( $usingCertificates && $certificateDetails = WPCW_certificate_getCertificateDetails( $user_id, $aSingleCourse->course_id, false ) ) {
				$html .= sprintf( '<td class="wpcw_fe_course_progress_certificate"><a href="%s" class="fe_btn fe_btn_download" target="_blank">%s</a></td>',
					WPCW_certificate_generateLink( $certificateDetails->cert_access_key ), __( 'Download Certificate', 'wp-courseware' ) );
			} else {
				$html .= sprintf( '<td class="wpcw_fe_course_progress_certificate">%s</td>', __( 'Not available', 'wp-courseware' ) );
			}
		}
		$html .= '</tr>';
		$html .= sprintf( '<tr><td class="wpcw_fe_course_progress_detail" id="wpcw_fe_course_progress_detail_%d" colspan="%d">',
			$aSingleCourse->course_id, $columnCount
		);
		if ( $showCourseDesc ) {
			$html .= sprintf( '<div class="wpcw_fe_course_progress_desc" id="wpcw_fe_course_progress_desc_%d">%s</div>', $aSingleCourse->course_id, $aSingleCourse->course_desc );
		}
		if ( $showCoursePrerequisites ) {
			$coursePrerequisites = WPCW_users_getCoursePrerequisites( $aSingleCourse->course_id );
			if ( $coursePrerequisites ) {
				$html .= sprintf( '<div class="wpcw_fe_course_progress_prerequisites" id="wpcw_fe_course_progress_prerequisites_%d">', $aSingleCourse->course_id );
				$html .= '<table class="wpcw_fe_course_prerequisites_table wpcw_fe_table" cellspacing="0" cellpadding="0">';
				$html .= '<tbody>';
				$html .= '<tr class="wpcw_fe_course_prerequisites_header">';
				$html .= sprintf( '<td class="wpcw_fe_course_prerequisites_header_column" colspan="2">%s</td>', esc_html__( 'Course Prerequisites', 'wp-courseware' ) );
				$html .= '</tr>';
				foreach ( $coursePrerequisites as $coursePrerequisite ) {
					$course = new Course( $coursePrerequisite );
					$html .= '<tr class="wpcw_fe_course_prerequisites_row">';
					$html .= sprintf( '<td class="wpcw_fe_course_prerequisites_column_title"><a target="_blank" href="%s">%s</a></td>', $course->get_permalink(), $course->get_course_title() );
					$html .= '<td class="wpcw_fe_course_prerequisites_column_complete">';
					if ( wpcw_has_student_completed_course( $user_id, $course->get_id() ) ) {
						$html .= '<span class="wpcw_checkmark"></span>';
					} else {
						$html .= '<span class="wpcw_circle"></span>';
					}
					$html .= '</td>';
					$html .= '</tr>';
				}
				$html .= '</tbody>';
				$html .= '</table>';
				$html .= '</div>';
			}
		}
		$html .= WPCW_courses_renderCourseList( $aSingleCourse->course_id, array( 'hide_credit_link' => true, 'user_quiz_grade' => $user_quiz_grade ) );
		$html .= '</td></tr>';
	}
	$html .= '</tbody></table>'; 
	if ( ! $hide_credit_link ) {
		$html .= WPCW_generatedPoweredByLink();
	}
	return $html;
}
function WPCW_shortcodes_showTrainingCourseProgress ( $ atts , $ content ) { extract ( shortcode_atts ( array ( 'courses' => 'all' , 'course_desc' => false , 'course_prerequisites' => false , 'user_progress' => true , 'user_grade' => true , 'user_quiz_grade' => false , 'certificate' => true , 'hide_credit_link' => false , ) , $ atts ) ) ; $ showCourseDesc = ( 'true' == strtolower ( $ course_desc ) ) ; $ showCoursePrerequisites = ( 'true' == strtolower ( $ course_prerequisites ) ) ; $ showUserProgress = ( 'true' == strtolower ( $ user_progress ) ) ; $ showUserGrade = ( 'true' == strtolower ( $ user_grade ) ) ; $ showCertificate = ( 'true' == strtolower ( $ certificate ) ) ; $ user_id = get_current_user_id ( ) ; if ( ! $ user_id ) { return sprintf ( __ ( '<div class="wpcw_fe_progress_box_wrap"><div class="wpcw_fe_progress_box wpcw_fe_progress_box_error">%s</div></div>' , 'wp-courseware' ) , apply_filters ( 'wpcw_front_shortcode_wpcourse_progress_notloggedin' , __ ( 'You need to be logged in to see your course progress.' , 'wp-courseware' ) ) ) ; } $ courseList = WPCW_users_getUserCourseList ( $ user_id ) ; $ selectedCourseList = array ( ) ; if ( ! empty ( $ courseList ) && 'all' != strtolower ( $ courses ) ) { $ selectedCourseList = explode ( ',' , $ courses ) ; $ chosenListOfCourses = array ( ) ; if ( ! empty ( $ selectedCourseList ) ) { foreach ( $ selectedCourseList as $ potentialItem ) { $ potentialItem = trim ( $ potentialItem ) ; if ( preg_match ( '/^([0-9]+)$/' , $ potentialItem ) ) { foreach ( $ courseList as $ idx => $ aSingleCourse ) { if ( $ potentialItem == $ aSingleCourse -> course_id ) { $ chosenListOfCourses [ ] = $ aSingleCourse ; unset ( $ courseList [ $ idx ] ) ; break ; } } } } } $ courseList = $ chosenListOfCourses ; } if ( empty ( $ courseList ) ) { $ messageToShow = __ ( 'You are not enrolled in any courses.' , 'wp-courseware' ) ; if ( ! empty ( $ selectedCourseList ) ) { $ messageToShow = __ ( 'You are not enrolled in any of these courses.' , 'wp-courseware' ) ; } return sprintf ( __ ( '<div class="wpcw_fe_progress_box_wrap"><div class="wpcw_fe_progress_box wpcw_fe_progress_box_error">%s</div></div>' , 'wp-courseware' ) , apply_filters ( 'wpcw_front_shortcode_wpcourse_progress_no_courses' , $ messageToShow , count ( $ courseList ) ) ) ; } $ columnCount = 1 ; $ html = '<table id="wpcw_fe_course_progress" class="wpcw_fe_table wpcw_fe_summary_course_progress">' ; $ html .= '<thead><tr>' ; $ html .= sprintf ( '<th class="wpcw_fe_course_progress_course">%s</th>' , __ ( 'Course' , 'wp-courseware' ) ) ; if ( $ showUserProgress ) { $ columnCount ++ ; $ html .= sprintf ( '<th class="wpcw_fe_course_progress_pc">%s</th>' , __ ( 'Progress' , 'wp-courseware' ) ) ; } if ( $ showUserGrade ) { $ columnCount ++ ; $ html .= sprintf ( '<th class="wpcw_fe_course_progress_grade">%s</th>' , __ ( 'Overall Grade' , 'wp-courseware' ) ) ; } if ( $ showCertificate ) { $ columnCount ++ ; $ html .= sprintf ( '<th class="wpcw_fe_course_progress_certificate">%s</th>' , __ ( 'Certificate' , 'wp-courseware' ) ) ; } $ html .= '</tr></thead><tbody>' ; foreach ( $ courseList as $ aSingleCourse ) { $ html .= '<tr class="wpcw_fe_course_progress_row">' ; $ html .= sprintf ( __ ( '<td class="wpcw_fe_course_progress_course"><a href="#" data-toggle="wpcw_fe_course_progress_detail_%d">%s</a></td>' , 'wp-courseware' ) , $ aSingleCourse -> course_id , $ aSingleCourse -> course_title ) ; if ( $ showUserProgress ) { $ html .= sprintf ( '<td class="wpcw_fe_course_progress_pc">%s</td>' , WPCW_content_progressBar ( $ aSingleCourse -> course_progress ) ) ; } if ( $ showUserGrade ) { $ overallGrade = WPCW_courses_getCourseCumulativeGrade ( $ aSingleCourse -> course_id , $ user_id ) ; if ( $ overallGrade === '-' || $ overallGrade === 'N/A' ) { $ html .= sprintf ( '<td class="wpcw_fe_course_progress_grade">%s</td>' , $ overallGrade ) ; } else { $ html .= sprintf ( '<td class="wpcw_fe_course_progress_grade">%s%%</td>' , $ overallGrade ) ; } } if ( $ showCertificate ) { $ courseDetails = WPCW_courses_getCourseDetails ( $ aSingleCourse -> course_id ) ; $ usingCertificates = ( 'use_certs' == $ courseDetails -> course_opt_use_certificate ) ; if ( $ usingCertificates && $ certificateDetails = WPCW_certificate_getCertificateDetails ( $ user_id , $ aSingleCourse -> course_id , false ) ) { $ html .= sprintf ( '<td class="wpcw_fe_course_progress_certificate"><a href="%s" class="fe_btn fe_btn_download" target="_blank">%s</a></td>' , WPCW_certificate_generateLink ( $ certificateDetails -> cert_access_key ) , __ ( 'Download Certificate' , 'wp-courseware' ) ) ; } else { $ html .= sprintf ( '<td class="wpcw_fe_course_progress_certificate">%s</td>' , __ ( 'Not available' , 'wp-courseware' ) ) ; } } $ html .= '</tr>' ; $ html .= sprintf ( '<tr><td class="wpcw_fe_course_progress_detail" id="wpcw_fe_course_progress_detail_%d" colspan="%d">' , $ aSingleCourse -> course_id , $ columnCount ) ; if ( $ showCourseDesc ) { $ html .= sprintf ( '<div class="wpcw_fe_course_progress_desc" id="wpcw_fe_course_progress_desc_%d">%s</div>' , $ aSingleCourse -> course_id , $ aSingleCourse -> course_desc ) ; } if ( $ showCoursePrerequisites ) { $ coursePrerequisites = WPCW_users_getCoursePrerequisites ( $ aSingleCourse -> course_id ) ; if ( $ coursePrerequisites ) { $ html .= sprintf ( '<div class="wpcw_fe_course_progress_prerequisites" id="wpcw_fe_course_progress_prerequisites_%d">' , $ aSingleCourse -> course_id ) ; $ html .= '<table class="wpcw_fe_course_prerequisites_table wpcw_fe_table" cellspacing="0" cellpadding="0">' ; $ html .= '<tbody>' ; $ html .= '<tr class="wpcw_fe_course_prerequisites_header">' ; $ html .= sprintf ( '<td class="wpcw_fe_course_prerequisites_header_column" colspan="2">%s</td>' , esc_html__ ( 'Course Prerequisites' , 'wp-courseware' ) ) ; $ html .= '</tr>' ; foreach ( $ coursePrerequisites as $ coursePrerequisite ) { $ course = new Course ( $ coursePrerequisite ) ; $ html .= '<tr class="wpcw_fe_course_prerequisites_row">' ; $ html .= sprintf ( '<td class="wpcw_fe_course_prerequisites_column_title"><a target="_blank" href="%s">%s</a></td>' , $ course -> get_permalink ( ) , $ course -> get_course_title ( ) ) ; $ html .= '<td class="wpcw_fe_course_prerequisites_column_complete">' ; if ( wpcw_has_student_completed_course ( $ user_id , $ course -> get_id ( ) ) ) { $ html .= '<span class="wpcw_checkmark"></span>' ; } else { $ html .= '<span class="wpcw_circle"></span>' ; } $ html .= '</td>' ; $ html .= '</tr>' ; } $ html .= '</tbody>' ; $ html .= '</table>' ; $ html .= '</div>' ; } } $ html .= WPCW_courses_renderCourseList ( $ aSingleCourse -> course_id , array ( 'hide_credit_link' => true , 'user_quiz_grade' => $ user_quiz_grade ) ) ; $ html .= '</td></tr>' ; } $ html .= '</tbody></table>' ; if ( ! $ hide_credit_link ) { $ html .= WPCW_generatedPoweredByLink ( ) ; } return $ html ; }
Creates widget that shows off the user's progress on their respective courses.
Creates widget that shows off the user ' s progress on their respective courses .
// Check flags to see what we're showing // Show a message to the user if they are not logged in. // Get a list of all of the courses that the user is subscribed to. // Filter the list of courses to remove the ones that the trainer doesn't // want the user to see. 'all' means show all courses with no filtering. // Only do this check if we have any courses to check, to save time. // This is the list of courses we'll actually use. // We've got courses that have been specified, so we need to go through them now. // Got a potential ID here. // Check each course we still have to see if the ID matches. // I know it's O(N), but it's simple at least. // Got a match... // Move the chosen course to the selected list. Doing // so makes subsequent searches faster. // Overwrite the list of courses to use. // Handle when the list is empty // Change message slightly based on how many courses are selected. // Used to determine how many columns we have in the table for showing the course details. // Show the list of courses // The title bar for the course. // Course name // Course progress // Overall grade so far // Overall grade so far // The main body of the course information. // Course name // Course progress // Show the Overall grade so far // Show certificate for course if available // Generate certificate button if enabled and a certificate exists for this user. // Show full course details. This might be a setting at some point. // end .wpcw_fe_summary_course_progress