| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || exit; |
| 4 |
|
| 5 |
use YayMail\Utils\TemplateHelpers; |
| 6 |
|
| 7 |
if ( empty( $args['element'] ) ) { |
| 8 |
return; |
| 9 |
} |
| 10 |
|
| 11 |
$element = $args['element']; |
| 12 |
$data = $element['data']; |
| 13 |
|
| 14 |
$wrapper_style = TemplateHelpers::get_style( |
| 15 |
[ |
| 16 |
'word-break' => 'break-word', |
| 17 |
'text-align' => $data['align'] ?? 'center', |
| 18 |
'background-color' => $data['background_color'] ?? '#fff', |
| 19 |
'padding' => TemplateHelpers::get_spacing_value( isset( $data['padding'] ) ? $data['padding'] : [] ), |
| 20 |
] |
| 21 |
); |
| 22 |
|
| 23 |
$table_style = TemplateHelpers::get_style( |
| 24 |
[ |
| 25 |
'display' => 'inline-table', |
| 26 |
'border-collapse' => 'collapse', |
| 27 |
] |
| 28 |
); |
| 29 |
|
| 30 |
$active_stars = min( $data['active_stars'] ?? 5, $data['total_stars'] ?? 5 ); |
| 31 |
$total_stars = $data['total_stars'] ?? 5; |
| 32 |
$size = $data['size'] ?? 40; |
| 33 |
$spacing = $data['spacing'] ?? 10; |
| 34 |
$active_color = $data['active_stars_color'] ?? '#FFD700'; |
| 35 |
$inactive_color = $data['inactive_stars_color'] ?? '#E0E0E0'; |
| 36 |
|
| 37 |
ob_start(); |
| 38 |
?> |
| 39 |
<table class="yaymail-element-rating-stars" cellpadding="0" cellspacing="0" role="presentation" style="<?php echo esc_attr( $table_style ); ?>"> |
| 40 |
<tbody> |
| 41 |
<tr> |
| 42 |
<td> |
| 43 |
<?php |
| 44 |
for ( $i = 0; $i < $total_stars; $i++ ) : |
| 45 |
$is_filled = $i < floor( $active_stars ); |
| 46 |
$color = $is_filled ? $active_color : $inactive_color; |
| 47 |
$cell_styles = [ |
| 48 |
'color' => $color, |
| 49 |
'font-size' => $size . 'px', |
| 50 |
'line-height' => 1, |
| 51 |
'padding' => '0', |
| 52 |
'padding-left' => TemplateHelpers::get_dimension_value( ( $spacing - 4 ) / 2, 'px' ), |
| 53 |
'padding-right' => TemplateHelpers::get_dimension_value( ( $spacing - 4 ) / 2, 'px' ), |
| 54 |
'display' => 'inline-block', |
| 55 |
]; |
| 56 |
?> |
| 57 |
<span style="<?php echo esc_attr( TemplateHelpers::get_style( $cell_styles ) ); ?>">★</span> |
| 58 |
<?php endfor; ?> |
| 59 |
</td> |
| 60 |
</tr> |
| 61 |
</tbody> |
| 62 |
</table> |
| 63 |
<?php |
| 64 |
|
| 65 |
$element_content = ob_get_clean(); |
| 66 |
|
| 67 |
TemplateHelpers::wrap_element_content( $element_content, $element, $wrapper_style ); |
| 68 |
|