| @@ -1,0 +1,93 @@ | ||
| 1 | +<?php | |
| 2 | +namespace ABlocks\Blocks\AcademyCertificate; | |
| 3 | + | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 8 | +use ABlocks\Classes\BlockBaseAbstract; | |
| 9 | +use ABlocks\Classes\CssGenerator; | |
| 10 | +use ABlocks\Controls\Dimensions; | |
| 11 | + | |
| 12 | +class Block extends BlockBaseAbstract { | |
| 13 | + protected $block_name = 'academy-certificate'; | |
| 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_certificate_wrapper_css( $attributes ), | |
| 21 | + $this->get_certificate_wrapper_css( $attributes, 'Tablet' ), | |
| 22 | + $this->get_certificate_wrapper_css( $attributes, 'Mobile' ), | |
| 23 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_certificate_wrapper_css( $attributes, $device ); } ) | |
| 24 | + ); | |
| 25 | + $css_generator->add_class_styles( | |
| 26 | + '{{WRAPPER}} .ablocks-block--certificate__background-image', | |
| 27 | + $this->get_certificate_bg_img_css( $attributes ), | |
| 28 | + $this->get_certificate_bg_img_css( $attributes, 'Tablet' ), | |
| 29 | + $this->get_certificate_bg_img_css( $attributes, 'Mobile' ), | |
| 30 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_certificate_bg_img_css( $attributes, $device ); } ) | |
| 31 | + ); | |
| 32 | + $css_generator->add_class_styles( | |
| 33 | + '{{WRAPPER}} .ablocks-block--certificate__background-image-inner-block', | |
| 34 | + $this->get_certificate_inner_block_css( $attributes ), | |
| 35 | + $this->get_certificate_inner_block_css( $attributes, 'Tablet' ), | |
| 36 | + $this->get_certificate_inner_block_css( $attributes, 'Mobile' ), | |
| 37 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_certificate_inner_block_css( $attributes, $device ); } ) | |
| 38 | + ); | |
| 39 | + | |
| 40 | + return $css_generator->generate_css(); | |
| 41 | + } | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + public function get_certificate_wrapper_css( $attributes, $device = '' ) { | |
| 46 | + $css = array(); | |
| 47 | + $css['width'] = '100%'; | |
| 48 | + $css['height'] = '100% !important'; | |
| 49 | + $css['padding'] = '0px !important'; | |
| 50 | + return $css; | |
| 51 | + } | |
| 52 | + public function get_certificate_bg_img_css( $attributes, $device = '' ) { | |
| 53 | + $css = array(); | |
| 54 | + if ( ! empty( $attributes['backgroundImage'] ) ) { | |
| 55 | + $css['background-image'] = 'url(' . $attributes['backgroundImage'] . ')'; | |
| 56 | + } | |
| 57 | + | |
| 58 | + if ( $attributes['pageOrientation'] === 'P' ) { | |
| 59 | + $css['background-size'] = 'inherit'; | |
| 60 | + $css['background-repeat'] = 'repeat !important'; | |
| 61 | + $css['background-position'] = 'center !important'; | |
| 62 | + | |
| 63 | + } else { | |
| 64 | + $css['background-image-resize'] = '6'; | |
| 65 | + $css['background-repeat'] = 'no-repeat !important'; | |
| 66 | + } | |
| 67 | + $css['width'] = '100%'; | |
| 68 | + $css['height'] = '100% !important'; | |
| 69 | + return $css; | |
| 70 | + } | |
| 71 | + | |
| 72 | + public function get_certificate_inner_block_css( $attributes, $device = '' ) { | |
| 73 | + $css = array(); | |
| 74 | + if ( ! empty( $attributes['containerWidth'] ) ) { | |
| 75 | + $css['width'] = $attributes['containerWidth'] . '%'; | |
| 76 | + } | |
| 77 | + $css['height'] = '100%'; | |
| 78 | + $css['box-sizing'] = 'border-box'; | |
| 79 | + $css['padding'] = '100px'; | |
| 80 | + $css['margin'] = 'auto !important'; | |
| 81 | + if ( ! empty( $attributes['certificate_padding'] ) ) { | |
| 82 | + $cssPadding = Dimensions::get_css( $attributes['certificate_padding'], 'padding', $device ); | |
| 83 | + } | |
| 84 | + | |
| 85 | + return array_merge( | |
| 86 | + $css, | |
| 87 | + $cssPadding | |
| 88 | + ); | |
| 89 | + } | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | +} | |