| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\AcademyEnrollForm; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
use ABlocks\Classes\BlockBaseAbstract; |
| 9 |
use ABlocks\Classes\CssGeneratorV2; |
| 10 |
use ABlocks\Helper; |
| 11 |
use ABlocks\Controls\Typography; |
| 12 |
use ABlocks\Controls\Background; |
| 13 |
use ABlocks\Controls\Border; |
| 14 |
use ABlocks\Controls\Dimensions; |
| 15 |
use ABlocks\Controls\Range; |
| 16 |
use ABlocks\Controls\Color; |
| 17 |
|
| 18 |
class Block extends BlockBaseAbstract { |
| 19 |
protected $block_name = 'academy-enroll-form'; |
| 20 |
|
| 21 |
public function build_css( $attributes ) { |
| 22 |
$css_generator = new CssGeneratorV2( $attributes, $this->block_name ); |
| 23 |
|
| 24 |
$css_generator->add_class_styles( |
| 25 |
'{{WRAPPER}} .academy-enroll-form .academy-widget-enroll__continue a, |
| 26 |
{{WRAPPER}} .academy-widget-enroll__continue .academy-btn, |
| 27 |
{{WRAPPER}} .academy-enroll-form-shortcode__continue a', |
| 28 |
$this->getStartButtonCss( $attributes ), |
| 29 |
$this->getStartButtonCss( $attributes, 'Tablet' ), |
| 30 |
$this->getStartButtonCss( $attributes, 'Mobile' ), |
| 31 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->getStartButtonCss( $attributes, $device ); } ) |
| 32 |
); |
| 33 |
|
| 34 |
$css_generator->add_class_styles( |
| 35 |
'{{WRAPPER}} .academy-enroll-form .academy-widget-enroll__continue a:hover, |
| 36 |
{{WRAPPER}} .academy-widget-enroll__continue .academy-btn:hover, |
| 37 |
{{WRAPPER}} .academy-enroll-form-shortcode__continue a:hover', |
| 38 |
$this->getStartButtonHoverCss( $attributes ), |
| 39 |
$this->getStartButtonHoverCss( $attributes, 'Tablet' ), |
| 40 |
$this->getStartButtonHoverCss( $attributes, 'Mobile' ), |
| 41 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->getStartButtonHoverCss( $attributes, $device ); } ) |
| 42 |
); |
| 43 |
|
| 44 |
$css_generator->add_class_styles( |
| 45 |
'{{WRAPPER}} .academy-enroll-form .academy-widget-enroll__enroll-form button, |
| 46 |
{{WRAPPER}} .academy-enroll-form-shortcode__prerequisite-button, |
| 47 |
{{WRAPPER}} .academy-enroll-form-shortcode__button, |
| 48 |
{{WRAPPER}} .academy-enroll-form-shortcode .academy-course-enroll-form .academy-btn--bg-purple, |
| 49 |
{{WRAPPER}} .academy-widget-enroll__enroll-form .academy-btn, |
| 50 |
{{WRAPPER}} .academy-add-to-cart-button button, |
| 51 |
{{WRAPPER}} .academy-enroll-form-shortcode .academy-course-enroll-form .academy-btn--preset-purple, |
| 52 |
{{WRAPPER}} .academy-widget-enroll__complete-form .academy-btn, |
| 53 |
{{WRAPPER}} .academy-widget-enroll__add-to-cart form button', |
| 54 |
$this->getEnrollButtonCss( $attributes ), |
| 55 |
$this->getEnrollButtonCss( $attributes, 'Tablet' ), |
| 56 |
$this->getEnrollButtonCss( $attributes, 'Mobile' ), |
| 57 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->getEnrollButtonCss( $attributes, $device ); } ) |
| 58 |
); |
| 59 |
|
| 60 |
$css_generator->add_class_styles( |
| 61 |
'{{WRAPPER}} .academy-enroll-form .academy-widget-enroll__enroll-form button:hover, |
| 62 |
{{WRAPPER}} .academy-enroll-form-shortcode__prerequisite-button:hover, |
| 63 |
{{WRAPPER}} .academy-enroll-form-shortcode__button:hover, |
| 64 |
{{WRAPPER}} .academy-enroll-form-shortcode .academy-course-enroll-form .academy-btn--bg-purple:hover, |
| 65 |
{{WRAPPER}} .academy-widget-enroll__enr oll-form .academy-btn:hover, |
| 66 |
{{WRAPPER}} .academy-add-to-cart-button button:hover, |
| 67 |
{{WRAPPER}} .academy-enroll-form-shortcode .academy-course-enroll-form .academy-btn--preset-purple:hover, |
| 68 |
{{WRAPPER}} .academy-widget-enroll__complete-form .academy-btn:hover', |
| 69 |
$this->getEnrollButtonHoverCss( $attributes ), |
| 70 |
$this->getEnrollButtonHoverCss( $attributes, 'Tablet' ), |
| 71 |
$this->getEnrollButtonHoverCss( $attributes, 'Mobile' ), |
| 72 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->getEnrollButtonHoverCss( $attributes, $device ); } ) |
| 73 |
); |
| 74 |
$css_generator->add_class_styles( |
| 75 |
'{{WRAPPER}} .academy-enroll-form-shortcode__prerequisite .academy-shortcode-prerequisites-message', |
| 76 |
$this->get_massage_title_css( $attributes, '' ), |
| 77 |
$this->get_massage_title_css( $attributes, 'Tablet' ), |
| 78 |
$this->get_massage_title_css( $attributes, 'Mobile' ), |
| 79 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_massage_title_css( $attributes, $device ); } ) |
| 80 |
); |
| 81 |
$css_generator->add_class_styles( |
| 82 |
'{{WRAPPER}} .academy-enroll-form-shortcode__prerequisite .academy-shortcode-prerequisites-message:hover', |
| 83 |
$this->get_massage_title_hover_css( $attributes, '' ), |
| 84 |
$this->get_massage_title_hover_css( $attributes, 'Tablet' ), |
| 85 |
$this->get_massage_title_hover_css( $attributes, 'Mobile' ), |
| 86 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_massage_title_hover_css( $attributes, $device ); } ) |
| 87 |
); |
| 88 |
$css_generator->add_class_styles( |
| 89 |
'{{WRAPPER}} .academy-enroll-form-shortcode__prerequisite', |
| 90 |
$this->get_modal_css( $attributes, '' ), |
| 91 |
$this->get_modal_css( $attributes, 'Tablet' ), |
| 92 |
$this->get_modal_css( $attributes, 'Mobile' ), |
| 93 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_modal_css( $attributes, $device ); } ) |
| 94 |
); |
| 95 |
$css_generator->add_class_styles( |
| 96 |
'{{WRAPPER}} .academy-enroll-form-shortcode__prerequisite .academy-shortcode-prerequisites-lists li a', |
| 97 |
$this->get_modal_list_css( $attributes, '' ), |
| 98 |
$this->get_modal_list_css( $attributes, 'Tablet' ), |
| 99 |
$this->get_modal_list_css( $attributes, 'Mobile' ), |
| 100 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_modal_list_css( $attributes, $device ); } ) |
| 101 |
); |
| 102 |
$css_generator->add_class_styles( |
| 103 |
'{{WRAPPER}} .academy-enroll-form-shortcode__prerequisite .academy-shortcode-prerequisites-lists li a:hover', |
| 104 |
$this->get_modal_list_hover_css( $attributes, '' ), |
| 105 |
$this->get_modal_list_hover_css( $attributes, 'Tablet' ), |
| 106 |
$this->get_modal_list_hover_css( $attributes, 'Mobile' ), |
| 107 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_modal_list_hover_css( $attributes, $device ); } ) |
| 108 |
); |
| 109 |
$css_generator->add_class_styles( |
| 110 |
'{{WRAPPER}} .academy-enroll-form-shortcode__price, |
| 111 |
{{WRAPPER}} .academy-widget-enroll__head .academy-course-type, |
| 112 |
{{WRAPPER}} .academy-widget-enroll__head .academy-course-price del, |
| 113 |
{{WRAPPER}} .academy-widget-enroll__head .academy-course-price ins', |
| 114 |
$this->get_price_css( $attributes, '' ), |
| 115 |
$this->get_price_css( $attributes, 'Tablet' ), |
| 116 |
$this->get_price_css( $attributes, 'Mobile' ), |
| 117 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_price_css( $attributes, $device ); } ) |
| 118 |
); |
| 119 |
$css_generator->add_class_styles( |
| 120 |
'{{WRAPPER}} .academy-enroll-form-shortcode__price:hover, |
| 121 |
{{WRAPPER}} .academy-widget-enroll__head .academy-course-type:hover, |
| 122 |
{{WRAPPER}} .academy-widget-enroll__head .academy-course-price del:hover, |
| 123 |
{{WRAPPER}} .academy-widget-enroll__head .academy-course-price ins:hover', |
| 124 |
$this->get_price_hover_css( $attributes, '' ), |
| 125 |
$this->get_price_hover_css( $attributes, 'Tablet' ), |
| 126 |
$this->get_price_hover_css( $attributes, 'Mobile' ), |
| 127 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_price_hover_css( $attributes, $device ); } ) |
| 128 |
); |
| 129 |
$css_generator->add_class_styles( |
| 130 |
'{{WRAPPER}} .academy-widget-enroll__head .title', |
| 131 |
$this->get_price_title_css( $attributes, '' ), |
| 132 |
$this->get_price_title_css( $attributes, 'Tablet' ), |
| 133 |
$this->get_price_title_css( $attributes, 'Mobile' ), |
| 134 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_price_title_css( $attributes, $device ); } ) |
| 135 |
); |
| 136 |
$css_generator->add_class_styles( |
| 137 |
'{{WRAPPER}} .academy-widget-enroll__head .title', |
| 138 |
$this->get_price_title_hover_css( $attributes, '' ), |
| 139 |
$this->get_price_title_hover_css( $attributes, 'Tablet' ), |
| 140 |
$this->get_price_title_hover_css( $attributes, 'Mobile' ), |
| 141 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_price_title_hover_css( $attributes, $device ); } ) |
| 142 |
); |
| 143 |
$css_generator->add_class_styles( |
| 144 |
'{{WRAPPER}} .academy-widget-enroll__enrolled-info', |
| 145 |
$this->get_enroll_info_css( $attributes, '' ), |
| 146 |
$this->get_enroll_info_css( $attributes, 'Tablet' ), |
| 147 |
$this->get_enroll_info_css( $attributes, 'Mobile' ), |
| 148 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_enroll_info_css( $attributes, $device ); } ) |
| 149 |
); |
| 150 |
$css_generator->add_class_styles( |
| 151 |
'{{WRAPPER}} .academy-widget-enroll__enrolled-info:hover', |
| 152 |
$this->get_enroll_info_hover_css( $attributes, '' ), |
| 153 |
$this->get_enroll_info_hover_css( $attributes, 'Tablet' ), |
| 154 |
$this->get_enroll_info_hover_css( $attributes, 'Mobile' ), |
| 155 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_enroll_info_hover_css( $attributes, $device ); } ) |
| 156 |
); |
| 157 |
|
| 158 |
return $css_generator->generate_css(); |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public function getStartButtonCss( $attributes, $device = '' ) { |
| 164 |
$typographyValueGlobal = ! empty( $attributes['start_btn_typographyGlobal'] ) ? $attributes['start_btn_typographyGlobal'] : ''; |
| 165 |
$start_btn_typography = isset( $attributes['start_btn_typography'] ) ? $attributes['start_btn_typography'] : []; |
| 166 |
$start_btn_padding = ! empty( $attributes['start_btn_padding'] ) ? Dimensions::get_css( $attributes['start_btn_padding'], 'padding', $device ) : array(); |
| 167 |
$start_btn_border = ! empty( $attributes['start_btn_border'] ) ? Border::get_css( $attributes['start_btn_border'], '', $device ) : array(); |
| 168 |
return array_merge( |
| 169 |
[ 'color' => Color::get_css( isset( $attributes['start_btn_color'] ) ? $attributes['start_btn_color'] : '' ) ], |
| 170 |
[ 'background' => Color::get_css( isset( $attributes['start_btn_bg_color'] ) ? $attributes['start_btn_bg_color'] : '' ) ], |
| 171 |
Typography::get_css( $start_btn_typography, '', $device, $typographyValueGlobal ), |
| 172 |
$start_btn_padding, |
| 173 |
$start_btn_border, |
| 174 |
); |
| 175 |
} |
| 176 |
public function getStartButtonHoverCss( $attributes, $device = '' ) { |
| 177 |
$start_btn_border = ! empty( $attributes['start_btn_border'] ) ? Border::get_hover_css( $attributes['start_btn_border'], '', $device ) : array(); |
| 178 |
return array_merge( |
| 179 |
[ 'color' => Color::get_css( isset( $attributes['start_btn_color_hover'] ) ? $attributes['start_btn_color_hover'] : '' ) ], |
| 180 |
[ 'background' => Color::get_css( isset( $attributes['start_btn_bg_hover_color'] ) ? $attributes['start_btn_bg_hover_color'] : '' ) ], |
| 181 |
$start_btn_border |
| 182 |
); |
| 183 |
} |
| 184 |
|
| 185 |
public function getEnrollButtonCss( $attributes, $device = '' ) { |
| 186 |
$typographyValueGlobal = ! empty( $attributes['enroll_btn_typographyGlobal'] ) ? $attributes['enroll_btn_typographyGlobal'] : ''; |
| 187 |
$enroll_btn_typography = isset( $attributes['enroll_btn_typography'] ) ? $attributes['enroll_btn_typography'] : []; |
| 188 |
$enroll_btn_padding = ! empty( $attributes['enroll_btn_padding'] ) ? Dimensions::get_css( $attributes['enroll_btn_padding'], 'padding', $device ) : array(); |
| 189 |
$enroll_btn_border = ! empty( $attributes['enroll_btn_border'] ) ? Border::get_css( $attributes['enroll_btn_border'], '', $device ) : array(); |
| 190 |
|
| 191 |
return array_merge( |
| 192 |
[ 'color' => Color::get_css( isset( $attributes['enroll_btn_color'] ) ? $attributes['enroll_btn_color'] : '' ) ], |
| 193 |
[ 'background' => Color::get_css( isset( $attributes['enroll_btn_bg_color'] ) ? $attributes['enroll_btn_bg_color'] : '' ) ], |
| 194 |
Typography::get_css( $enroll_btn_typography, '', $device, $typographyValueGlobal ), |
| 195 |
$enroll_btn_padding, |
| 196 |
$enroll_btn_border, |
| 197 |
); |
| 198 |
} |
| 199 |
public function getEnrollButtonHoverCss( $attributes, $device = '' ) { |
| 200 |
$enroll_btn_border = ! empty( $attributes['enroll_btn_border'] ) ? Border::get_hover_css( $attributes['enroll_btn_border'], '', $device ) : array(); |
| 201 |
return array_merge( |
| 202 |
[ 'color' => Color::get_css( isset( $attributes['enroll_btn_color_hover'] ) ? $attributes['enroll_btn_color_hover'] : '' ) ], |
| 203 |
[ 'background' => Color::get_css( isset( $attributes['enroll_btn_bg_hover_color'] ) ? $attributes['enroll_btn_bg_hover_color'] : '' ) ], |
| 204 |
$enroll_btn_border |
| 205 |
); |
| 206 |
} |
| 207 |
|
| 208 |
public function get_massage_title_css( $attributes, $device = '' ) { |
| 209 |
$typographyValueGlobal = ! empty( $attributes['massage_title_typographyGlobal'] ) ? $attributes['massage_title_typographyGlobal'] : ''; |
| 210 |
$typography_value = isset( $attributes['massage_title_typography'] ) ? $attributes['massage_title_typography'] : []; |
| 211 |
|
| 212 |
return array_merge( |
| 213 |
[ 'color' => Color::get_css( isset( $attributes['massage_title_color'] ) ? $attributes['massage_title_color'] : '' ) ], |
| 214 |
[ 'background' => Color::get_css( isset( $attributes['massage_title_bg'] ) ? $attributes['massage_title_bg'] : '' ) ], |
| 215 |
Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ), |
| 216 |
); |
| 217 |
} |
| 218 |
public function get_massage_title_hover_css( $attributes, $device = '' ) { |
| 219 |
return array_merge( |
| 220 |
[ 'color' => Color::get_css( isset( $attributes['massage_title_hover_color'] ) ? $attributes['massage_title_hover_color'] : '' ) ], |
| 221 |
[ 'background' => Color::get_css( isset( $attributes['massage_title_hover_bg'] ) ? $attributes['massage_title_hover_bg'] : '' ) ] |
| 222 |
); |
| 223 |
|
| 224 |
} |
| 225 |
public function get_modal_css( $attributes, $device = '' ) { |
| 226 |
return array_merge( |
| 227 |
Range::get_css([ |
| 228 |
'attributeValue' => $attributes['modalWidth'], |
| 229 |
'attribute_object_key' => 'value', |
| 230 |
'isResponsive' => true, |
| 231 |
'defaultValue' => 150, |
| 232 |
'hasUnit' => true, |
| 233 |
'unitDefaultValue' => 'px', |
| 234 |
'property' => 'width', |
| 235 |
'device' => $device, |
| 236 |
]), |
| 237 |
); |
| 238 |
|
| 239 |
} |
| 240 |
|
| 241 |
public function get_modal_list_css( $attributes, $device = '' ) { |
| 242 |
$css = []; |
| 243 |
$css['text-decoration'] = 'none'; |
| 244 |
$typographyValueGlobal = ! empty( $attributes['list_typographyGlobal'] ) ? $attributes['list_typographyGlobal'] : ''; |
| 245 |
$typography_value = isset( $attributes['list_typography'] ) ? $attributes['list_typography'] : []; |
| 246 |
|
| 247 |
return array_merge( |
| 248 |
[ 'color' => Color::get_css( isset( $attributes['list_color'] ) ? $attributes['list_color'] : '' ) ], |
| 249 |
$css, |
| 250 |
Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ), |
| 251 |
); |
| 252 |
} |
| 253 |
|
| 254 |
public function get_modal_list_hover_css( $attributes, $device = '' ) { |
| 255 |
return [ 'color' => Color::get_css( isset( $attributes['list_hover_color'] ) ? $attributes['list_hover_color'] : '' ) ]; |
| 256 |
|
| 257 |
} |
| 258 |
|
| 259 |
public function get_price_css( $attributes, $device = '' ) { |
| 260 |
$typographyValueGlobal = ! empty( $attributes['price_typographyGlobal'] ) ? $attributes['price_typographyGlobal'] : ''; |
| 261 |
$typography_value = isset( $attributes['price_typography'] ) ? $attributes['price_typography'] : []; |
| 262 |
return array_merge( |
| 263 |
[ 'color' => Color::get_css( isset( $attributes['price_color'] ) ? $attributes['price_color'] : '' ) ], |
| 264 |
Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ), ); |
| 265 |
} |
| 266 |
|
| 267 |
public function get_price_hover_css( $attributes, $device = '' ) { |
| 268 |
return [ 'color' => Color::get_css( isset( $attributes['price_hover_color'] ) ? $attributes['price_hover_color'] : '' ) ]; |
| 269 |
} |
| 270 |
|
| 271 |
public function get_price_title_css( $attributes, $device = '' ) { |
| 272 |
$css = []; |
| 273 |
$css['color'] = $attributes['price_title_color'] ?? ''; |
| 274 |
$typography_value = ! empty( $attributes['price_title_typography'] ) ? Typography::get_css( $attributes['price_title_typography'], '', $device ) : array(); |
| 275 |
|
| 276 |
return array_merge( |
| 277 |
$css, |
| 278 |
$typography_value, |
| 279 |
); |
| 280 |
|
| 281 |
} |
| 282 |
public function get_price_title_hover_css( $attributes, $device = '' ) { |
| 283 |
$css = []; |
| 284 |
$css['color'] = $attributes['price_title_hover_color'] ?? ''; |
| 285 |
return $css; |
| 286 |
} |
| 287 |
|
| 288 |
public function get_enroll_info_css( $attributes, $device = '' ) { |
| 289 |
$css = []; |
| 290 |
$css['color'] = $attributes['info_color'] ?? '#7b68ee'; |
| 291 |
$css['background'] = $attributes['info_bg'] ?? '#eae8fa'; |
| 292 |
|
| 293 |
$typography_value = $attributes['info_typography'] ? Typography::get_css( $attributes['info_typography'], '', $device ) : array(); |
| 294 |
|
| 295 |
return array_merge( |
| 296 |
$css, |
| 297 |
$typography_value |
| 298 |
); |
| 299 |
} |
| 300 |
|
| 301 |
public function get_enroll_info_hover_css( $attributes, $device = '' ) { |
| 302 |
$css = []; |
| 303 |
$css['color'] = $attributes['info_color_hover'] ?? '#7b68ee'; |
| 304 |
$css['background'] = $attributes['info_bg_hover'] ?? '#eae8fa'; |
| 305 |
|
| 306 |
return array_merge( |
| 307 |
$css, |
| 308 |
Range::get_css([ |
| 309 |
'attributeValue' => $attributes['bg_transition'], |
| 310 |
'attribute_object_key' => 'value', |
| 311 |
'defaultValue' => 0, |
| 312 |
'unitDefaultValue' => 's', |
| 313 |
'property' => 'transition-duration', |
| 314 |
'device' => $device, |
| 315 |
]), |
| 316 |
); |
| 317 |
} |
| 318 |
|
| 319 |
public function render_block_content( $attributes, $content, $block_instance ) { |
| 320 |
$attr_array = [ |
| 321 |
'course_id' => absint( Helper::get_attribute_value( $attributes, 'course_id' ) ), |
| 322 |
'layout' => (string) ( Helper::get_attribute_value( $attributes, 'layout' ) ) |
| 323 |
]; |
| 324 |
|
| 325 |
if ( isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) && empty( $attr_array['course_id'] ) ) { |
| 326 |
$attr_array['course_id'] = $block_instance->context['postId']; |
| 327 |
} |
| 328 |
|
| 329 |
$shortcode = '[academy_enroll_form ' . Helper::attr_shortcode( $attr_array ) . ']'; |
| 330 |
echo do_shortcode( $shortcode ); |
| 331 |
} |
| 332 |
|
| 333 |
} |
| 334 |
|