Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: updated course rating to v2 course rating and made several fixes #16

Open
wants to merge 1 commit into
base: php-8x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions includes/modules/CourseRating/CourseRating.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CourseRating extends Component {

if (layout) {
additionalCss.push([{
selector: '%%order_class%% .tutor-single-course-rating',
selector: '%%order_class%% .tutor-ratings',
declaration: `display: flex; column-gap: 3px; flex-direction: ${layout};`,
}]);
}
Expand All @@ -39,76 +39,100 @@ class CourseRating extends Component {
if ( 'row' === layout ) {
if ( '' !== alignment ) {
additionalCss.push([{
selector: '%%order_class%% .tutor-single-course-rating',
selector: '%%order_class%% .tutor-ratings',
declaration: `justify-content: ${alignment};`,
}]);
}
if ( '' !== alignment_tablet ) {
additionalCss.push([{
selector: '%%order_class%% .tutor-single-course-rating',
selector: '%%order_class%% .tutor-ratings',
declaration: `justify-content: ${alignment_tablet};`,
device: 'tablet',
}]);
}
if ( '' !== alignment_phone ) {
additionalCss.push([{
selector: '%%order_class%% .tutor-single-course-rating',
selector: '%%order_class%% .tutor-ratings',
declaration: `justify-content: ${alignment_phone};`,
device: 'phone'
}]);
}

// set tutor ratings layout gap
additionalCss.push([
{
selector: '%%order_class%% .tutor-ratings',
declaration: `column-gap: ${props.rating_gap}`
}
]);
}

if ( 'column' === layout ) {
if ( '' !== alignment ) {
additionalCss.push([{
selector: '%%order_class%% .tutor-single-course-rating',
selector: '%%order_class%% .tutor-ratings',
declaration: `align-items: ${alignment};`,
}]);
}
if ( '' !== alignment_tablet ) {
additionalCss.push([{
selector: '%%order_class%% .tutor-single-course-rating',
selector: '%%order_class%% .tutor-ratings',
declaration: `align-items: ${alignment_tablet};`,
device: 'tablet'
}]);
}
if ( '' !== alignment_phone ) {
additionalCss.push([{
selector: '%%order_class%% .tutor-single-course-rating',
selector: '%%order_class%% .tutor-ratings',
declaration: `align-items: ${alignment_phone};`,
device: 'phone'
}]);
}

// set tutor ratings layout gap
additionalCss.push([
{
selector: '%%order_class%% .tutor-ratings',
declaration: `row-gap: ${props.rating_gap}`
}
]);
}
// alignments end

//default star color
additionalCss.push([
{
selector: '%%order_class%% .tutor-star-rating-group i',
selector: '%%order_class%% .dtlms-rating-wrapper .tutor-ratings-stars span',
declaration: 'color: #ed9700;'
}
]);

//star group style
additionalCss.push([
{
selector: '%%order_class%% .dtlms-rating-wrapper .tutor-ratings-stars',
declaration: 'display:flex;flex-direction:row;'
}
])

if (props.star_size) {
additionalCss.push([{
selector: `%%order_class%% .dtlms-rating-wrapper .tutor-ratings-stars i`,
selector: `%%order_class%% .dtlms-rating-wrapper .tutor-ratings-stars span`,
declaration: `font-size: ${props.star_size};`,
}]);
}

if (props.star_color) {
additionalCss.push([{
selector: `%%order_class%% .dtlms-rating-wrapper .tutor-ratings-stars i`,
selector: `%%order_class%% .dtlms-rating-wrapper .tutor-ratings-stars span`,
declaration: `color: ${props.star_color};`,
}]);
}

if (props.star_gap) {
additionalCss.push([{
selector: `%%order_class%% .dtlms-rating-wrapper .tutor-ratings-stars`,
declaration: `letter-spacing: ${props.star_gap};`,
declaration: `column-gap: ${props.star_gap};`,
}]);
}

Expand Down
85 changes: 73 additions & 12 deletions includes/modules/CourseRating/CourseRating.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public function init() {
'title' => esc_html__( 'Rating Stars', 'tutor-lms-divi-modules' ),
'priority' => 49,
),
'rating' => array(
'title' => esc_html__( 'Rating', 'tutor-lms-divi-modules'),
'priority' => 50,
)
),
),
);
Expand All @@ -57,12 +61,20 @@ public function init() {
'fonts' => array(
'count_text' => array(
'css' => array(
'main' => '%%order_class%% .tutor-single-course-rating .tutor-single-rating-count',
'main' => '%%order_class%% .tutor-ratings .tutor-ratings-count',
),
'hide_text_align' => true,
'tab_slug' => 'advanced',
'toggle_slug' => 'rating_stars',
),
'avg_text' => array(
'css' => array(
'main' => '%%order_class%% .tutor-ratings .tutor-ratings-average',
),
'hide_text_align' => true,
'tab_slug' => 'advanced',
'toggle_slug' => 'rating',
)
),
'background' => array(
'settings' => array(
Expand Down Expand Up @@ -182,6 +194,23 @@ public function get_fields() {
'tab_slug' => 'advanced',
'toggle_slug' => 'rating_stars',
),
'rating_gap' => array(
'label' => esc_html__( 'Rating Gap', 'tutor-lms-divi-modules' ),
'type' => 'range',
'allowed_units' => array( '%', 'em', 'rem', 'px', 'cm', 'mm', 'in', 'pt', 'pc', 'ex', 'vh', 'vw' ),
'default_unit' => 'px',
'range_settings' => array(
'min' => '0',
'max' => '100',
'step' => '1',
),
'range_settings' => array(
'min' => 0,
'max' => 100,
),
'tab_slug' => 'advanced',
'toggle_slug' => 'rating',
),

);

Expand Down Expand Up @@ -216,9 +245,9 @@ public static function get_rating( $args = array() ) {
*/
public function render( $attrs, $content, $render_slug ) {
// Process image size value into style.
$selector = '%%order_class%% .dtlms-rating-wrapper';
$selector = '%%order_class%% .dtlms-rating-wrapper .tutor-ratings';
$star_icon_group = "$selector .tutor-ratings-stars";
$star_icon = "$selector .tutor-ratings-stars i";
$star_icon = "$selector .tutor-ratings-stars span";
$layout = $this->props['rating_layout'];
// prepare alignment props.
$alignment = $this->props['rating_alignment'];
Expand Down Expand Up @@ -251,7 +280,7 @@ public function render( $attrs, $content, $render_slug ) {
ET_Builder_Element::set_style(
$render_slug,
array(
'selector' => '%%order_class%% .tutor-single-course-rating',
'selector' => '%%order_class%% .tutor-ratings',
'declaration' => sprintf(
'display: flex;
column-gap: 3px;
Expand All @@ -268,7 +297,7 @@ public function render( $attrs, $content, $render_slug ) {
ET_Builder_Element::set_style(
$render_slug,
array(
'selector' => '%%order_class%% .tutor-single-course-rating',
'selector' => '%%order_class%% .tutor-ratings',
'declaration' => sprintf(
'justify-content: %1$s;',
$alignment
Expand All @@ -280,7 +309,7 @@ public function render( $attrs, $content, $render_slug ) {
ET_Builder_Element::set_style(
$render_slug,
array(
'selector' => '%%order_class%% .tutor-single-course-rating',
'selector' => '%%order_class%% .tutor-ratings',
'declaration' => sprintf(
'justify-content: %1$s;',
$alignment_tablet
Expand All @@ -293,7 +322,7 @@ public function render( $attrs, $content, $render_slug ) {
ET_Builder_Element::set_style(
$render_slug,
array(
'selector' => '%%order_class%% .tutor-single-course-rating',
'selector' => '%%order_class%% .tutor-ratings',
'declaration' => sprintf(
'justify-content: %1$s;',
$alignment_mobile
Expand All @@ -302,14 +331,26 @@ public function render( $attrs, $content, $render_slug ) {
)
);
}

// set tutor rating layout gap
ET_Builder_Element::set_style(
$render_slug,
array(
'selector' => '%%order_class%% .tutor-ratings',
'declaration' => sprintf(
'column-gap: %1$s;',
$this->props['rating_gap']
),
)
);
}

if ( 'column' === $layout ) {
if ( '' !== $alignment ) {
ET_Builder_Element::set_style(
$render_slug,
array(
'selector' => '%%order_class%% .tutor-single-course-rating',
'selector' => '%%order_class%% .tutor-ratings',
'declaration' => sprintf(
'align-items: %1$s;',
$alignment
Expand All @@ -321,7 +362,7 @@ public function render( $attrs, $content, $render_slug ) {
ET_Builder_Element::set_style(
$render_slug,
array(
'selector' => '%%order_class%% .tutor-single-course-rating',
'selector' => '%%order_class%% .tutor-ratings',
'declaration' => sprintf(
'align-items: %1$s;',
$alignment_tablet
Expand All @@ -334,7 +375,7 @@ public function render( $attrs, $content, $render_slug ) {
ET_Builder_Element::set_style(
$render_slug,
array(
'selector' => '%%order_class%% .tutor-single-course-rating',
'selector' => '%%order_class%% .tutor-ratings',
'declaration' => sprintf(
'align-items: %1$s;',
$alignment_mobile
Expand All @@ -343,10 +384,30 @@ public function render( $attrs, $content, $render_slug ) {
)
);
}
// set tutor rating layout gap
ET_Builder_Element::set_style(
$render_slug,
array(
'selector' => '%%order_class%% .tutor-ratings',
'declaration' => sprintf(
'row-gap: %1$s;',
$this->props['rating_gap']
),
)
);
}

// alignment end.

// star group style
ET_Builder_Element::set_style(
$render_slug,
array(
'selector' => $star_icon_group,
'declaration' => 'display: flex; flex-direction:row;'
)
);

// default star color.
ET_Builder_Element::set_style(
$render_slug,
Expand All @@ -362,7 +423,7 @@ public function render( $attrs, $content, $render_slug ) {
array(
'selector' => $star_icon,
'declaration' => sprintf(
'font-size: %1$s !important;',
'font-size: %1$s;',
esc_html( $this->props['star_size'] )
),
)
Expand All @@ -389,7 +450,7 @@ public function render( $attrs, $content, $render_slug ) {
array(
'selector' => $star_icon_group,
'declaration' => sprintf(
'letter-spacing: %1$s;',
'column-gap: %1$s;',
esc_html( $this->props['star_gap'] )
),
)
Expand Down
16 changes: 3 additions & 13 deletions includes/templates/course/rating.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,9 @@
if ( $is_enabled_reviews ) :
?>
<div class="tutor-leadinfo-top-meta dtlms-rating-wrapper">
<span class="tutor-single-course-rating">
<?php
<?php
$course_rating = tutor_utils()->get_course_rating();
tutor_utils()->star_rating_generator( $course_rating->rating_avg );
?>
<span class="tutor-single-rating-count">
<?php
$text = __( 'Ratings', 'tutor-lms-divi-modules' );
echo esc_html( $course_rating->rating_avg );
$count = $course_rating->rating_count . ' ' . $text;
echo '(' . esc_html( $count ) . ')';
?>
</span>
</span>
tutor_utils()->star_rating_generator_v2( $course_rating->rating_avg, $course_rating->rating_count, true );
?>
</div>
<?php endif; ?>
2 changes: 1 addition & 1 deletion scripts/builder-bundle.min.js

Large diffs are not rendered by default.