| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\Counter; |
| 3 |
|
| 4 |
use ABlocks\Classes\BlockBaseAbstract; |
| 5 |
use ABlocks\Classes\CssGenerator; |
| 6 |
use ABlocks\Controls\Alignment; |
| 7 |
use ABlocks\Controls\Typography; |
| 8 |
use ABlocks\Controls\Dimensions; |
| 9 |
use ABlocks\Controls\Icon; |
| 10 |
use ABlocks\Controls\Range; |
| 11 |
|
| 12 |
class Block extends BlockBaseAbstract { |
| 13 |
protected $block_name = 'counter'; |
| 14 |
|
| 15 |
public function build_css( $attributes ) { |
| 16 |
$css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 17 |
// wrapper css |
| 18 |
$css_generator->add_class_styles( |
| 19 |
'{{WRAPPER}}', |
| 20 |
$this->get_wrapper_css( $attributes ), |
| 21 |
$this->get_wrapper_css( $attributes, 'Tablet' ), |
| 22 |
$this->get_wrapper_css( $attributes, 'Mobile' ), |
| 23 |
); |
| 24 |
$css_generator->add_class_styles( |
| 25 |
'{{WRAPPER}}.ablocks-block--counter--number .ablocks-block-container', |
| 26 |
$this->get_number_wrapper_css( $attributes ), |
| 27 |
$this->get_number_wrapper_css( $attributes, 'Tablet' ), |
| 28 |
$this->get_number_wrapper_css( $attributes, 'Mobile' ), |
| 29 |
); |
| 30 |
// number text css |
| 31 |
$css_generator->add_class_styles( |
| 32 |
'{{WRAPPER}} .ablocks-counter__content', |
| 33 |
$this->get_number_text_css( $attributes ), |
| 34 |
$this->get_number_text_css( $attributes, 'Tablet' ), |
| 35 |
$this->get_number_text_css( $attributes, 'Mobile' ), |
| 36 |
); |
| 37 |
// heading text css |
| 38 |
$css_generator->add_class_styles( |
| 39 |
'{{WRAPPER}} .ablocks-counter__text', |
| 40 |
$this->get_heading_text_css( $attributes ), |
| 41 |
$this->get_heading_text_css( $attributes, 'Tablet' ), |
| 42 |
$this->get_heading_text_css( $attributes, 'Mobile' ), |
| 43 |
); |
| 44 |
// counter bar css |
| 45 |
|
| 46 |
// counter circle css |
| 47 |
$css_generator->add_class_styles( |
| 48 |
'{{WRAPPER}}.ablocks-block--counter--bar .ablocks-bar-counter__background', |
| 49 |
$this->get_counter_bar_bg_css( $attributes ) |
| 50 |
); |
| 51 |
|
| 52 |
$css_generator->add_class_styles( |
| 53 |
'{{WRAPPER}}.ablocks-block--counter--bar .ablocks-bar-counter__progress', |
| 54 |
$this->get_counter_bar_progress_css( $attributes ), |
| 55 |
$this->get_counter_bar_progress_css( $attributes, 'Tablet' ), |
| 56 |
$this->get_counter_bar_progress_css( $attributes, 'Mobile' ) |
| 57 |
); |
| 58 |
$css_generator->add_class_styles( |
| 59 |
'{{WRAPPER}}.ablocks-block--counter--circle', |
| 60 |
$this->get_counter_circle_css( $attributes ), |
| 61 |
$this->get_counter_circle_css( $attributes, 'Tablet' ), |
| 62 |
$this->get_counter_circle_css( $attributes, 'Mobile' ) |
| 63 |
); |
| 64 |
$css_generator->add_class_styles( |
| 65 |
'{{WRAPPER}}.ablocks-block--counter--circle .ablocks-circle-counter__background', |
| 66 |
$this->get_counter_circle_bg_css( $attributes ) |
| 67 |
); |
| 68 |
|
| 69 |
$css_generator->add_class_styles( |
| 70 |
'{{WRAPPER}}.ablocks-block--counter--circle .ablocks-circle-counter__progress', |
| 71 |
$this->get_counter_circle_progress_css( $attributes ) |
| 72 |
); |
| 73 |
|
| 74 |
$css_generator->add_class_styles( |
| 75 |
'{{WRAPPER}} .ablocks-icon-wrap', |
| 76 |
Icon::get_wrapper_css( $attributes ), |
| 77 |
Icon::get_wrapper_css( $attributes, 'Tablet' ), |
| 78 |
Icon::get_wrapper_css( $attributes, 'Mobile' ) |
| 79 |
); |
| 80 |
$css_generator->add_class_styles( |
| 81 |
'{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon', |
| 82 |
Icon::get_element_image_css( $attributes ), |
| 83 |
Icon::get_element_image_css( $attributes, 'Tablet' ), |
| 84 |
Icon::get_element_image_css( $attributes, 'Mobile' ), |
| 85 |
); |
| 86 |
$css_generator->add_class_styles( |
| 87 |
'{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover', |
| 88 |
Icon::get_element_image_hover_css( $attributes ), |
| 89 |
Icon::get_element_image_hover_css( $attributes, 'Tablet' ), |
| 90 |
Icon::get_element_image_hover_css( $attributes, 'Mobile' ), |
| 91 |
); |
| 92 |
$css_generator->add_class_styles( |
| 93 |
'{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon', |
| 94 |
Icon::get_element_css( $attributes ), |
| 95 |
Icon::get_element_css( $attributes, 'Tablet' ), |
| 96 |
Icon::get_element_css( $attributes, 'Mobile' ), |
| 97 |
); |
| 98 |
$css_generator->add_class_styles( |
| 99 |
'{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover', |
| 100 |
Icon::get_element_image_hover_css( $attributes ), |
| 101 |
Icon::get_element_image_hover_css( $attributes, 'Tablet' ), |
| 102 |
Icon::get_element_image_hover_css( $attributes, 'Mobile' ), |
| 103 |
); |
| 104 |
|
| 105 |
return $css_generator->generate_css(); |
| 106 |
} |
| 107 |
|
| 108 |
public function get_wrapper_css( $attributes, $device = '' ) { |
| 109 |
$alignment = ! empty( $attributes['alignment'] ) ? $attributes['alignment'] : ''; |
| 110 |
return Alignment::get_css( $alignment, 'text-align', $device ); |
| 111 |
} |
| 112 |
public function get_number_wrapper_css( $attributes, $device = '' ) { |
| 113 |
$counterNumberWrapperCSS = array( |
| 114 |
'display' => 'flex', |
| 115 |
'align-items' => 'center', |
| 116 |
); |
| 117 |
if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) { |
| 118 |
$counterNumberWrapperCSS['justify-content'] = $attributes['alignment'][ 'value' . $device ]; |
| 119 |
} |
| 120 |
return $counterNumberWrapperCSS; |
| 121 |
} |
| 122 |
public function get_number_text_css( $attributes, $device = '' ) { |
| 123 |
$css = []; |
| 124 |
$number_color = ! empty( $attributes['numberColor'] ) ? $attributes['numberColor'] : ''; |
| 125 |
if ( $number_color ) { |
| 126 |
$css['color'] = $attributes['numberColor']; |
| 127 |
} |
| 128 |
if ( isset( $attributes['mediaPosition'] ) && $attributes['mediaPosition'] === 'leftOfNumber' || isset( $attributes['mediaPosition'] ) && $attributes['mediaPosition'] === 'rightOfNumber' || isset( $attributes['layout'] ) && $attributes['layout'] === 'bar' ) { |
| 129 |
$css['display'] = 'inline-flex'; |
| 130 |
$css['align-items'] = 'center'; |
| 131 |
$css['justify-content'] = 'center'; |
| 132 |
} else { |
| 133 |
$css['display'] = 'block'; |
| 134 |
} |
| 135 |
return array_merge( |
| 136 |
isset( $attributes['numberTypography'] ) ? Typography::get_css( $attributes['numberTypography'], '', $device ) : [], |
| 137 |
isset( $attributes['numberMargin'] ) ? Dimensions::get_css( $attributes['numberMargin'], 'margin', '', $device ) : [], |
| 138 |
$css |
| 139 |
); |
| 140 |
} |
| 141 |
|
| 142 |
public function get_heading_text_css( $attributes, $device = '' ) { |
| 143 |
$css = []; |
| 144 |
$heading_color = ! empty( $attributes['headingColor'] ) ? $attributes['headingColor'] : ''; |
| 145 |
if ( $heading_color ) { |
| 146 |
$css['color'] = $attributes['headingColor']; |
| 147 |
} |
| 148 |
return array_merge( |
| 149 |
isset( $attributes['headingTypography'] ) ? Typography::get_css( $attributes['headingTypography'], '', $device ) : [], |
| 150 |
isset( $attributes['headingMargin'] ) ? Dimensions::get_css( $attributes['headingMargin'], 'margin', $device ) : [], |
| 151 |
$css |
| 152 |
); |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
public function get_counter_bar_bg_css( $attributes ) { |
| 157 |
$counter_bar_bg_css = []; |
| 158 |
|
| 159 |
if ( ! empty( $attributes['barBackgroundColor'] ) ) { |
| 160 |
$counter_bar_bg_css['background'] = $attributes['barBackgroundColor']; |
| 161 |
} |
| 162 |
|
| 163 |
return $counter_bar_bg_css; |
| 164 |
} |
| 165 |
|
| 166 |
public function get_counter_bar_progress_css( $attributes, $device = '' ) { |
| 167 |
$counter_bar_progress_css = []; |
| 168 |
if ( ! empty( $attributes['barProgressColor'] ) ) { |
| 169 |
$counter_bar_progress_css['background'] = $attributes['barProgressColor']; |
| 170 |
} |
| 171 |
if ( ! empty( $attributes['barHeadingPosition'] ) ) { |
| 172 |
if ( $attributes['barHeadingPosition'] === 'inner' ) { |
| 173 |
$counter_bar_progress_css['justify-content'] = 'space-between'; |
| 174 |
} elseif ( |
| 175 |
$attributes['barHeadingPosition'] === 'top' || |
| 176 |
$attributes['barHeadingPosition'] === 'bottom' |
| 177 |
) { |
| 178 |
$counter_bar_progress_css['justify-content'] = 'right'; |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
return array_merge( |
| 183 |
Range::get_css([ |
| 184 |
'attributeValue' => $attributes['barSize'], |
| 185 |
'attribute_object_key' => 'value', |
| 186 |
'isResponsive' => true, |
| 187 |
'defaultValue' => 40, |
| 188 |
'hasUnit' => true, |
| 189 |
'unitDefaultValue' => 'px', |
| 190 |
'property' => 'height', |
| 191 |
'device' => $device, |
| 192 |
]), |
| 193 |
$counter_bar_progress_css, |
| 194 |
); |
| 195 |
} |
| 196 |
|
| 197 |
public function get_counter_circle_css( $attributes, $device = '' ) { |
| 198 |
$counterCircleCSS = array( |
| 199 |
'align-items' => 'center', |
| 200 |
); |
| 201 |
if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) { |
| 202 |
$alignmentValue = $attributes['alignment'][ 'value' . $device ]; |
| 203 |
|
| 204 |
if ( $alignmentValue === 'center' ) { |
| 205 |
$counterCircleCSS['align-items'] = 'center'; |
| 206 |
} elseif ( $alignmentValue === 'left' ) { |
| 207 |
$counterCircleCSS['align-items'] = 'flex-start'; |
| 208 |
} elseif ( $alignmentValue === 'right' ) { |
| 209 |
$counterCircleCSS['align-items'] = 'flex-end'; |
| 210 |
} |
| 211 |
} |
| 212 |
return $counterCircleCSS; |
| 213 |
} |
| 214 |
public function get_counter_circle_bg_css( $attributes ) { |
| 215 |
$counter_circle_bg_css = []; |
| 216 |
|
| 217 |
if ( ! empty( $attributes['circleBackgroundColor'] ) ) { |
| 218 |
$counter_circle_bg_css['stroke'] = $attributes['circleBackgroundColor']; |
| 219 |
} |
| 220 |
|
| 221 |
if ( ! empty( $attributes['circleStrokeSize'] ) ) { |
| 222 |
$counter_circle_bg_css['stroke-width'] = $attributes['circleStrokeSize']; |
| 223 |
} |
| 224 |
|
| 225 |
return array_merge( |
| 226 |
Range::get_css([ |
| 227 |
'attributeValue' => $attributes['circleStrokeSize'], |
| 228 |
'attribute_object_key' => 'value', |
| 229 |
'defaultValue' => 20, |
| 230 |
'property' => 'stroke-width', |
| 231 |
]), |
| 232 |
$counter_circle_bg_css, |
| 233 |
); |
| 234 |
} |
| 235 |
|
| 236 |
public function get_counter_circle_progress_css( $attributes ) { |
| 237 |
$counter_circle_progress_css = []; |
| 238 |
|
| 239 |
if ( ! empty( $attributes['circleProgressColor'] ) ) { |
| 240 |
$counter_circle_progress_css['stroke'] = $attributes['circleProgressColor']; |
| 241 |
} |
| 242 |
|
| 243 |
return array_merge( |
| 244 |
Range::get_css([ |
| 245 |
'attributeValue' => $attributes['circleStrokeSize'], |
| 246 |
'attribute_object_key' => 'value', |
| 247 |
'defaultValue' => 20, |
| 248 |
'property' => 'stroke-width', |
| 249 |
]), |
| 250 |
$counter_circle_progress_css, |
| 251 |
); |
| 252 |
} |
| 253 |
|
| 254 |
} |
| 255 |
|