Skip to content

Commit 12e1f8b

Browse files
committed
Add star icons and rating component for wishlist feature
1 parent 71ba4fb commit 12e1f8b

File tree

9 files changed

+184
-41
lines changed

9 files changed

+184
-41
lines changed

assets/icons/star-fill.svg

Lines changed: 3 additions & 0 deletions
Loading

assets/icons/star-half.svg

Lines changed: 4 additions & 0 deletions
Loading

assets/icons/star-line.svg

Lines changed: 3 additions & 0 deletions
Loading

assets/src/js/v3/shared/icons/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ export const icons = [
320320
'spreadsheet',
321321
'star',
322322
'star2',
323+
'starFill',
324+
'starHalf',
325+
'starLine',
323326
'stepper',
324327
'stopwatch',
325328
'storeEye',

classes/Assets.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,6 @@ public static function add_frontend_editor_button() {
851851
public function enqueue_scripts() {
852852
$is_dashboard = tutor_utils()->is_dashboard_page();
853853
$is_learning_area = tutor_utils()->is_learning_area();
854-
$is_course_list = tutor_utils()->is_course_list_page();
855854

856855
$core_css_url = tutor()->assets_url . 'css/tutor-core.min.css';
857856
$dashboard_css_url = tutor()->assets_url . 'css/tutor-dashboard.min.css';
@@ -863,7 +862,7 @@ public function enqueue_scripts() {
863862

864863
$version = TUTOR_ENV === 'DEV' ? time() : TUTOR_VERSION;
865864

866-
if ( $is_dashboard || $is_learning_area || $is_course_list ) {
865+
if ( $is_dashboard || $is_learning_area ) {
867866
$localize_data = apply_filters( 'tutor_localize_data', $this->get_default_localized_data() );
868867

869868
// Core.

classes/Icon.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ final class Icon {
336336
const SPREADSHEET = 'spreadsheet';
337337
const STAR = 'star';
338338
const STAR_2 = 'star-2';
339+
const STAR_FILL = 'star-fill';
340+
const STAR_HALF = 'star-half';
341+
const STAR_LINE = 'star-line';
339342
const STEPPER = 'stepper';
340343
const STOPWATCH = 'stopwatch';
341344
const STORE_EYE = 'store-eye';

classes/Student.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,13 @@ public function get_courses_tab( $active_tab, $post_type_args, $enrolled_course_
387387
'icon' => Icon::WISHLIST,
388388
'url' => esc_url( tutor_utils()->tutor_dashboard_url( 'courses/wishlist' ) ),
389389
'active' => 'courses/wishlist' === $active_tab ? true : false,
390-
'count' => $wishlist_course_count ?? 0,
391390
),
392391
array(
393392
'type' => 'link',
394393
'label' => __( 'Quiz Attempts', 'tutor' ),
395394
'icon' => Icon::QUIZ_2,
396395
'url' => esc_url( tutor_utils()->tutor_dashboard_url( 'courses/my-quiz-attempts' ) ),
397396
'active' => 'courses/my-quiz-attempts' === $active_tab ? true : false,
398-
'count' => 0,
399397
),
400398
);
401399

templates/dashboard/wishlist.php

Lines changed: 126 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
use TUTOR\Input;
13+
use TUTOR\Icon;
1314

1415
global $post;
1516
$per_page = tutor_utils()->get_option( 'pagination_per_page', 20 );
@@ -18,59 +19,147 @@
1819

1920
$wishlists = tutor_utils()->get_wishlist( null, $offset, $per_page );
2021
$total_wishlists_count = count( tutor_utils()->get_wishlist( null ) );
22+
23+
24+
// Default values - all data must be passed from parent.
25+
$image_url = isset( $image_url ) ? $image_url : '';
26+
$course_title = isset( $title ) ? $title : '';
27+
$rating_avg = isset( $rating_avg ) ? $rating_avg : 0;
28+
$rating_count = isset( $rating_count ) ? $rating_count : 0;
29+
$learners = isset( $learners ) ? $learners : 0;
30+
$instructor = isset( $instructor ) ? $instructor : '';
31+
$instructor_url = isset( $instructor_url ) ? $instructor_url : '#';
32+
$provider = isset( $provider ) ? $provider : '';
33+
$show_bestseller = isset( $show_bestseller ) ? $show_bestseller : false;
34+
$price = isset( $price ) ? $price : '';
35+
$original_price = isset( $original_price ) ? $original_price : '';
36+
$permalink = isset( $permalink ) ? $permalink : '#';
37+
2138
?>
2239

23-
<div class="tutor-fs-5 tutor-fw-medium tutor-color-black tutor-mb-24"><?php esc_html_e( 'Wishlist', 'tutor' ); ?></div>
24-
<div class="tutor-dashboard-content-inner my-wishlist">
40+
<!-- <?php tutor_load_template( 'demo-components.dashboard.pages.wishlist' ); ?> -->
41+
42+
<!-- <?php
43+
tutor_utils()->render_svg_icon( Icon::STAR, 14 );
44+
tutor_utils()->render_svg_icon( Icon::STAR_2, 14 );
45+
?> -->
46+
47+
<div class="tutor-dashboard-page-card-body">
2548
<?php if ( is_array( $wishlists ) && count( $wishlists ) ) : ?>
26-
<div class="tutor-grid tutor-grid-3">
49+
<div class="tutor-wishlist-grid">
2750
<?php
2851
foreach ( $wishlists as $post ) :
2952
setup_postdata( $post );
53+
$tutor_course_img = get_tutor_course_thumbnail_src();
3054
?>
31-
<div class="tutor-card tutor-course-card">
32-
<?php tutor_load_template( 'loop.header' ); ?>
55+
<div>
56+
<div class="tutor-card tutor-card--rounded-2xl tutor-card--padding-small tutor-course-card">
57+
<a href="<?php echo esc_url( $permalink ); ?>" class="tutor-course-card-thumbnail">
58+
<div class="tutor-ratio tutor-ratio-16x9" style="max-width: 100px;">
59+
<img src="<?php echo esc_url( $tutor_course_img ); ?>"
60+
alt="<?php the_title(); ?>" loading="lazy" />
61+
</div>
62+
<?php if ( $show_bestseller ) : ?>
63+
<span class="tutor-badge tutor-badge-primary tutor-course-card-badge">
64+
<?php esc_html_e( 'Bestseller', 'tutor' ); ?>
65+
</span>
66+
<?php endif; ?>
67+
</a>
3368

34-
<div class="tutor-card-body">
35-
<?php tutor_load_template( 'loop.rating' ); ?>
69+
<div class="tutor-card-body">
70+
<div class="tutor-course-card-ratings-stars">
71+
<?php
72+
// $course_rating = tutor_utils()->get_course_rating();
73+
// tutor_utils()->star_rating_generator_course( $course_rating->rating_avg );
74+
?>
75+
</div>
76+
<!-- star rating -->
77+
<?php // if ( $rating_avg > 0 ) : ?>
78+
<?php if ( true ) : ?>
79+
<div class="tutor-course-card-rating">
80+
<div class="tutor-ratings">
81+
<?php
82+
$course_rating = tutor_utils()->get_course_rating();
83+
tutor_load_template(
84+
// 'core-components.star-rating',
85+
'dashboard.wishlist.star-rating',
86+
array(
87+
'rating' => $course_rating->rating_count,
88+
'wrapper_class' => 'tutor-course-card-ratings-stars',
89+
'icon_class' => '',
90+
'show_rating_average' => true,
91+
)
92+
);
93+
?>
94+
<?php if ( $course_rating->rating_count > 0 ) : ?>
95+
<!-- <div class="tutor-ratings-count">
96+
(<?php echo esc_html( number_format_i18n( $course_rating->rating_count ) ); ?>)
97+
</div> -->
98+
<?php endif; ?>
99+
</div>
100+
</div>
101+
<?php endif; ?>
36102

37-
<div class="tutor-course-name tutor-fs-6 tutor-fw-bold">
38-
<a href="<?php echo esc_url( get_the_permalink() ); ?>">
39-
<?php the_title(); ?>
40-
</a>
41-
</div>
103+
<h3 class="tutor-course-card-title">
104+
<a href="<?php the_permalink(); ?>">
105+
<?php the_title(); ?>
106+
</a>
107+
</h3>
42108

43-
<div class="tutor-mt-auto">
44-
<?php tutor_load_template( 'loop.course-author' ); ?>
45-
</div>
46-
</div>
109+
<div class="tutor-course-card-meta">
110+
<?php if ( $learners > 0 ) : ?>
111+
<span>
112+
<?php
113+
/* translators: %d: number of learners */
114+
echo esc_html( sprintf( _n( '%d Learner', '%d Learners', $learners, 'tutor' ), $learners ) );
115+
?>
116+
</span>
117+
<?php endif; ?>
118+
<?php if ( ! empty( $instructor ) ) : ?>
119+
<?php if ( $learners > 0 ) : ?>
120+
<span class="tutor-course-card-separator">•</span>
121+
<?php endif; ?>
122+
<span class="tutor-course-card-instructor">
123+
<?php echo esc_html( $instructor ); ?>
124+
</span>
125+
<?php endif; ?>
126+
<?php if ( ! empty( $provider ) ) : ?>
127+
<?php if ( $learners > 0 || ! empty( $instructor ) ) : ?>
128+
<span class="tutor-course-card-separator">•</span>
129+
<?php endif; ?>
130+
<span>
131+
<?php
132+
/* translators: %s: provider name */
133+
echo esc_html( sprintf( __( 'by %s', 'tutor' ), $provider ) );
134+
?>
135+
</span>
136+
<?php endif; ?>
137+
</div>
138+
</div>
47139

48-
<div class="tutor-card-footer">
49-
<?php tutor_course_loop_price(); ?>
140+
<?php tutor_course_loop_price(); ?>
141+
<?php if ( ! empty( $price ) ) : ?>
142+
<div class="tutor-course-card-footer">
143+
<span class="tutor-course-card-price">
144+
<?php echo esc_html( $price ); ?>
145+
</span>
146+
<?php if ( ! empty( $original_price ) ) : ?>
147+
<del class="tutor-course-card-price-original">
148+
<?php echo esc_html( $original_price ); ?>
149+
</del>
150+
<?php endif; ?>
151+
</div>
152+
<?php endif; ?>
153+
</div>
50154
</div>
51-
</div>
52155
<?php
53156
endforeach;
54157
wp_reset_postdata();
55158
?>
56159
</div>
57160
<?php else : ?>
58-
<?php tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() ); ?>
161+
<div class="tutor-text-center tutor-py-16 tutor-text-muted">
162+
<?php esc_html_e( 'You have not added any courses to your wishlist yet.', 'tutor' ); ?>
163+
</div>
59164
<?php endif; ?>
60-
</div>
61-
<div class="tutor-mt-24">
62-
<?php
63-
if ( $total_wishlists_count >= $per_page ) {
64-
$pagination_data = array(
65-
'total_items' => $total_wishlists_count,
66-
'per_page' => $per_page,
67-
'paged' => $current_page,
68-
);
69-
70-
tutor_load_template_from_custom_path(
71-
tutor()->path . 'templates/dashboard/elements/pagination.php',
72-
$pagination_data
73-
);
74-
}
75-
?>
76-
</div>
165+
</div>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Star Rating Component
4+
* Reusable star rating component for displaying ratings
5+
*
6+
* @package Tutor\Templates
7+
* @author Themeum <[email protected]>
8+
* @link https://themeum.com
9+
* @since 4.0.0
10+
*/
11+
12+
if ( ! defined( 'ABSPATH' ) ) {
13+
exit;
14+
}
15+
16+
use TUTOR\Icon;
17+
18+
// Default values - all data must be passed from parent.
19+
$rating = isset( $rating ) ? floatval( $rating ) : 0.00;
20+
$wrapper_class = isset( $wrapper_class ) ? $wrapper_class : 'tutor-ratings-stars tutor-flex tutor-items-center tutor-gap-2';
21+
$show_rating_average = isset( $show_rating_average ) ? (bool) $show_rating_average : false;
22+
?>
23+
<div class="<?php echo esc_attr( $wrapper_class ); ?> tutor-text-exception4" data-rating-value="<?php echo esc_attr( $rating ); ?>">
24+
<?php for ( $i = 1; $i <= 5; $i++ ) : ?>
25+
<?php
26+
if ( (int) $rating >= $i ) {
27+
tutor_utils()->render_svg_icon( Icon::STAR_FILL, 14 );
28+
} elseif ( ( $rating - $i ) >= -0.5 ) {
29+
tutor_utils()->render_svg_icon( Icon::STAR_HALF, 14 );
30+
} else {
31+
tutor_utils()->render_svg_icon( Icon::STAR_LINE, 14 );
32+
}
33+
?>
34+
35+
<?php endfor; ?>
36+
<?php if ( $show_rating_average ) : ?>
37+
<div class="tutor-ratings-average">
38+
<?php echo esc_html( apply_filters( 'tutor_course_rating_average', $rating ) ); ?>
39+
</div>
40+
<?php endif; ?>
41+
</div>

0 commit comments

Comments
 (0)