| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\StarRatings; |
| 3 |
|
| 4 |
use ABlocks\Classes\BlockBaseAbstract; |
| 5 |
use ABlocks\Classes\CssGenerator; |
| 6 |
use ABlocks\Controls\Alignment; |
| 7 |
use ABlocks\Controls\TextShadow; |
| 8 |
use ABlocks\Controls\TextStroke; |
| 9 |
use ABlocks\Controls\Typography; |
| 10 |
use ABlocks\Controls\Icon; |
| 11 |
use ABlocks\Controls\Range; |
| 12 |
|
| 13 |
class Block extends BlockBaseAbstract { |
| 14 |
protected $block_name = 'star-ratings'; |
| 15 |
|
| 16 |
public function build_css( $attributes ) { |
| 17 |
|
| 18 |
$css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 19 |
|
| 20 |
$css_generator->add_class_styles( |
| 21 |
'{{WRAPPER}} .ablocks-block-container', |
| 22 |
$this->get_container_css( $attributes ), |
| 23 |
$this->get_container_css( $attributes, 'Tablet' ), |
| 24 |
$this->get_container_css( $attributes, 'Mobile' ), |
| 25 |
); |
| 26 |
// rating icon css |
| 27 |
$css_generator->add_class_styles( |
| 28 |
'{{WRAPPER}} .ablocks-rating', |
| 29 |
$this->get_rating_css( $attributes ), |
| 30 |
$this->get_rating_css( $attributes, 'Tablet' ), |
| 31 |
$this->get_rating_css( $attributes, 'Mobile' ), |
| 32 |
); |
| 33 |
|
| 34 |
$css_generator->add_class_styles( |
| 35 |
'{{WRAPPER}} .ablocks-icon-wrap', |
| 36 |
Icon::get_wrapper_css( $attributes ), |
| 37 |
Icon::get_wrapper_css( $attributes, 'Tablet' ), |
| 38 |
Icon::get_wrapper_css( $attributes, 'Mobile' ) |
| 39 |
); |
| 40 |
|
| 41 |
$css_generator->add_class_styles( |
| 42 |
'{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon', |
| 43 |
Icon::get_element_image_css( $attributes ), |
| 44 |
Icon::get_element_image_css( $attributes, 'Tablet' ), |
| 45 |
Icon::get_element_image_css( $attributes, 'Mobile' ), |
| 46 |
); |
| 47 |
|
| 48 |
// rating icon spacing css |
| 49 |
$css_generator->add_class_styles( |
| 50 |
'{{WRAPPER}} .ablocks-star-ratings-icons', |
| 51 |
$this->get_rating_icon_spacing_css( $attributes ), |
| 52 |
$this->get_rating_icon_spacing_css( $attributes, 'Tablet' ), |
| 53 |
$this->get_rating_icon_spacing_css( $attributes, 'Mobile' ), |
| 54 |
); |
| 55 |
|
| 56 |
$get_desktop_rating_number_css = $this->get_rating_number_css( $attributes ); |
| 57 |
if ( ! empty( $attributes['ratingNumberColor'] ) ) { |
| 58 |
$get_desktop_rating_number_css['color'] = $attributes['ratingNumberColor']; |
| 59 |
} |
| 60 |
if ( ! empty( $attributes['ratingNumberPosition'] ) ) { |
| 61 |
if ( 'left' === $attributes['ratingNumberPosition'] ) { |
| 62 |
$get_desktop_rating_number_css['order'] = '-5'; |
| 63 |
} else { |
| 64 |
$get_desktop_rating_number_css['order'] = '10'; |
| 65 |
} |
| 66 |
} |
| 67 |
// rating number css |
| 68 |
$css_generator->add_class_styles( |
| 69 |
'{{WRAPPER}} .ablocks-star-rating-number', |
| 70 |
$get_desktop_rating_number_css, |
| 71 |
$this->get_rating_number_css( $attributes, 'Tablet' ), |
| 72 |
$this->get_rating_number_css( $attributes, 'Mobile' ), |
| 73 |
); |
| 74 |
|
| 75 |
return $css_generator->generate_css(); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
public function get_container_css( $attributes, $device = '' ) { |
| 80 |
return array_merge( |
| 81 |
Range::get_css([ |
| 82 |
'attributeValue' => $attributes['ratingNumberGap'], |
| 83 |
'attribute_object_key' => 'value', |
| 84 |
'isResponsive' => true, |
| 85 |
'defaultValue' => 0, |
| 86 |
'hasUnit' => true, |
| 87 |
'unitDefaultValue' => 'px', |
| 88 |
'property' => 'gap', |
| 89 |
'device' => $device, |
| 90 |
]), |
| 91 |
isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'justify-content', $device ) : [], |
| 92 |
); |
| 93 |
} |
| 94 |
|
| 95 |
public function get_rating_number_css( $attributes, $device = '' ) { |
| 96 |
return Typography::get_css( $attributes['ratingNumberTypography'], '', $device ); |
| 97 |
} |
| 98 |
|
| 99 |
public function get_rating_css( $attributes, $device = '' ) { |
| 100 |
$rating_css = []; |
| 101 |
$size_value = $attributes['size'][ 'value' . $device ] ?? ''; |
| 102 |
$size_unit = $attributes['size'][ 'valueUnit' . $device ] ?? 'px'; |
| 103 |
$unit = ! empty( $attributes['gap'][ 'valueUnit' . $device ] ) ? $attributes['gap'][ 'valueUnit' . $device ] : 'px'; |
| 104 |
|
| 105 |
if ( ! empty( $size_value ) ) { |
| 106 |
$rating_css['font-size'] = $size_value . $size_unit; |
| 107 |
} |
| 108 |
return $rating_css; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
public function get_rating_icon_spacing_css( $attributes, $device = '' ) { |
| 113 |
$spacing_value = Range::get_css([ |
| 114 |
'attributeValue' => $attributes['spacing'], |
| 115 |
'attribute_object_key' => 'value', |
| 116 |
'isResponsive' => true, |
| 117 |
'defaultValue' => 0, |
| 118 |
'hasUnit' => true, |
| 119 |
'unitDefaultValue' => 'px', |
| 120 |
'property' => 'gap', |
| 121 |
'device' => $device, |
| 122 |
]); |
| 123 |
return $spacing_value; |
| 124 |
} |
| 125 |
} |
| 126 |
|