Skip to content

Commit

Permalink
Update Testimonial Widget - Add Rating Option
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Sep 26, 2024
1 parent 0659166 commit 5d2bc78
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
24 changes: 23 additions & 1 deletion framework/elements/testimonials/testimonials.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,20 @@

$overlay_text_color = $params->get('overlay_text_color', '');
$overlay_text_color = $overlay_text_color !== '' ? ' ' . $overlay_text_color : '';

$enable_rating = $params->get('enable_rating', 0);
echo '<div class="astroid-grid '.($enable_slider ? 'astroid-slick opacity-0' . $nav_position : $row_column_cls).$gutter_cls.$overlay_text_color.'">';
foreach ($testimonials as $key => $testimonial) {
$testimonial_params = Helper::loadParams($testimonial->params);
$avatar = $testimonial_params->get('avatar', '');
$rating = $testimonial_params->get('rating', 0);
$media = '';
if ($avatar) {
$media = '<div class="as-author-avatar d-inline-block position-relative overflow-hidden' . $image_border_radius . $box_shadow . $hover_effect . $transition . '">';
$media .= '<img class="' . ($avatar_position == 'left' || $avatar_position == 'right' ? 'object-fit-cover w-100 h-100 ' : '') .'" src="'. Astroid\Helper\Media::getPath() . '/' . $avatar .'" alt="'.$testimonial_params->get('title', '').'">';
$media .= '</div>';
}


echo '<div id="testimonial-'. $testimonial -> id .'"><div class="card' . $card_style . $box_shadow . $box_shadow_hover .$bd_radius . $card_hover_transition . ($enable_grid_match ? ' h-100' : '') . '">';
if ($avatar_position == 'left' || $avatar_position == 'right') {
echo '<div class="row g-0">';
Expand All @@ -243,6 +245,21 @@
if ($avatar_position == 'bottom') {
echo $media;
}
if (!empty($enable_rating)) {
echo '<div class="as-rating-block row row-cols-auto gx-2">';
for ($i = 0; $i < 5 ; $i++) {
if ($i < $rating) {
if ($rating - $i >= 1) {
echo '<div class="as-star"><i class="fa-solid fa-star"></i></div>';
} else {
echo '<div class="as-star"><i class="fa-solid fa-star-half-stroke"></i></div>';
}
} else {
echo '<div class="as-star"><i class="fa-regular fa-star"></i></div>';
}
}
echo '</div>';
}
if (!empty($testimonial_params->get('designation', '')) && $designation_position == 'before') {
echo '<div class="as-author-designation">' . $testimonial_params->get('designation', '') . '</div>';
}
Expand Down Expand Up @@ -310,4 +327,9 @@
}
if (!empty($dot_alignment)) {
$element->style->child('.astroid-slick .slick-dots')->addCss('text-align', $dot_alignment);
}
if (!empty($enable_rating)) {
$rating_color = Style::getColor($params->get('rating_color', ''));
$element->style->child('.as-rating-block')->addCss('color', $rating_color['light']);
$element->style_dark->child('.as-rating-block')->addCss('color', $rating_color['dark']);
}
4 changes: 4 additions & 0 deletions framework/elements/testimonials/testimonials.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<field type="astroidgroup" name="name_options" title="ASTROID_WIDGET_NAME_OPTIONS_LABEL"/>
<field type="astroidgroup" name="designation_options" title="ASTROID_WIDGET_TESTIMONIALS_DESIGNATION_POSITION_LABEL"/>
<field type="astroidgroup" name="content_options" title="ASTROID_WIDGET_MESSAGE_OPTIONS_LABEL"/>
<field type="astroidgroup" name="rating_options" title="ASTROID_WIDGET_RATING_OPTIONS_LABEL"/>
<field astroidgroup="general" name="testimonials" type="astroidsubform" label="ASTROID_WIDGET_TESTIMONIALS_LABEL">
<form>
<fields>
Expand All @@ -25,6 +26,7 @@
<field ngShow="[link]!=''" type="astroidtext" label="ASTROID_WIDGET_LINK_TEXT_LABEL" name="link_title" hint="astroidframe.work"/>
<field name="avatar" type="astroidmedia" label="ASTROID_WIDGET_AVATAR_LABEL"/>
<field type="astroideditor" label="ASTROID_WIDGET_MESSAGE_LABEL" name="message"/>
<field name="rating" type="astroidrange" min="0" max="5" step="0.5" default="5" label="ASTROID_RATING" postfix="stars" />
</fieldset>
</fields>
</form>
Expand Down Expand Up @@ -455,6 +457,8 @@

<field astroidgroup="content_options" name="content_font_style" label="ASTROID_WIDGET_FONT_STYLES_LABEL" type="astroidtypography" columns="1" preview="false"/>
<field astroidgroup="content_options" name="content_margin" type="astroidspacing" label="ASTROID_WIDGET_MARGIN_LABEL" />
<field astroidgroup="rating_options" name="enable_rating" type="astroidradio" astroid-switch="true" default="0" label="ASTROID_WIDGET_ENABLE_RATING"/>
<field astroidgroup="rating_options" name="rating_color" type="astroidcolor" label="ASTROID_WIDGET_RATING_COLOR"/>
</fieldset>
<fieldset name="assignment-settings" label="TPL_ASTROID_ASSIGNMENT_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields" articleData="false">
<field type="astroidlist" name="assignment_type" label="ASTROID_WIDGET_ASSIGN" default="1">
Expand Down
4 changes: 4 additions & 0 deletions language/en-GB/en-GB.astroid.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ ASTROID_WHATS_GOOD_DESC="Pro's<br> multiple pro's can be listed (one per line)."
ASTROID_WHATS_BAD="What's Bad"
ASTROID_WHATS_BAD_DESC="Con's<br> multiple con's can be listed (one per line)."
ASTROID_OVERALL_RATING="Overall Rating"
ASTROID_RATING="Rating"
ASTROID_OVERALL_RATING_DESC="Give an overall rating for an article."
ASTROID_CALL_ACTION_BUTTON="Call to Action button"
ASTROID_CALL_ACTION_BUTTON_DESC="Enter text for the Call to Action button."
Expand Down Expand Up @@ -1565,6 +1566,7 @@ ASTROID_WIDGET_TESTIMONIALS_DESIGNATION_LABEL="Designation"
ASTROID_WIDGET_TESTIMONIALS_AVATAR_POSITION_LABEL="Avatar Position"
ASTROID_WIDGET_NAME_OPTIONS_LABEL="Name Options"
ASTROID_WIDGET_MESSAGE_OPTIONS_LABEL="Message Options"
ASTROID_WIDGET_RATING_OPTIONS_LABEL="Rating Options"
ASTROID_WIDGET_TESTIMONIALS_DESIGNATION_POSITION_LABEL="Designation Options"
ASTROID_WIDGET_AVATAR_OPTIONS_LABEL="Avatar Options"
ASTROID_WIDGET_XXL_COLUMN_AVATAR_WIDTH="Avatar Width 2X-Large Screen"
Expand All @@ -1580,6 +1582,8 @@ ASTROID_WIDGET_DOT_ALIGNMENT="Dots Alignment"
ASTROID_WIDGET_NAV_POSITION="Navigation Position"
ASTROID_WIDGET_NAV_POSITION_INSIDE="Inside"
ASTROID_WIDGET_NAV_POSITION_OUTSIDE="Outside"
ASTROID_WIDGET_ENABLE_RATING="Enable Rating"
ASTROID_WIDGET_RATING_COLOR="Rating Color"

; Map
ASTROID_WIDGET_MAP_LABEL="Map"
Expand Down

0 comments on commit 5d2bc78

Please sign in to comment.