| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\Countdown; |
| 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\Border; |
| 9 |
use ABlocks\Controls\BoxShadow; |
| 10 |
use ABlocks\Controls\Range; |
| 11 |
|
| 12 |
class Block extends BlockBaseAbstract { |
| 13 |
protected $block_name = 'countdown'; |
| 14 |
|
| 15 |
public function build_css( $attributes ) { |
| 16 |
$css_generator = new CssGenerator( $attributes ); |
| 17 |
|
| 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 |
|
| 25 |
$css_generator->add_class_styles( |
| 26 |
'{{WRAPPER}} .ablocks-block-container', |
| 27 |
$this->get_countdown_items_css( $attributes ), |
| 28 |
$this->get_countdown_items_css( $attributes, 'Tablet' ), |
| 29 |
$this->get_countdown_items_css( $attributes, 'Mobile' ) |
| 30 |
); |
| 31 |
|
| 32 |
$css_generator->add_class_styles( |
| 33 |
'{{WRAPPER}} .ablocks-countdown__item', |
| 34 |
$this->get_countdown_item_css( $attributes ), |
| 35 |
$this->get_countdown_item_css( $attributes, 'Tablet' ), |
| 36 |
$this->get_countdown_item_css( $attributes, 'Mobile' ) |
| 37 |
); |
| 38 |
$css_generator->add_class_styles( |
| 39 |
'{{WRAPPER}} .ablocks-countdown__item:hover', |
| 40 |
$this->get_countdown_item_hover_css( $attributes ), |
| 41 |
$this->get_countdown_item_hover_css( $attributes, 'Tablet' ), |
| 42 |
$this->get_countdown_item_hover_css( $attributes, 'Mobile' ) |
| 43 |
); |
| 44 |
|
| 45 |
$css_generator->add_class_styles( |
| 46 |
'{{WRAPPER}} .ablocks-countdown__item .ablocks-countdown-label', |
| 47 |
$this->get_label_css( $attributes ), |
| 48 |
$this->get_label_css( $attributes, 'Tablet' ), |
| 49 |
$this->get_label_css( $attributes, 'Mobile' ) |
| 50 |
); |
| 51 |
|
| 52 |
$css_generator->add_class_styles( |
| 53 |
'{{WRAPPER}} .ablocks-countdown__item .ablocks-countdown-value', |
| 54 |
$this->get_number_css( $attributes ), |
| 55 |
$this->get_number_css( $attributes, 'Tablet' ), |
| 56 |
$this->get_number_css( $attributes, 'Mobile' ) |
| 57 |
); |
| 58 |
|
| 59 |
$css_generator->add_class_styles( |
| 60 |
'{{WRAPPER}} .ablocks-countdown__separator', |
| 61 |
$this->get_separator_css( $attributes ), |
| 62 |
$this->get_separator_css( $attributes, 'Tablet' ), |
| 63 |
$this->get_separator_css( $attributes, 'Mobile' ) |
| 64 |
); |
| 65 |
|
| 66 |
return $css_generator->generate_css(); |
| 67 |
} |
| 68 |
|
| 69 |
public function get_wrapper_css( $attributes, $device = '' ) { |
| 70 |
$alignment = ! empty( $attributes['alignment'] ) ? $attributes['alignment'] : ''; |
| 71 |
return Alignment::get_css( $alignment, 'text-align', $device ); |
| 72 |
} |
| 73 |
|
| 74 |
public function get_countdown_items_css( $attributes, $device = '' ) { |
| 75 |
$css = []; |
| 76 |
|
| 77 |
if ( ! empty( $attributes['orient'][ 'value' . $device ] ) ) { |
| 78 |
$css['flex-direction'] = $attributes['orient'][ 'value' . $device ]; |
| 79 |
} |
| 80 |
if ( ! empty( $attributes['justifyDep'][ 'value' . $device ] ) ) { |
| 81 |
$css['justify-content'] = $attributes['justifyDep'][ 'value' . $device ]; |
| 82 |
} |
| 83 |
if ( ! empty( $attributes['alignment'][ 'value' . $device ] ) ) { |
| 84 |
$css['align-items'] = $attributes['alignment'][ 'value' . $device ]; |
| 85 |
} |
| 86 |
if ( ! empty( $attributes['wrapping'][ 'value' . $device ] ) ) { |
| 87 |
$css['flex-wrap'] = $attributes['wrapping'][ 'value' . $device ]; |
| 88 |
} |
| 89 |
if ( ! empty( $attributes['boxColumnGap'][ 'value' . $device ] ) ) { |
| 90 |
$css['column-gap'] = $attributes['boxColumnGap'][ 'value' . $device ] |
| 91 |
. ( ! empty( $attributes['boxColumnGap'][ 'valueUnit' . $device ] ) ? $attributes['boxColumnGap'][ 'valueUnit' . $device ] : 'px' ); |
| 92 |
} |
| 93 |
|
| 94 |
if ( ! empty( $attributes['boxRowGap'][ 'value' . $device ] ) ) { |
| 95 |
$css['row-gap'] = $attributes['boxRowGap'][ 'value' . $device ] |
| 96 |
. ( ! empty( $attributes['boxRowGap'][ 'valueUnit' . $device ] ) ? $attributes['boxRowGap'][ 'valueUnit' . $device ] : 'px' ); |
| 97 |
} |
| 98 |
return array_merge( |
| 99 |
Range::get_css([ |
| 100 |
'attributeValue' => $attributes['boxSize'], |
| 101 |
'attribute_object_key' => 'value', |
| 102 |
'isResponsive' => true, |
| 103 |
'defaultValue' => 130, |
| 104 |
'hasUnit' => true, |
| 105 |
'unitDefaultValue' => 'px', |
| 106 |
'property' => 'min-height', |
| 107 |
'device' => $device, |
| 108 |
]), |
| 109 |
Range::get_css([ |
| 110 |
'attributeValue' => $attributes['boxRowGap'], |
| 111 |
'attribute_object_key' => 'value', |
| 112 |
'isResponsive' => true, |
| 113 |
'defaultValue' => 0, |
| 114 |
'hasUnit' => true, |
| 115 |
'unitDefaultValue' => 'px', |
| 116 |
'property' => 'row-gap', |
| 117 |
'device' => $device, |
| 118 |
]), |
| 119 |
Range::get_css([ |
| 120 |
'attributeValue' => $attributes['boxColumnGap'], |
| 121 |
'attribute_object_key' => 'value', |
| 122 |
'isResponsive' => true, |
| 123 |
'defaultValue' => 0, |
| 124 |
'hasUnit' => true, |
| 125 |
'unitDefaultValue' => 'px', |
| 126 |
'property' => 'column-gap', |
| 127 |
'device' => $device, |
| 128 |
]), |
| 129 |
$css, |
| 130 |
); |
| 131 |
} |
| 132 |
|
| 133 |
public function get_countdown_item_css( $attributes, $device = '' ) { |
| 134 |
$css = []; |
| 135 |
|
| 136 |
$box_background_color = ! empty( $attributes['boxBackgroundColor'] ) ? $attributes['boxBackgroundColor'] : ''; |
| 137 |
|
| 138 |
$label_position = ! empty( $attributes['labelPosition'] ) ? $attributes['labelPosition'] : ''; |
| 139 |
if ( $label_position ) { |
| 140 |
$css['flex-direction'] = $label_position; |
| 141 |
} |
| 142 |
if ( $box_background_color ) { |
| 143 |
$css['background'] = $box_background_color; |
| 144 |
} |
| 145 |
$border_css = []; |
| 146 |
if ( isset( $attributes['boxBorder'] ) ) { |
| 147 |
$border_css = Border::get_css( $attributes['boxBorder'], '', $device ); |
| 148 |
} |
| 149 |
return array_merge( |
| 150 |
Range::get_css([ |
| 151 |
'attributeValue' => $attributes['boxSize'], |
| 152 |
'attribute_object_key' => 'value', |
| 153 |
'isResponsive' => true, |
| 154 |
'defaultValue' => 130, |
| 155 |
'hasUnit' => true, |
| 156 |
'unitDefaultValue' => 'px', |
| 157 |
'property' => 'width', |
| 158 |
'device' => $device, |
| 159 |
]), |
| 160 |
Range::get_css([ |
| 161 |
'attributeValue' => $attributes['numberAndLabelGap'], |
| 162 |
'attribute_object_key' => 'value', |
| 163 |
'isResponsive' => true, |
| 164 |
'defaultValue' => 5, |
| 165 |
'hasUnit' => true, |
| 166 |
'unitDefaultValue' => 'px', |
| 167 |
'property' => 'gap', |
| 168 |
'device' => $device, |
| 169 |
]), |
| 170 |
$border_css, |
| 171 |
$css, |
| 172 |
BoxShadow::get_css( ! empty( $attributes['boxShadow'] ) ? $attributes['boxShadow'] : '', $device ) |
| 173 |
); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
public function get_countdown_item_hover_css( $attributes, $device = '' ) { |
| 179 |
return array_merge( |
| 180 |
Border::get_hover_css( ! empty( $attributes['boxBorder'] ) ? $attributes['boxBorder'] : [], '', $device ), |
| 181 |
BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device ) |
| 182 |
); |
| 183 |
} |
| 184 |
|
| 185 |
public function get_label_css( $attributes, $device = '' ) { |
| 186 |
$css = []; |
| 187 |
$label_color = ! empty( $attributes['labelColor'] ) ? $attributes['labelColor'] : ''; |
| 188 |
if ( $label_color ) { |
| 189 |
$css['color'] = $label_color; |
| 190 |
} |
| 191 |
if ( $attributes['labelBgColor'] ) { |
| 192 |
$css['background'] = $attributes['labelBgColor']; |
| 193 |
} |
| 194 |
if ( $attributes['labelPosition'] === 'column' || $attributes['labelPosition'] === 'column-reverse' ) { |
| 195 |
$css['width'] = '100%'; |
| 196 |
$css['flex'] = '1 1 30%'; |
| 197 |
$css['display'] = 'flex'; |
| 198 |
$css['justify-content'] = 'center'; |
| 199 |
$css['align-items'] = 'center'; |
| 200 |
} |
| 201 |
return array_merge( |
| 202 |
! empty( $attributes['labelTypography'] ) ? Typography::get_css( $attributes['labelTypography'], '', $device ) : array(), |
| 203 |
$css |
| 204 |
); |
| 205 |
} |
| 206 |
|
| 207 |
public function get_number_css( $attributes, $device = '' ) { |
| 208 |
$css = []; |
| 209 |
$number_color = ! empty( $attributes['numberColor'] ) ? $attributes['numberColor'] : ''; |
| 210 |
if ( $number_color ) { |
| 211 |
$css['color'] = $number_color; |
| 212 |
} |
| 213 |
if ( $attributes['numberBgColor'] ) { |
| 214 |
$css['background'] = $attributes['numberBgColor']; |
| 215 |
} |
| 216 |
if ( $attributes['labelPosition'] === 'column' || $attributes['labelPosition'] === 'column-reverse' ) { |
| 217 |
$css['width'] = '100%'; |
| 218 |
$css['flex'] = '1 1 70%'; |
| 219 |
$css['display'] = 'flex'; |
| 220 |
$css['justify-content'] = 'center'; |
| 221 |
$css['align-items'] = 'center'; |
| 222 |
} |
| 223 |
return array_merge( |
| 224 |
! empty( $attributes['numberTypography'] ) ? Typography::get_css( $attributes['numberTypography'], '', $device ) : array(), |
| 225 |
$css |
| 226 |
); |
| 227 |
} |
| 228 |
|
| 229 |
public function get_separator_css( $attributes, $device = '' ) { |
| 230 |
$css = []; |
| 231 |
$separator_color = ! empty( $attributes['separatorColor'] ) ? $attributes['separatorColor'] : ''; |
| 232 |
if ( $separator_color ) { |
| 233 |
$css['color'] = $separator_color; |
| 234 |
} |
| 235 |
return array_merge( |
| 236 |
! empty( $attributes['separatorTypography'] ) ? Typography::get_css( $attributes['separatorTypography'], '', $device ) : array(), |
| 237 |
$css |
| 238 |
); |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
|