__( 'Please log in to view your enrolled courses.', 'academy' ) ]
);
printf( '
%2$s
', get_block_wrapper_attributes( [ 'style' => \Academy\Blocks::academy_colors_style( $attributes ) ] ), ob_get_clean() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- core wrapper attributes and an escaped template.
return;
}
$academy_user_id = get_current_user_id();
$academy_show = in_array( $attributes['show'] ?? 'all', [ 'all', 'in-progress', 'completed' ], true ) ? $attributes['show'] : 'all';
// A student can hold more than one enrolment record for a course.
$academy_ids = array_values( array_unique( array_map( 'intval', (array) \Academy\Helper::get_enrolled_courses_ids_by_user( $academy_user_id ) ) ) );
$academy_completed = array_map( 'intval', (array) \Academy\Helper::get_completed_courses_ids_by_user( $academy_user_id ) );
if ( 'completed' === $academy_show ) {
$academy_ids = array_values( array_intersect( $academy_ids, $academy_completed ) );
} elseif ( 'in-progress' === $academy_show ) {
$academy_ids = array_values( array_diff( $academy_ids, $academy_completed ) );
}
\Academy\Blocks::use_course_assets();
$academy_wrapper = get_block_wrapper_attributes(
[
'class' => 'is-style-progress',
'style' => \Academy\Blocks::academy_colors_style( $attributes ),
]
);
if ( empty( $academy_ids ) ) {
$academy_messages = [
'all' => __( 'You have not enrolled in any courses yet.', 'academy' ),
'in-progress' => __( 'No courses in progress. Every course you enrolled in is finished.', 'academy' ),
'completed' => __( 'No finished courses yet. Keep going!', 'academy' ),
];
ob_start();
\Academy\Helper::get_template(
'shortcode/academy-enrolled-courses/empty-state.php',
[
'message' => $academy_messages[ $academy_show ],
'browse_url' => get_post_type_archive_link( 'academy_courses' ),
]
);
printf( '%s
', $academy_wrapper, ob_get_clean() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- core wrapper attributes and an escaped template.
return;
}
// WP paginates a singular page with `page`, an archive with `paged`.
$academy_paged = max( 1, (int) ( get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' ) ) );
$academy_query = new WP_Query(
[
'post_type' => 'academy_courses',
'post__in' => $academy_ids,
'orderby' => 'post__in',
'posts_per_page' => $academy_count,
'paged' => $academy_paged,
'ignore_sticky_posts' => true,
]
);
$academy_date_format = get_option( 'date_format' );
// Small line icons for the facts under the progress bar.
$academy_icons = [
'lesson' => '',
'quiz' => '',
'assignment' => '',
'enrolled' => '',
];
$academy_icon = static function ( $name ) use ( $academy_icons ) {
return '';
};
?>
>
posts as $academy_course ) :
$academy_course_id = (int) $academy_course->ID;
$academy_total = (int) \Academy\Helper::get_total_number_of_course_topics( $academy_course_id );
$academy_done = min( $academy_total, (int) \Academy\Helper::get_total_number_of_completed_course_topics_by_course_and_student_id( $academy_course_id, $academy_user_id ) );
$academy_finished = in_array( $academy_course_id, $academy_completed, true );
$academy_percent = $academy_finished ? 100 : ( $academy_total ? (int) floor( $academy_done / $academy_total * 100 ) : 0 );
$academy_counts = \Academy\Helper::get_course_curriculums_number_of_counts( $academy_course_id );
$academy_enrolment = \Academy\Helper::is_enrolled( $academy_course_id, $academy_user_id );
$academy_image = \Academy\Helper::get_the_course_thumbnail_url_by_id( $academy_course_id, 'medium_large' );
if ( $academy_finished ) {
$academy_state = 'completed';
$academy_label = __( 'Completed', 'academy' );
$academy_button = __( 'Review course', 'academy' );
} elseif ( $academy_done > 0 ) {
$academy_state = 'in-progress';
$academy_label = __( 'In progress', 'academy' );
$academy_button = __( 'Continue learning', 'academy' );
} else {
$academy_state = 'not-started';
$academy_label = __( 'Not started', 'academy' );
$academy_button = __( 'Start course', 'academy' );
}
$academy_facts = [];
if ( ! empty( $attributes['showTopics'] ) ) {
if ( ! empty( $academy_counts['total_lessons'] ) ) {
/* translators: %s: number of lessons. */
$academy_facts[] = [ 'lesson', sprintf( _n( '%s lesson', '%s lessons', $academy_counts['total_lessons'], 'academy' ), number_format_i18n( $academy_counts['total_lessons'] ) ) ];
}
if ( ! empty( $academy_counts['total_quizzes'] ) ) {
/* translators: %s: number of quizzes. */
$academy_facts[] = [ 'quiz', sprintf( _n( '%s quiz', '%s quizzes', $academy_counts['total_quizzes'], 'academy' ), number_format_i18n( $academy_counts['total_quizzes'] ) ) ];
}
if ( ! empty( $academy_counts['total_assignments'] ) ) {
/* translators: %s: number of assignments. */
$academy_facts[] = [ 'assignment', sprintf( _n( '%s assignment', '%s assignments', $academy_counts['total_assignments'], 'academy' ), number_format_i18n( $academy_counts['total_assignments'] ) ) ];
}
}
?>
-
post_date ) ) ) : ?>
post_date ) ) : ?>
-
post_date ) ) );
?>
max_num_pages > 1 ) {
$academy_links = paginate_links(
[
'current' => $academy_paged,
'total' => $academy_query->max_num_pages,
'type' => 'list',
]
);
if ( $academy_links ) {
echo '';
}
}
?>