setup_query();
}
protected function setup_query()
{
global $post;
if (empty($post) || empty($post->ID)) {
return;
}
$with = ['sections'];
$this->enable_rating_and_reviews = acadlix()->helper()->acadlix_get_option('acadlix_enable_rating_and_reviews') === 'yes';
$this->require_admin_approval_for_reviews = acadlix()->helper()->acadlix_get_option('acadlix_require_admin_approval_for_reviews') === 'yes';
$this->review_pagination_count = (int) acadlix()->helper()->acadlix_get_option('acadlix_review_pagination_count') ?: 10;
$this->disable_student_enrolled = acadlix()->helper()->acadlix_get_option('acadlix_disable_student_enrolled') === 'yes';
$this->checkout_url = get_permalink(acadlix()->helper()->acadlix_get_option('acadlix_checkout_page_id'));
$this->dashboard_url = get_permalink(acadlix()->helper()->acadlix_get_option('acadlix_dashboard_page_id'));
$this->course = acadlix()->model()->course()->ofCourse()->with($with)->find($post->ID);
if (is_null($this->course)) {
return;
}
if (is_user_logged_in()) {
$this->user_id = get_current_user_id() ?? 0;
$this->cart = acadlix()->model()->courseCart()->where([
['user_id', '=', $this->user_id],
['item_id', '=', $post->ID],
])->first();
$this->is_course_purchased = $this->course->isPurchasedBy($this->user_id);
} else {
if (isset($_COOKIE['acadlix_cart_token'])) {
$this->cart = acadlix()
->model()
->courseCart()
->where('cart_token', sanitize_text_field(wp_unslash($_COOKIE['acadlix_cart_token'])))
->where('item_id', $post->ID)
->first();
}
}
$this->average_rating = $this->course->getAverageRating() ?? 0;
$this->total_rating = $this->course->getTotalRatings() ?? 0;
if ($this->enable_rating_and_reviews) {
$this->comments = acadlix()
->model()
->courseReview()
->ofCourseRating()
->ofApproved()
->where('comment_post_ID', $post->ID)
->orderBy('comment_date', 'DESC')
->skip(0)
->take($this->review_pagination_count)
->get();
$this->rating_breakdown = $this->course->getRatingBreakdown();
if (is_user_logged_in()) {
$this->user_comment = acadlix()
->model()
->courseReview()
->ofCourseRating()
->where('comment_post_ID', $post->ID)
->where('user_id', $this->user_id)
->first();
}
}
}
/**
* Outputs the HTML for a course breadcrumb navigation with specific display settings.
*
* @param bool $desktop Determines if the breadcrumb should be displayed on desktop.
* @param bool $mobile Determines if the breadcrumb should be displayed on mobile.
*
* @return array The HTML for a course breadcrumb navigation
*/
protected function acadlix_course_breadcrumb(bool $desktop = true, bool $mobile = true)
{
if (!is_bool($desktop) || !is_bool($mobile)) {
// error_log('The parameters must be boolean values.');
}
$classes = ['acadlix-course-breadcrumb'];
if ($desktop && !$mobile) {
$classes[] = 'acadlix-course-breadcrumb-only-desktop';
}
if (!$desktop && $mobile) {
$classes[] = 'acadlix-course-breadcrumb-only-mobile';
}
?>
'nav',
'props' => [
'class' => esc_attr(implode(' ', $classes))
],
'children' =>
[
[
'component' => 'a',
'props' => [
'href' => esc_url(home_url()),
'class' => 'acadlix-course-breadcrumb acadlix-subtitle1'
],
'value' => __('Home', 'acadlix')
],
[
'component' => 'span',
'value' => ' > '
],
!empty($categories = get_the_terms($this->course->ID, ACADLIX_COURSE_CATEGORY_TAXONOMY)) && !is_wp_error($categories) ? [
'component' => 'a',
'props' => [
'href' => esc_attr(get_term_link($categories[0]->term_id, ACADLIX_COURSE_CATEGORY_TAXONOMY)),
'class' => 'acadlix-course-breadcrumb acadlix-subtitle1'
],
'value' => esc_html($categories[0]->name)
] : null,
!empty($categories) && !is_wp_error($categories) ? [
'component' => 'span',
'value' => ' > '
] : null,
[
'component' => 'a',
'props' => [
'href' => '#',
'disabled' => 'true',
'class' => 'acadlix-course-breadcrumb acadlix-subtitle1'
],
'children' => [
[
'component' => 'php',
'value' => function () use ($mobile) {
$title = $this->course->post_title;
if ($mobile && strlen($title) > 15) {
return esc_html(mb_substr($title, 0, 15)) . '...';
}
return esc_html($title);
}
]
]
]
]
];
return apply_filters('acadlix_single_course_breadcrumb', $breadcrumb, $this->course, $desktop, $mobile);
}
/**
* Outputs the HTML for a course image with specific display settings.
*
* @param bool $desktop Determines if the course image should be displayed on desktop.
* @param bool $mobile Determines if the course image should be displayed on mobile.
*
* @return array The HTML for a course image
*/
protected function acadlix_course_img(bool $desktop = true, bool $mobile = true)
{
if (is_null($desktop) || is_null($mobile)) {
// error_log('The parameters must be boolean values.');
}
$classes = ['acadlix-course-featured-item'];
if ($desktop && !$mobile) {
$classes[] = 'acadlix-course-featured-item-only-desktop';
}
if (!$desktop && $mobile) {
$classes[] = 'acadlix-course-featured-item-only-mobile';
}
?>
'img',
'props' => [
'class' => esc_attr(implode(' ', $classes)),
'loading' => 'lazy',
'src' => esc_url(isset($this->course->thumbnail['url']) ? $this->course->thumbnail['url'] : ACADLIX_ASSETS_IMAGE_URL . 'demo-course.jpg'),
'alt' => isset($this->course->thumbnail['alt']) ? esc_attr($this->course->thumbnail['alt']) : esc_attr($this->course?->post_title)
]
];
return apply_filters('acadlix_single_course_img', $img_component, $this->course, $desktop, $mobile);
}
/**
* Function to display course pricing
*
* @return array
*/
protected function acadlix_course_pricing($type = 'desktop')
{
$enable_sale_price = $this->course->rendered_metas['enable_sale_price'] ?? false;
$price = $this->course->rendered_metas['price'] ?? 0;
$sale_price = $this->course->rendered_metas['sale_price'] ?? 0;
$price_component = [
'component' => 'div',
'props' => [
'class' => 'acadlix-pricing-info'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-pricing'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-sale-price acadlix-h4'
],
'value' => esc_html(acadlix()->helper()->course()->getCoursePrice($enable_sale_price ? $sale_price : $price))
],
$enable_sale_price ? [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-price acadlix-subtitle1'
],
'value' => esc_html(acadlix()->helper()->course()->getCoursePrice($price))
] : null
]
],
($enable_sale_price && $price != 0 && $price > $sale_price) ? [
'component' => 'div',
'props' => [
'class' => 'acadlix-discount-tag acadlix-body1'
],
'value' => esc_html(ceil((($price - $sale_price) / $price) * 100)) . '% ' . esc_html__('OFF', 'acadlix')
] : null
]
];
return apply_filters(
'acadlix_single_course_pricing',
$price_component,
$this->course,
$type
);
}
/**
* Displays the price of a course in a mobile-friendly format.
*
* @return array The HTML content for the mobile price info.
*/
protected function acadlix_mobile_course_price()
{
$enable_sale_price = $this->course->rendered_metas['enable_sale_price'] ?? false;
$price = $this->course->rendered_metas['price'] ?? 0;
$sale_price = $this->course->rendered_metas['sale_price'] ?? 0;
$price_component = [
'component' => 'div',
'props' => [
'class' => 'acadlix-mobile-price-info'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-pricing'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-sale-price acadlix-h4'
],
'value' => esc_html(acadlix()->helper()->course()->getCoursePrice($enable_sale_price ? $sale_price : $price))
],
$enable_sale_price ? [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-price acadlix-subtitle1'
],
'value' => esc_html(acadlix()->helper()->course()->getCoursePrice($this->course->rendered_metas['price']))
] : null
]
],
]
];
return apply_filters('acadlix_single_course_mobile_price', $price_component, $this->course);
}
protected function acadlix_course_tags()
{
if (count($this->course->course_tags) == 0) {
return [];
}
$tags = [];
foreach ($this->course->course_tags as $tag) {
$tags[] = sprintf(
// translators: 1: tag link 2: tag name
'%2$s',
esc_url(get_term_link($tag->term_id, ACADLIX_COURSE_TAG_TAXONOMY)),
esc_html($tag->term->name)
);
}
return apply_filters('acadlix_single_course_tags', [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-aside-details-option'
],
'children' => [
[
'component' => 'div',
'children' => [
[
'component' => 'strong',
'value' => count($this->course->course_tags) > 1 ? esc_html__('Tags:', 'acadlix') : esc_html__('Tag:', 'acadlix'),
]
]
],
[
'component' => 'div',
'props' => ['class' => 'acadlix-course-tags acadlix-body1'],
'value' => implode(', ', $tags)
]
]
], $this->course);
}
protected function acadlix_student_enrolled()
{
if ($this->disable_student_enrolled) {
return null;
}
$fake_students_count = $this->course->rendered_metas['fake_students_count'] ?? 0;
$student_count = $this->course->student_count ?? 0;
return apply_filters('acadlix_single_course_students_enrolled', [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-aside-details-option'
],
'children' => [
[
'component' => 'div',
'children' => [
[
'component' => 'strong',
'value' => esc_html__('Students Enrolled:', 'acadlix'),
]
]
],
[
'component' => 'div',
'value' => esc_html($student_count + $fake_students_count),
]
]
], $this->course);
}
protected function acadlix_basic_course_details(bool $desktop = true, bool $mobile = true)
{
if (!is_bool($desktop) || !is_bool($mobile)) {
// error_log('The parameters must be boolean values.');
}
$duration = $this->course->rendered_metas['duration']['duration'] ?? 0;
$duration_type = $this->course->rendered_metas['duration']['type'] ?? '';
$difficulty_level = $this->course->rendered_metas['difficulty_level'] ?? '';
$tax = $this->course->rendered_metas['tax'] ?? 0;
$tax_percent = $this->course->rendered_metas['tax_percent'] ?? 0;
$classes = ['acadlix-course-aside-details'];
if ($desktop && !$mobile) {
$classes[] = 'acadlix-course-aside-details-only-desktop';
}
if (!$desktop && $mobile) {
$classes[] = 'acadlix-course-aside-details-only-mobile';
}
?>
'div',
'props' => [
'class' => 'acadlix-course-aside-details acadlix-subtitle2 ' . esc_attr(implode(' ', $classes))
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-aside-details-option'
],
'children' => [
[
'component' => 'div',
'children' => [
[
'component' => 'strong',
'value' => esc_html__('Course Duration:', 'acadlix'),
]
]
],
[
'component' => 'div',
'value' => esc_html("{$duration} {$duration_type}"),
]
]
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-aside-details-option'
],
'children' => [
[
'component' => 'div',
'children' => [
[
'component' => 'strong',
'value' => esc_html__('Course Level:', 'acadlix'),
]
]
],
[
'component' => 'div',
'value' => esc_html(acadlix()->helper()->course()->getCourseLevelName($difficulty_level ?? '')),
],
]
],
$this->acadlix_student_enrolled(),
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-aside-details-option'
],
'children' => [
[
'component' => 'div',
'children' => [
[
'component' => 'strong',
'value' => esc_html__('Tax:', 'acadlix'),
]
]
],
[
'component' => 'div',
'value' => esc_html($tax ? $tax_percent : 0) . '%',
]
]
]
]
];
return apply_filters('acadlix_single_course_basic_course_details', $basic_course_details, $this->course, $desktop, $mobile);
}
protected function acadlix_course_checkout_button($type = 'desktop')
{
return apply_filters('acadlix_single_course_checkout_button', [
'component' => 'button',
'props' => [
'data-link' => esc_url($this->checkout_url),
'class' => 'acadlix-action-button acadlix-subtitle2 acadlix-go-to-checkout'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-action-button-text'
],
'value' => esc_html__('Go to Checkout', 'acadlix')
]
]
], $this->course, $type);
}
protected function acadlix_course_go_to_course_button($type = 'desktop')
{
return apply_filters('acadlix_single_course_go_to_course_button', [
'component' => 'button',
'props' => [
'data-link' => esc_url($this->dashboard_url . '#/courses'),
'class' => 'acadlix-action-button acadlix-subtitle2 acadlix-go-to-course'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-action-button-text'
],
'value' => esc_html__('Go to Course', 'acadlix')
]
]
], $this->course, $type);
}
protected function acadlix_course_start_now_button($type = 'desktop')
{
return apply_filters('acadlix_single_course_start_now_button', [
'component' => 'button',
'props' => [
'class' => 'acadlix-action-button acadlix-subtitle2 acadlix-start-now',
'data-id' => esc_attr($this->course->ID),
'data-type' => esc_attr($this->type),
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-action-button-text',
],
'value' => __('Start Now', 'acadlix'),
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-btn-loader',
],
],
],
], $this->course, $type);
}
protected function acadlix_course_buy_now_button($type = 'desktop')
{
return apply_filters('acadlix_single_course_buy_now_button', [
'component' => 'button',
'props' => [
'class' => 'acadlix-action-button acadlix-subtitle2 acadlix-buy-now',
'data-id' => esc_attr($this->course->ID),
'data-type' => esc_attr($this->type),
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-action-button-text',
],
'children' => [
[
'component' => 'i',
'props' => [
'class' => 'fa fa-shopping-cart',
],
],
[
'component' => 'span',
'props' => [
'class' => 'acadlix-action-button-buy-now-text',
],
'value' => __('Buy Now', 'acadlix'),
],
],
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-btn-loader',
],
],
],
], $this->course, $type);
}
protected function acadlix_course_error_button($check_registration_date)
{
return apply_filters('acadlix_single_course_error_button', [
'component' => 'div',
'props' => [
'class' => 'acadlix-action-error-message',
],
'value' => wp_kses($check_registration_date['message'], ['br' => []]),
], $this->course);
}
protected function acadlix_course_wishlist($type = 'desktop')
{
$wishlist = [];
if (is_user_logged_in() && acadlix()->helper()->acadlix_get_option('acadlix_disable_wishlist') === 'no') {
$course_wishlist_count = acadlix()
->model()
->userActivityMeta()
->ofWishlist()
->where([
'type_id' => $this->course->ID,
'user_id' => get_current_user_id(),
'type' => $this->type,
])
->count();
$wishlist = apply_filters('acadlix_single_course_whishlist', [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-wishlist',
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-page-icon-element acadlix-add-to-wishlist ' . ($course_wishlist_count == 0 ? '' : 'acadlix-hidden'),
'id' => 'add-to-wishlist-' . esc_attr($this->course->ID),
'title' => __('Add to Wishlist', 'acadlix'),
'data-id' => esc_attr($this->course->ID),
'data-type' => esc_attr($this->type),
],
'children' => [
['component' => 'i', 'props' => ['class' => 'far fa-heart']],
['component' => 'div', 'props' => ['class' => 'acadlix-btn-loader']],
],
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-page-icon-element acadlix-remove-from-wishlist ' . ($course_wishlist_count > 0 ? '' : 'acadlix-hidden'),
'id' => 'remove-from-wishlist-' . esc_attr($this->course->ID),
'title' => __('Remove From Wishlist', 'acadlix'),
'data-id' => esc_attr($this->course->ID),
'data-type' => esc_attr($this->type),
],
'children' => [
['component' => 'i', 'props' => ['class' => 'fas fa-heart']],
['component' => 'div', 'props' => ['class' => 'acadlix-btn-loader']],
],
],
]
], $this->course, $course_wishlist_count, $type);
}
return $wishlist;
}
protected function acadlix_course_button($type = 'desktop')
{
$course = $this->course;
$start_date = $course->rendered_metas['start_date'] ?? null;
$end_date = $course->rendered_metas['end_date'] ?? null;
if ($course->post_status != 'publish') {
return [];
}
$check_registration_date = acadlix()->helper()->course()->checkRegistrationDate($start_date, $end_date);
$button = [];
$checkout_button = $this->acadlix_course_checkout_button($type);
$go_to_course_button = $this->acadlix_course_go_to_course_button($type);
$start_now_button = $this->acadlix_course_start_now_button($type);
$buy_now_button = $this->acadlix_course_buy_now_button($type);
$error_button = $this->acadlix_course_error_button($check_registration_date);
if ($check_registration_date['status']) {
if ($course->isFree()) {
if ($this->is_course_purchased) {
$button = $go_to_course_button;
} elseif ($this->cart) {
$button = $checkout_button;
} else {
$button = $start_now_button;
}
} else {
if ($this->is_course_purchased) {
$button = $go_to_course_button;
} elseif ($this->cart) {
$button = $checkout_button;
} else {
$button = $buy_now_button;
}
}
} else {
$button = $error_button;
}
return $button;
}
/**
* Outputs the HTML for the course action buttons.
*
* @param object $cart The cart object.
* @param object $course The course object.
*
* @return array The HTML for the course action buttons.
*/
protected function acadlix_course_action_buttons($type = 'desktop'): array
{
$course = $this->course;
$button = $this->acadlix_course_button($type);
$wishlist = $this->acadlix_course_wishlist($type);
$action_button_component = [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-action-buttons',
],
'children' => [
$button,
$wishlist,
],
];
return apply_filters(
'acadlix_single_course_action_buttons',
$action_button_component,
$course,
$button,
$wishlist,
$type
);
}
public function render()
{
$this->render_header();
$this->render_content();
$this->render_footer();
}
protected function render_header()
{
global $wp_version;
if (version_compare($wp_version, '5.9', '>=') && function_exists('wp_is_block_theme') && wp_is_block_theme()) {
?>
>
get('TextDomain');
echo wp_kses_post(do_blocks(''));
} else {
get_header();
}
}
protected function render_content()
{
// acadlix()->helper()->acadlix_dd($this->course);
$course_content = [
[
'component' => 'main',
'props' => [
'class' => 'acadlix-course-page acadlix-my-16',
'id' => 'acadlix-single-course-page'
],
'children' => [
$this->course_listener(),
$this->acadlix_course_breadcrumb(false, true),
$this->course_header(),
$this->course_main(),
$this->course_mobile_footer(),
]
]
];
$course_content = apply_filters('acadlix_single_course_content', $course_content, $this->course);
acadlix()->helper()->acadlix_render_tree($course_content);
}
protected function course_listener()
{
return apply_filters('acadlix_single_course_listener', [
'component' => 'div',
'props' => [
'id' => 'acadlix-course-listener',
],
], $this->course);
}
protected function course_header()
{
$course_header = [
'component' => 'section',
'props' => [
'class' => 'acadlix-card acadlix-course-header-section acadlix-box-shadow-2'
],
'children' => [
// Main course image
$this->acadlix_course_img(false, true),
// Body
$this->course_header_body(),
// Aside
$this->course_header_aside()
]
];
$course_header = apply_filters('acadlix_single_course_header', $course_header, $this->course);
return $course_header;
}
protected function course_header_title()
{
return apply_filters('acadlix_single_course_header_title', [
'component' => 'h1',
'props' => [
'class' => 'acadlix-course-header-title acadlix-my-8'
],
'value' => esc_html($this->course->post_title)
], $this->course);
}
protected function course_header_last_update()
{
return apply_filters('acadlix_single_course_header_last_update', [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-header-last-updated acadlix-body1 acadlix-mb-8'
],
'children' => [
[
'component' => 'i',
'props' => ['class' => 'fa fa-exclamation-circle']
],
[
'component' => 'span',
'value' => esc_html__('Last updated', 'acadlix') . ': '
. esc_html(acadlix()->helper()->formatDate($this->course->post_date))
]
]
], $this->course);
}
protected function course_header_rating()
{
if (!$this->enable_rating_and_reviews) {
return [];
}
return apply_filters('acadlix_single_course_header_rating', [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-header-rating'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-rating-stars'
],
'children' => acadlix()->helper()->course()->courseReviewStar($this->average_rating)
],
[
'component' => 'div',
'props' => ['class' => 'acadlix-course-rating-value acadlix-body1'],
'value' => sprintf(
/* translators: 1: average rating, 2: total ratings */
esc_html__('%1$.2f (%2$d ratings)', 'acadlix'),
$this->average_rating,
$this->total_rating
)
]
]
], $this->course);
}
protected function course_header_author()
{
return apply_filters('acadlix_single_course_header_author', [
'component' => 'div',
'props' => ['class' => 'acadlix-course-header-author'],
'children' => [
[
'component' => 'div',
'props' => ['class' => 'acadlix-course-header-created-at-text acadlix-subtitle2'],
'value' => esc_html__('Created by', 'acadlix') . ':'
],
[
'component' => 'div',
'props' => ['class' => 'acadlix-course-author acadlix-body1'],
'value' => acadlix()->helper()->course()->getCourseUserHtml($this->course)
]
]
], $this->course);
}
protected function course_header_categories()
{
$categories = [];
foreach ($this->course->course_categories as $category) {
$term_link = get_term_link(
$category->term_id,
ACADLIX_COURSE_CATEGORY_TAXONOMY
);
if (is_wp_error($term_link)) {
continue; // skip invalid term
}
$categories[] = sprintf(
'
%2$s',
esc_url($term_link),
esc_html($category->term->name)
);
// $categories[] = sprintf(
// // translators: 1: category link 2: category name
// '
%2$s',
// esc_url(get_term_link($category->term_id, ACADLIX_COURSE_CATEGORY_TAXONOMY)),
// esc_html($category->term->name)
// );
}
return apply_filters('acadlix_single_course_header_categories', [
'component' => 'div',
'props' => ['class' => 'acadlix-course-header-categories'],
'children' => [
[
'component' => 'div',
'props' => ['class' => 'acadlix-course-header-categories-text acadlix-subtitle2'],
'value' => count($this->course->course_categories) > 1 ? esc_html__('Categories', 'acadlix') . ':' : esc_html__('Category', 'acadlix') . ':'
],
[
'component' => 'div',
'props' => ['class' => 'acadlix-course-categories acadlix-body1'],
'value' => implode(', ', $categories)
]
],
], $this->course);
}
protected function course_header_body()
{
return apply_filters('acadlix_single_course_header_body', [
'component' => 'div',
'props' => [
'class' => 'acadlix-card-body acadlix-course-header-body'
],
'children' => [
$this->acadlix_course_breadcrumb(true, false),
$this->course_header_title(),
$this->course_header_last_update(),
$this->course_header_rating(),
$this->course_header_author(),
$this->course_header_categories(),
[
'component' => 'div',
'props' => [
'class' => 'acadlix-mobile-price-info'
],
'children' => [
$this->acadlix_course_pricing('mobile')
]
],
$this->acadlix_basic_course_details(false, true),
]
], $this->course);
}
protected function course_header_aside()
{
return apply_filters('acadlix_single_course_header_aside', [
'component' => 'div',
'props' => ['class' => 'acadlix-course-aside acadlix-card'],
'children' => [
$this->acadlix_course_img(true, false),
[
'component' => 'div',
'props' => ['class' => 'acadlix-card-body acadlix-course-aside-body'],
'children' => [
$this->acadlix_course_pricing('desktop'),
[
'component' => 'div',
'props' => ['class' => 'acadlix-course-aside-purchase-options'],
'children' => [
$this->acadlix_course_action_buttons('desktop')
]
],
$this->acadlix_basic_course_details(true, false),
]
]
]
], $this->course);
}
protected function course_main()
{
return apply_filters('acadlix_single_course_main', [
'component' => 'section',
'props' => [
'class' => 'acadlix-course-main-section'
],
'children' => [
// Navbar Tabs
$this->course_main_navbar(),
// Overview Section
$this->course_main_overview(),
// Curriculum Section
$this->course_main_curriculum(),
// Requirements Section
$this->course_main_requirements(),
// Target Audience Section
$this->course_main_target_audience(),
// Course Resources Section
$this->course_main_resources(),
// FAQs Section
$this->course_main_faqs(),
// Instructor Section
$this->course_main_instructor(),
// Reviews Section
$this->course_main_reviews(),
]
], $this->course);
}
protected function course_main_navbar()
{
$review_list_item = [];
if ($this->enable_rating_and_reviews) {
$review_list_item[] = [
'component' => 'li',
'children' => [
[
'component' => 'a',
'props' => [
'href' => '#reviews',
'class' => 'acadlix-subtitle1'
],
'value' => esc_html__('Reviews', 'acadlix')
]
]
];
}
return apply_filters('acadlix_single_course_main_navbar', [
'component' => 'nav',
'props' => ['class' => 'acadlix-course-main-navbar'],
'children' => [
[
'component' => 'ul',
'props' => ['class' => 'acadlix-course-main-navbar-list'],
'children' => [
[
'component' => 'li',
'children' => [
[
'component' => 'a',
'props' => [
'href' => '#overview',
'class' => 'acadlix-subtitle1'
],
'value' => esc_html__('Overview', 'acadlix')
]
]
],
[
'component' => 'li',
'children' => [
[
'component' => 'a',
'props' => [
'href' => '#curriculum',
'class' => 'acadlix-subtitle1'
],
'value' => esc_html__('Curriculum', 'acadlix')
]
]
],
[
'component' => 'li',
'children' => [
[
'component' => 'a',
'props' => [
'href' => '#instructor',
'class' => 'acadlix-subtitle1'
],
'value' => esc_html__('Instructor', 'acadlix')
]
]
],
...$review_list_item
]
]
]
], $this->course);
}
protected function course_main_overview_outcomes_heading()
{
return apply_filters('acadlix_single_course_main_overview_outcomes_heading', [
'component' => 'h2',
'props' => [
'class' => 'acadlix-card-header'
],
'value' => esc_html__('What you will learn in this course', 'acadlix')
], $this->course);
}
protected function course_main_overview_single_outcome($outcome = '')
{
return apply_filters('acadlix_single_course_main_overview_single_outcome', [
'component' => 'div',
'props' => [
'class' => 'acadlix-col-12 acadlix-col-lg-6 acadlix-d-flex acadlix-align-center acadlix-gap-1 acadlix-mt-8'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-button-icon acadlix-p-4'
],
'children' => [
[
'component' => 'i',
'props' => [
'class' => 'fa fa-check'
]
]
]
],
[
'component' => 'span',
'props' => [
'class' => 'acadlix-body1'
],
'value' => esc_html($outcome)
]
]
], $this->course);
}
protected function course_main_overview_outcomes()
{
$outcome_list = [];
$outcomes = $this->course->rendered_metas['outcomes'] ?? [];
// Filter out empty/null items from the array
$valid_outcomes = array_filter($outcomes, function ($outcome) {
return !empty(trim($outcome)); // trim handles whitespace-only strings
});
// If there are no valid outcomes left, return null early
if (empty($valid_outcomes)) {
return null;
}
// Build the rendered outcome components
$outcome_list = array_map(function ($outcome) {
return $this->course_main_overview_single_outcome($outcome);
}, $valid_outcomes);
return [
'component' => 'div',
'props' => [
'class' => 'acadlix-card acadlix-box-shadow-2'
],
'children' => [
$this->course_main_overview_outcomes_heading(),
[
'component' => 'div',
'props' => [
'class' => 'acadlix-card-body'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-row'
],
'children' => array_values($outcome_list)
]
]
]
]
];
}
protected function course_main_overview_description_heading()
{
return apply_filters('acadlix_single_course_main_overview_description_heading', [
'component' => 'h2',
'props' => ['class' => 'acadlix-card-header'],
'value' => esc_html__('Description', 'acadlix')
], $this->course);
}
protected function course_main_overview_description()
{
if(empty($this->course->rendered_post_content)) {
return null; // Return null if the description is empty
}
return apply_filters('acadlix_single_course_main_overview_description', [
'component' => 'div',
'props' => [
'class' => 'acadlix-card acadlix-box-shadow-2'
],
'children' => [
$this->course_main_overview_description_heading(),
[
'component' => 'div',
'props' => ['class' => 'acadlix-card-body'],
'value' => $this->course->rendered_post_content
]
]
], $this->course);
}
protected function course_main_overview()
{
return apply_filters('acadlix_single_course_main_overview', [
'component' => 'div',
'props' => [
'id' => 'overview',
'class' => 'acadlix-course-overview acadlix-mb-16'
],
'children' => [
$this->course_main_overview_outcomes(),
$this->course_main_overview_description()
]
], $this->course);
}
protected function course_main_curriculum_content($i, $content, $c_index, $preview = false)
{
return apply_filters('acadlix_single_course_main_curriculum_content', [
'component' => 'div',
'props' => [
'class' => 'acadlix-curriculum-content-item',
'data-section-index' => esc_attr($i),
'data-content-index' => esc_attr($c_index),
'data-is-preview' => esc_attr($preview),
],
'children' => [
// left: icon + title
[
'component' => 'div',
'props' => [
'class' => 'acadlix-d-flex acadlix-align-center acadlix-gap-1'
],
'children' => [
[
'component' => 'span',
'props' => [
'class' => 'acadlix-content-icon'
],
'children' => [
[
'component' => 'php',
'value' => function () use ($content) {
$type = $content->contentable['type'];
$icon = '';
if ($type === 'lesson') {
$icon = $content->contentable_data?->rendered_metas['type'] === 'video'
? '
'
: '
';
} elseif ($type === 'quiz') {
$icon = '
';
} elseif ($type === 'assignment') {
$icon = '
';
}
return apply_filters(
'acadlix/single-course/content/icon',
$icon,
$content
);
}
]
]
],
[
'component' => 'span',
'props' => [
'class' => 'acadlix-content-text acadlix-body1'
],
'value' => esc_html($content->contentable['title'])
]
]
],
// right: duration + lock/eye
[
'component' => 'div',
'props' => [
'class' => 'acadlix-content-duration-icon acadlix-d-flex acadlix-gap-1 acadlix-justify-center acadlix-align-center'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-content-duration'
],
'children' => [
[
'component' => 'php',
'value' => function () use ($content) {
if ($content->contentable['type'] === 'lesson') {
if ($content->contentable_data?->rendered_metas['type'] === 'video') {
return esc_html(
acadlix()->helper()->course()->intToTimeFormat(
$content->contentable_data?->rendered_metas['hours'] ?? 0,
$content->contentable_data?->rendered_metas['minutes'] ?? 0,
$content->contentable_data?->rendered_metas['seconds'] ?? 0
)
);
}
}
return '';
}
]
]
],
[
'component' => 'php',
'value' => function () use ($content) {
return isset($content->rendered_metas['preview']) && $content->rendered_metas['preview']
? '
'
: '
';
}
]
]
]
]
], $content, $c_index, $preview);
}
protected function course_main_curriculum_section($section, $i)
{
$contents = $section->contents;
$content_list = [];
if ($contents->count() > 0) {
foreach ($contents as $c_index => $content) {
$preview = $content->rendered_metas['preview'] ?? false;
$content_list[] = $this->course_main_curriculum_content(
$i,
$content,
$c_index,
$preview
);
}
}
return [
'component' => 'div',
'props' => [
'class' => 'acadlix-curriculum-item'
],
'children' =>
[
[
'component' => 'details',
'props' => [
'class' => 'acadlix-curriculum-details',
// add open attribute if first section
'open' => $i === 0 ? true : null,
],
'children' => [
[
'component' => 'summary',
'props' => [
'class' => 'acadlix-curriculum-summary'
],
'children' => [
[
'component' => 'h3',
'props' => [
'role' => 'term',
'aria-details' => 'pure-css'
],
'children' => [
[
'component' => 'i',
'props' => [
'class' => 'fas fa-caret-right'
]
],
[
'component' => 'php',
'value' => function () use ($section) {
return esc_html($section->post_title);
}
]
]
]
]
]
]
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-curriculum-content'
],
'children' => $content_list
]
]
];
}
protected function course_main_curriculum_heading()
{
return apply_filters('acadlix_single_course_main_curriculum_heading', [
'component' => 'h2',
'props' => [
'class' => 'acadlix-card-header'
],
'value' => esc_html__('Curriculum', 'acadlix')
], $this->course);
}
protected function course_main_curriculum()
{
$sections = $this->course->sections;
$section_list = [];
$section_list[] = [
'component' => 'div',
'props' => [
'id' => 'acadlix-curriculum-react-preview'
]
];
if ($sections->count() > 0) {
foreach ($sections as $i => $section) {
$section_list[] = $this->course_main_curriculum_section($section, $i);
}
}
return [
'component' => 'div',
'props' => [
'id' => 'curriculum',
'class' => 'acadlix-course-curriculum acadlix-card acadlix-mb-16 acadlix-box-shadow-2'
],
'children' => [
$this->course_main_curriculum_heading(),
[
'component' => 'div',
'props' => [
'class' => 'acadlix-d-flex acadlix-flex-column acadlix-gap-1 acadlix-card-body'
],
'children' => $section_list
]
]
];
}
protected function course_main_requirements_heading()
{
return apply_filters('acadlix_single_course_main_requirements_heading', [
'component' => 'h2',
'props' => [
'class' => 'acadlix-card-header'
],
'value' => esc_html__('Requirements', 'acadlix')
], $this->course);
}
protected function course_main_single_requirement($requirement = '')
{
return apply_filters('acadlix_single_course_main_single_requirement', [
'component' => 'div',
'props' => [
'class' => 'acadlix-col-12 acadlix-col-lg-6 acadlix-d-flex acadlix-align-center acadlix-gap-1 acadlix-mt-8'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-button-icon acadlix-p-4'
],
'children' => [
[
'component' => 'i',
'props' => [
'class' => 'fa fa-check'
]
]
]
],
[
'component' => 'span',
'props' => [
'class' => 'acadlix-body1'
],
'value' => esc_html($requirement)
]
]
], $this->course);
}
protected function course_main_requirements()
{
$requirement_list = [];
$requirements = $this->course->rendered_metas['requirements'] ?? [];
// Filter out empty/null items from the array
$valid_requirements = array_filter($requirements, function ($requirement) {
return !empty(trim($requirement)); // trim handles whitespace-only strings
});
// If there are no valid requirements left, return null early
if (empty($valid_requirements)) {
return null;
}
// Build the rendered requirement components
$requirement_list = array_map(function ($requirement) {
return $this->course_main_single_requirement($requirement);
}, $valid_requirements);
return [
'component' => 'div',
'props' => [
'class' => 'acadlix-card acadlix-box-shadow-2 acadlix-mb-16'
],
'children' => [
$this->course_main_requirements_heading(),
[
'component' => 'div',
'props' => [
'class' => 'acadlix-card-body'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-row'
],
'children' => array_values($requirement_list)
]
]
]
]
];
}
protected function course_main_target_audience_heading()
{
return apply_filters('acadlix_single_course_main_target_audience_heading', [
'component' => 'h2',
'props' => [
'class' => 'acadlix-card-header'
],
'value' => esc_html__('Target Audience', 'acadlix')
], $this->course);
}
protected function course_main_single_target_audience($target_audience = '')
{
return apply_filters('acadlix_single_course_main_single_target_audience', [
'component' => 'div',
'props' => [
'class' => 'acadlix-col-12 acadlix-col-lg-6 acadlix-d-flex acadlix-align-center acadlix-gap-1 acadlix-mt-8'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-button-icon acadlix-p-4'
],
'children' => [
[
'component' => 'i',
'props' => [
'class' => 'fa fa-check'
]
]
]
],
[
'component' => 'span',
'props' => [
'class' => 'acadlix-body1'
],
'value' => esc_html($target_audience)
]
]
], $this->course);
}
protected function course_main_target_audience()
{
$target_audience_list = [];
$target_audiences = $this->course->rendered_metas['target_audience'] ?? [];
// Filter out empty/null items from the array
$valid_targets = array_filter($target_audiences, function ($target) {
return !empty(trim($target)); // trim handles whitespace-only strings
});
// If there are no valid targets left, return null early
if (empty($valid_targets)) {
return null;
}
// Build the rendered target audience components
$target_audience_list = array_map(function ($target) {
return $this->course_main_single_target_audience($target);
}, $valid_targets);
return [
'component' => 'div',
'props' => [
'class' => 'acadlix-card acadlix-box-shadow-2 acadlix-mb-16'
],
'children' => [
$this->course_main_target_audience_heading(),
[
'component' => 'div',
'props' => [
'class' => 'acadlix-card-body'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-row'
],
'children' => array_values($target_audience_list)
]
]
]
]
];
}
protected function course_main_resource_heading()
{
return apply_filters('acadlix_single_course_main_resource_heading', [
'component' => 'h2',
'props' => [
'class' => 'acadlix-card-header'
],
'value' => esc_html__('Course Resource(s)', 'acadlix')
], $this->course);
}
protected function course_main_single_resource($resource = [], $index = 0)
{
$title = $resource['title'] ?? '';
$type = $resource['type'] ?? 'upload';
$filename = $resource['filename'] ?? '';
$file_url = $resource['file_url'] ?? '';
$size = $resource['size'] ?? '';
$link = $resource['link'] ?? '';
$extension = '';
if ($type === 'upload' && !empty($filename)) {
$extension = pathinfo($filename, PATHINFO_EXTENSION);
}
return apply_filters('acadlix_single_course_main_single_resource', [
'component' => 'div',
'props' => [
'class' => 'acadlix-resource-item acadlix-mb-3',
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-resource-content',
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-resource-content-info'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-h6',
],
'value' => wp_kses_post($title),
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-resource-content-meta acadlix-subtitle2',
],
'value' => $type === 'upload'
? (!empty($extension) ? esc_html(strtoupper($extension)) : '')
. (!empty($size) ? ' | ' . esc_html($size) : '')
: esc_html__('Link', 'acadlix'),
]
]
],
[
'component' => 'a',
'props' => [
'href' => $type === 'upload' ? esc_url($file_url) : esc_url($link),
'class' => 'acadlix-resource-action acadlix-resource-icon acadlix-h5',
'target' => '_blank',
'rel' => 'noopener noreferrer',
],
'children' => [
[
'component' => 'i',
'props' => [
'class' => ($type === 'upload' ? 'fas fa-download' : 'fas fa-arrow-up-right-from-square'),
],
],
]
]
],
],
],
], $this->course, $index);
}
protected function course_main_resources()
{
$resources_list = [];
$resources = $this->course->rendered_metas['resources'] ?? [];
// Filter out items where the 'title' key is missing, null, or empty whitespace
$valid_resources = array_filter($resources, function ($resource) {
if (!is_array($resource) || !isset($resource['title'])) {
return false;
}
return !empty(trim((string) $resource['title']));
});
// If there are no valid resources left, return null early
if (empty($valid_resources)) {
return null;
}
// Build the rendered resource components
$resources_list = array_map(function ($resource, $index) {
return $this->course_main_single_resource($resource, $index);
}, $valid_resources, array_keys($valid_resources));
return [
'component' => 'div',
'props' => [
'class' => 'acadlix-card acadlix-box-shadow-2 acadlix-mb-16'
],
'children' => [
$this->course_main_resource_heading(),
[
'component' => 'div',
'props' => [
'class' => 'acadlix-card-body'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-resource-list'
],
'children' => array_values($resources_list)
]
]
]
]
];
}
protected function course_main_faq_heading()
{
return apply_filters('acadlix_single_course_main_faq_heading', [
'component' => 'h2',
'props' => [
'class' => 'acadlix-card-header'
],
'value' => esc_html__('FAQ(s)', 'acadlix')
], $this->course);
}
protected function course_main_single_faq($faq = [], $index = 0)
{
$question = $faq['question'] ?? '';
$answer = $faq['answer'] ?? '';
$toggle_id = 'acadlix-faq-toggle-' . esc_attr($index);
return apply_filters('acadlix_single_course_main_single_faq', [
'component' => 'div',
'props' => [
'class' => 'acadlix-faq-item acadlix-mb-3',
],
'children' => [
// Hidden Checkbox Trigger
[
'component' => 'input',
'props' => array_merge([
'type' => 'checkbox',
'id' => $toggle_id,
'class' => 'acadlix-faq-checkbox',
], $index === 0 ? ['checked' => true] : []),
],
// Clickable faq Header (Label)
[
'component' => 'label',
'props' => [
'for' => $toggle_id,
'class' => 'acadlix-faq-header acadlix-h3',
],
'children' => [
[
'component' => 'i',
'props' => [
'class' => 'fas fa-caret-down acadlix-faq-icon',
],
],
[
'component' => 'span',
'props' => [
'class' => 'acadlix-faq-question',
],
'value' => esc_html($question),
],
],
],
// Collapsible Content Body
[
'component' => 'div',
'props' => [
'class' => 'acadlix-faq-answer',
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-body1',
],
'value' => wp_kses_post($answer),
],
],
],
],
], $this->course, $index);
}
protected function course_main_faqs()
{
$faq_list = [];
$faqs = $this->course->rendered_metas['faqs'] ?? [];
// Filter out items where the 'question' key is missing, null, or empty whitespace
$valid_faqs = array_filter($faqs, function ($faq) {
if (!is_array($faq) || !isset($faq['question'])) {
return false;
}
return !empty(trim((string) $faq['question']));
});
// If there are no valid FAQs left, return null early
if (empty($valid_faqs)) {
return null;
}
// Build the rendered FAQ components
$faq_list = array_map(function ($faq, $index) {
return $this->course_main_single_faq($faq, $index);
}, $valid_faqs, array_keys($valid_faqs));
return [
'component' => 'div',
'props' => [
'class' => 'acadlix-card acadlix-box-shadow-2 acadlix-mb-16'
],
'children' => [
$this->course_main_faq_heading(),
[
'component' => 'div',
'props' => [
'class' => 'acadlix-card-body'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-faq-list'
],
'children' => array_values($faq_list)
]
]
]
]
];
}
protected function course_single_instructor_img($user_id = 0)
{
$author_data = get_userdata($user_id);
$author_name = $author_data ? $author_data->display_name : '';
return apply_filters('acadlix_single_course_single_instructor_img', [
'component' => 'img',
'props' => [
'src' => esc_url(get_avatar_url($user_id, ['size' => 80])),
'alt' => esc_attr($author_name),
'class' => 'acadlix-card-img acadlix-course-instructor-img',
]
], $user_id);
}
protected function course_single_instructor_name($user_id = 0)
{
return apply_filters('acadlix_single_course_single_instructor_name', [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-author acadlix-h3'
],
'value' => acadlix()->helper()->course()->getUserLinkHtml($user_id)
], $user_id);
}
protected function course_single_instructor_desc($user_id = 0)
{
$author_desc = get_user_meta($user_id, 'description', true);
return apply_filters('acadlix_single_course_single_instructor_desc', !empty($author_desc) ? [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-user-description acadlix-body1'
],
'value' => esc_html($author_desc)
] : null, $user_id);
}
protected function course_single_instructor($user_id = 0)
{
return apply_filters('acadlix_single_course_single_instructor', [
'component' => 'div',
'props' => [
'class' => 'acadlix-col-12'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-card'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-card-body acadlix-d-flex acadlix-align-center'
],
'children' => [
$this->course_single_instructor_img($user_id),
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-instructor-detail'
],
'children' => [
$this->course_single_instructor_name($user_id),
$this->course_single_instructor_desc($user_id)
]
]
]
]
]
]
]
], $this->course, $user_id);
}
protected function course_main_instructor_heading()
{
return apply_filters('acadlix_single_course_main_instructor_heading', [
'component' => 'h2',
'props' => [
'class' => 'acadlix-card-header'
],
'value' => esc_html__('Course Instructor', 'acadlix')
], $this->course);
}
protected function course_main_instructor()
{
$course_instructors = [];
if (count($this->course->users) === 0) {
$course_instructors[] = $this->course_single_instructor($this->course->post_author);
} else {
foreach ($this->course->users as $user) {
$course_instructors[] = $this->course_single_instructor($user->ID);
}
}
return apply_filters('acadlix_single_course_main_instructor', [
'component' => 'div',
'props' => [
'id' => 'instructor',
'class' => 'acadlix-card acadlix-course-instructor acadlix-mb-16 acadlix-box-shadow-2'
],
'children' => [
$this->course_main_instructor_heading(),
[
'component' => 'div',
'props' => [
'class' => 'acadlix-card-body'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-row'
],
'children' => $course_instructors
]
]
]
]
], $this->course);
}
protected function course_main_reviews_heading()
{
return apply_filters('acadlix_single_course_main_reviews_heading', [
'component' => 'h2',
'props' => [
'class' => 'acadlix-card-header'
],
'value' => esc_html__('Course Reviews', 'acadlix')
], $this->course);
}
protected function course_main_single_review_breakdown(
$star_number = 5,
) {
$rating_count = $this->rating_breakdown[$star_number];
$percentage = 0;
if ($this->total_rating > 0) {
$percentage = ($rating_count / $this->total_rating) * 100;
}
return [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-review-breakdown-item'
],
'children' => [
acadlix()->helper()->course()->courseSingleReviewStar("unfilled"), // star icon
[
'component' => 'div',
'props' => [
'class' => 'acadlix-review-star-label acadlix-body1'
],
'value' => esc_html($star_number)
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-progress-bar acadlix-rating-progress-bar',
'style' => '--acadlix-progress-value: ' . esc_html($percentage) . '%;'
],
'children' => [
[
'component' => 'span',
'props' => [
'class' => 'acadlix-progress-value',
]
]
]
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-review-star-count acadlix-body1'
],
'value' => esc_html($rating_count) . ' ' . esc_html__('Rating', 'acadlix')
]
]
];
}
protected function course_main_reviews_summary()
{
return [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-reviews-summary'
],
'children' => [
// Overall Rating
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-review-basic-summary'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-rating-value'
],
'value' => esc_html($this->average_rating) // Placeholder value
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-rating-stars'
],
'children' => acadlix()->helper()->course()->courseReviewStar($this->average_rating, 5) // Placeholder value
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-rating-count acadlix-body2'
],
'value' => sprintf(
// translators: %d is the number of ratings
esc_html__('Based on %d ratings', 'acadlix'),
esc_html($this->total_rating)
) // Placeholder value
]
]
],
// Rating Breakdown
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-review-breakdown'
],
'children' => [
// Individual rating bars would go here
$this->course_main_single_review_breakdown(5),
$this->course_main_single_review_breakdown(4),
$this->course_main_single_review_breakdown(3),
$this->course_main_single_review_breakdown(2),
$this->course_main_single_review_breakdown(1),
]
]
]
];
}
protected function course_main_single_review($comment)
{
return [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-single-review'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-review-user-info'
],
'children' => [
// User Avatar
[
'component' => 'img',
'props' => [
'src' => esc_url(get_avatar_url($comment->user_id, ['size' => 60])), // Placeholder user ID
'alt' => esc_attr__('User Avatar', 'acadlix'),
'class' => 'acadlix-course-review-user-avatar'
]
],
// User Name and Date
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-review-user-details'
],
'children' => [
[
'component' => 'a',
'props' => [
'href' => esc_url(get_author_posts_url($comment->user_id)), // Placeholder user ID
'class' => 'acadlix-course-review-user-name acadlix-body1'
],
'value' => esc_html($comment->comment_author) // Placeholder name
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-review-date acadlix-subtitle2'
],
'value' => esc_html(human_time_diff(strtotime($comment->comment_date))) // Placeholder date
]
]
],
$comment->comment_approved == "pending" ? [
'component' => 'div',
'props' => [
'class' => 'acadlix-course-review-pending acadlix-body2'
],
'value' => esc_html__('Pending', 'acadlix')
] : null
]
],
// Review Rating
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-review-rating'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-single-course-review-stars'
],
'children' => acadlix()->helper()->course()->courseReviewStar($comment->rating ?? 0, 6) // Placeholder rating
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-user-review acadlix-body1'
],
'value' => esc_html($comment->comment_content) // Placeholder review text
]
]
],
]
];
}
public function course_main_reviews_list($comments = [])
{
$review_list = [];
if (count($comments) === 0) {
return null;
}
foreach ($comments as $comment) {
$review_list[] = $this->course_main_single_review($comment);
}
acadlix()->helper()->acadlix_render_tree($review_list);
}
protected function course_main_selectable_ratings($selected_rating = 0)
{
$selectable_stars = [];
for ($i = 1; $i <= 5; $i++) {
$class = $i <= $selected_rating ? 'fas fa-star' : 'far fa-star';
$selectable_stars[] = [
'component' => 'i',
'props' => [
'class' => $class . ' acadlix-fs-5 acadlix-rating-star-icon',
'data-rating-value' => esc_attr($i),
]
];
}
return $selectable_stars;
}
protected function course_main_review_form()
{
if (!$this->is_course_purchased) {
return null;
}
return [
'component' => 'div',
'props' => [
'id' => 'acadlix-review-form-container',
'class' => 'acadlix-review-form-container acadlix-hidden',
],
'children' => [
// Review form elements would go here
[
'component' => 'form',
'props' => [
'method' => 'post',
],
'children' => [
// Form fields (e.g., rating input, review text area, submit button)
[
'component' => 'input',
'props' => [
'type' => 'hidden',
'name' => 'acadlix_course_id',
'value' => esc_attr($this->course->ID)
],
],
[
'component' => 'input',
'props' => [
'type' => 'hidden',
'name' => 'acadlix_user_id',
'value' => esc_attr($this->user_id)
],
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-ratings-selectable acadlix-mb-8',
'acadlix-ratings-selectable' => true,
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-rating-stars'
],
'children' => $this->course_main_selectable_ratings(
$this->user_comment ? esc_attr($this->user_comment->rating) : 0
)
],
[
'component' => 'input',
'props' => [
'type' => 'hidden',
'name' => 'acadlix_review_rating',
'id' => 'acadlix_review_rating',
'value' => $this->user_comment ? esc_attr($this->user_comment->rating) : 0
],
]
]
],
[
'component' => 'textarea',
'props' => [
'name' => 'acadlix_review_text',
'placeholder' => esc_attr__('Write your review here...', 'acadlix'),
'class' => 'acadlix-rating-textarea',
'autocompolete' => 'off',
'rows' => '4',
],
'value' => $this->user_comment ? esc_html($this->user_comment->comment_content) : ''
],
[
'component' => 'button',
'props' => [
'type' => 'submit',
'class' => 'acadlix-submit-review-btn acadlix-subtitle2',
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-action-button-text',
],
'value' => esc_html__('Submit Review', 'acadlix')
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-btn-loader',
],
],
],
]
]
]
]
];
}
protected function course_main_reviews()
{
if (!$this->enable_rating_and_reviews) {
return null;
}
$current_page = 1;
$total_pages = ceil($this->total_rating / $this->review_pagination_count);
$view_pagination_button = $total_pages > $current_page ? true : false;
return apply_filters('acadlix_single_course_main_reviews', [
'component' => 'div',
'props' => [
'id' => 'reviews',
'class' => 'acadlix-card acadlix-course-reviews acadlix-mb-16 acadlix-box-shadow-2'
],
'children' => [
$this->course_main_reviews_heading(),
[
'component' => 'div',
'props' => [
'class' => 'acadlix-card-body'
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-mb-16'
],
'children' => [
$this->course_main_reviews_summary(),
]
],
// add divider
[
'component' => 'hr',
],
// add review list
[
'component' => 'div',
'props' => [
'id' => 'acadlix-course-reviews-list',
],
'children' => [
!empty($this->user_comment) && $this->user_comment->comment_approved == "pending"
? $this->course_main_single_review($this->user_comment)
: null,
[
'component' => 'php',
'value' => function () {
ob_start();
$this->course_main_reviews_list($this->comments);
return ob_get_clean();
}
]
]
],
// add pagination placeholder
[
'component' => 'div',
'props' => [
'class' => 'acadlix-course-reviews-pagination',
],
'children' => [
[
'component' => 'button',
'props' => [
'class' => 'acadlix-load-review-button acadlix-subtitle2 ' . ($view_pagination_button ? '' : 'acadlix-hidden'),
'type' => 'button',
'id' => 'acadlix-load-review-button',
'data-pagination-count' => esc_attr($this->review_pagination_count),
'data-course-id' => esc_attr($this->course->ID),
'data-current-page' => esc_attr($current_page),
'data-total-pages' => esc_attr($total_pages),
'data-skip-count' => esc_attr($current_page * $this->review_pagination_count),
'data-take-count' => esc_attr(($current_page + 1) * $this->review_pagination_count),
],
'children' => [
[
'component' => 'div',
'props' => [
'class' => 'acadlix-action-button-text',
],
'value' => esc_html__('Load More Reviews', 'acadlix')
],
[
'component' => 'div',
'props' => [
'class' => 'acadlix-btn-loader',
],
],
],
],
]
],
// add/edit review button
[
'component' => 'button',
'props' => [
'class' => 'acadlix-add-edit-review-button acadlix-subtitle2 ' . ($this->is_course_purchased ? '' : 'acadlix-hidden'),
'type' => 'button',
'id' => 'acadlix-add-edit-review-button',
],
'children' => [
[
'component' => 'i',
'props' => [
'class' => 'far fa-star acadlix-mr-4'
]
],
[
'component' => 'span',
'props' => [],
'value' => $this->user_comment ? esc_html__('Edit Review', 'acadlix') : esc_html__('Write a Review', 'acadlix')
]
],
],
// Review form placeholder
$this->course_main_review_form(),
]
]
]
], $this->course);
}
protected function course_mobile_footer()
{
return apply_filters('acadlix_single_course_mobile_footer', [
'component' => 'div',
'props' => [
'class' => 'acadlix-mobile-sticky-footer',
],
'children' => [
$this->acadlix_mobile_course_price(),
$this->acadlix_course_action_buttons('mobile'),
],
], $this->course);
}
protected function render_footer()
{
global $wp_version;
if (version_compare($wp_version, '5.9', '>=') && function_exists('wp_is_block_theme') && true === wp_is_block_theme()) {
$theme = wp_get_theme();
$theme_slug = $theme->get('TextDomain');
echo wp_kses_post(do_blocks(''));
echo '
';
wp_footer();
echo '';
echo '';
} else {
get_footer();
}
}
}