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.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / components / StarRating.php
tutor / components Last commit date
Constants 4 days ago Accordion.php 4 days ago Alert.php 4 days ago AttachmentCard.php 4 days ago Avatar.php 4 days ago Badge.php 4 days ago BaseComponent.php 4 days ago Button.php 4 days ago ConfirmationModal.php 4 days ago CourseFilter.php 4 days ago DateFilter.php 4 days ago DropdownFilter.php 4 days ago EmptyState.php 4 days ago FileUploader.php 4 days ago InputField.php 4 days ago Modal.php 4 days ago Nav.php 4 days ago Pagination.php 4 days ago Popover.php 4 days ago PreviewTrigger.php 4 days ago Progress.php 4 days ago SearchFilter.php 4 days ago Sorting.php 4 days ago StarRating.php 4 days ago StarRatingInput.php 4 days ago StatusSelect.php 4 days ago SvgIcon.php 4 days ago Table.php 4 days ago Tabs.php 4 days ago Tooltip.php 4 days ago WPEditor.php 4 days ago
StarRating.php
185 lines
1 <?php
2 /**
3 * StarRating Component Class.
4 *
5 * Renders a static star rating display.
6 *
7 * @package Tutor\Components
8 * @author Themeum
9 * @link https://themeum.com
10 * @since 4.0.0
11 */
12
13 namespace Tutor\Components;
14
15 defined( 'ABSPATH' ) || exit;
16
17 use TUTOR\Icon;
18
19 /**
20 * Class StarRating
21 *
22 * Example Usage:
23 * ```
24 * StarRating::make()
25 * ->rating(4.5)
26 * ->show_average(true)
27 * ->render();
28 * ```
29 *
30 * @since 4.0.0
31 */
32 class StarRating extends BaseComponent {
33
34 /**
35 * Rating value
36 *
37 * @since 4.0.0
38 *
39 * @var float
40 */
41 protected $rating = 0;
42
43 /**
44 * Whether to show numerical rating
45 *
46 * @since 4.0.0
47 *
48 * @var bool
49 */
50 protected $show_average = false;
51
52 /**
53 * Star icon size
54 *
55 * @since 4.0.0
56 *
57 * @var int
58 */
59 protected $icon_size = 16;
60
61 /**
62 * Review count
63 *
64 * @since 4.0.0
65 *
66 * @var int|null
67 */
68 protected $count = null;
69
70 /**
71 * Set rating value
72 *
73 * @since 4.0.0
74 *
75 * @param float $rating rating.
76 *
77 * @return self
78 */
79 public function rating( float $rating ): self {
80 $this->rating = $rating;
81 return $this;
82 }
83
84 /**
85 * Set whether to show average rating text
86 *
87 * @since 4.0.0
88 *
89 * @param bool $show show average.
90 *
91 * @return self
92 */
93 public function show_average( bool $show = true ): self {
94 $this->show_average = $show;
95 return $this;
96 }
97
98 /**
99 * Set icon size
100 *
101 * @since 4.0.0
102 *
103 * @param int $size size.
104 *
105 * @return self
106 */
107 public function icon_size( int $size ): self {
108 $this->icon_size = $size;
109 return $this;
110 }
111
112 /**
113 * Set review count
114 *
115 * @since 4.0.0
116 *
117 * @param int $count count.
118 *
119 * @return self
120 */
121 public function count( int $count ): self {
122 $this->count = $count;
123 return $this;
124 }
125
126 /**
127 * Get component content
128 *
129 * @since 4.0.0
130 *
131 * @return string
132 */
133 public function get(): string {
134 $rating = $this->rating;
135 $icon_size = $this->icon_size;
136
137 $star_fill = SvgIcon::make()->name( Icon::STAR_FILL )->size( $icon_size )->ignore_kids()->get();
138 $star_half = SvgIcon::make()->name( Icon::STAR_HALF )->size( $icon_size )->ignore_kids()->get();
139 $star = SvgIcon::make()->name( Icon::STAR_LINE )->size( $icon_size )->ignore_kids()->get();
140
141 ob_start();
142 ?>
143 <div class="tutor-ratings-stars tutor-flex tutor-items-center tutor-gap-1" data-rating-value="<?php echo esc_attr( $rating ); ?>">
144 <div class="tutor-flex tutor-items-center tutor-gap-1">
145 <?php for ( $i = 1; $i <= 5; $i++ ) : ?>
146 <span class="tutor-icon-exception4 tutor-flex-center">
147 <?php
148 if ( (int) $rating >= $i ) {
149 echo $star_fill; // phpcs:ignore -- get_svg_icon returns escaped html
150 } elseif ( ( $rating - $i ) >= -0.5 ) {
151 echo $star_half; // phpcs:ignore -- get_svg_icon returns escaped html
152 } else {
153 echo $star; // phpcs:ignore -- get_svg_icon returns escaped html
154 }
155 ?>
156 </span>
157 <?php endfor; ?>
158 </div>
159
160 <?php if ( $this->show_average || $this->count ) : ?>
161 <div class="tutor-ratings-meta tutor-flex tutor-items-center tutor-gap-1 tutor-ml-1">
162 <?php if ( $this->show_average ) : ?>
163 <span class="tutor-small tutor-font-medium tutor-text-primary">
164 <?php echo esc_html( number_format( $rating, 1 ) ); ?>
165 </span>
166 <?php endif; ?>
167
168 <?php if ( $this->count ) : ?>
169 <span class="tutor-small tutor-text-subdued">
170 <?php
171 /* translators: %s: review count */
172 echo esc_html( sprintf( _n( '(%s Review)', '(%s Reviews)', $this->count, 'tutor' ), number_format_i18n( $this->count ) ) );
173 ?>
174 </span>
175 <?php endif; ?>
176 </div>
177 <?php endif; ?>
178 </div>
179 <?php
180
181 $this->component_string = ob_get_clean();
182 return $this->component_string;
183 }
184 }
185