← All changes
|
includes/blocks/academy-course-instructor/block.php
+225
-0
2.7.4
→
2.14.0
View file →
| @@ -1,0 +1,225 @@ | ||
| 1 | +<?php | |
| 2 | +namespace ABlocks\Blocks\AcademyCourseInstructor; | |
| 3 | + | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 8 | +use ABlocks\Classes\BlockBaseAbstract; | |
| 9 | +use ABlocks\Classes\CssGenerator; | |
| 10 | +use ABlocks\Classes\CssGeneratorV2; | |
| 11 | +use ABlocks\Helper; | |
| 12 | +use ABlocks\Controls\Typography; | |
| 13 | +use ABlocks\Controls\Background; | |
| 14 | +use ABlocks\Controls\Border; | |
| 15 | +use ABlocks\Controls\Dimensions; | |
| 16 | +use ABlocks\Controls\Range; | |
| 17 | +use ABlocks\Controls\BoxShadow; | |
| 18 | +use ABlocks\Controls\Color; | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | +class Block extends BlockBaseAbstract { | |
| 23 | + protected $block_name = 'academy-course-instructor'; | |
| 24 | + | |
| 25 | + public function build_css( $attributes ) { | |
| 26 | + $css_generator = new CssGeneratorV2( $attributes, $this->block_name ); | |
| 27 | + | |
| 28 | + $css_generator->add_class_styles( | |
| 29 | + '{{WRAPPER}} .academy-single-course__content-item--instructors .course-single-instructor .instructor-info__thumbnail img', | |
| 30 | + $this->get_avatar_image_css( $attributes, '' ), | |
| 31 | + $this->get_avatar_image_css( $attributes, 'Tablet' ), | |
| 32 | + $this->get_avatar_image_css( $attributes, 'Mobile' ), | |
| 33 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_avatar_image_css( $attributes, $device ); } ) | |
| 34 | + ); | |
| 35 | + | |
| 36 | + $css_generator->add_class_styles( | |
| 37 | + '{{WRAPPER}} .academy-single-course__content-item--instructors .course-single-instructor .instructor-review__title, | |
| 38 | + {{WRAPPER}} .academy-single-course__content-item--instructors .course-single-instructor .instructor-info__content .instructor-title', | |
| 39 | + $this->get_title_css( $attributes, '' ), | |
| 40 | + $this->get_title_css( $attributes, 'Tablet' ), | |
| 41 | + $this->get_title_css( $attributes, 'Mobile' ), | |
| 42 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_title_css( $attributes, $device ); } ) | |
| 43 | + ); | |
| 44 | + | |
| 45 | + $css_generator->add_class_styles( | |
| 46 | + '{{WRAPPER}} .academy-single-course__content-item--instructors .course-single-instructor .instructor-review__title:hover, | |
| 47 | + {{WRAPPER}} .academy-single-course__content-item--instructors .course-single-instructor .instructor-info__content .instructor-title:hover', | |
| 48 | + $this->get_title_hover_css( $attributes, '' ), | |
| 49 | + $this->get_title_hover_css( $attributes, 'Tablet' ), | |
| 50 | + $this->get_title_hover_css( $attributes, 'Mobile' ), | |
| 51 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_title_hover_css( $attributes, $device ); } ) | |
| 52 | + ); | |
| 53 | + | |
| 54 | + $css_generator->add_class_styles( | |
| 55 | + '{{WRAPPER}} .academy-single-course__content-item--instructors .course-single-instructor .instructor-review__rating span', | |
| 56 | + $this->get_review_text_css( $attributes, '' ), | |
| 57 | + $this->get_review_text_css( $attributes, 'Tablet' ), | |
| 58 | + $this->get_review_text_css( $attributes, 'Mobile' ), | |
| 59 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_review_text_css( $attributes, $device ); } ) | |
| 60 | + ); | |
| 61 | + | |
| 62 | + $css_generator->add_class_styles( | |
| 63 | + '{{WRAPPER}} .academy-single-course__content-item--instructors .course-single-instructor .instructor-review__rating span:hover', | |
| 64 | + $this->get_review_text_hover_css( $attributes, '' ), | |
| 65 | + $this->get_review_text_hover_css( $attributes, 'Tablet' ), | |
| 66 | + $this->get_review_text_hover_css( $attributes, 'Mobile' ), | |
| 67 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_review_text_hover_css( $attributes, $device ); } ) | |
| 68 | + ); | |
| 69 | + $css_generator->add_class_styles( | |
| 70 | + '{{WRAPPER}} .academy-single-course__content-item--instructors .course-single-instructor .instructor-review__rating .academy-group-star .academy-icon:before', | |
| 71 | + $this->get_review_icon_css( $attributes, '' ), | |
| 72 | + $this->get_review_icon_css( $attributes, 'Tablet' ), | |
| 73 | + $this->get_review_icon_css( $attributes, 'Mobile' ), | |
| 74 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_review_icon_css( $attributes, $device ); } ) | |
| 75 | + ); | |
| 76 | + $css_generator->add_class_styles( | |
| 77 | + '{{WRAPPER}} .academy-single-course__content-item--instructors .course-single-instructor .instructor-review__rating .academy-group-star .academy-icon:hover:before', | |
| 78 | + $this->get_review_icon_hover_css( $attributes, '' ), | |
| 79 | + $this->get_review_icon_hover_css( $attributes, 'Tablet' ), | |
| 80 | + $this->get_review_icon_hover_css( $attributes, 'Mobile' ), | |
| 81 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_review_icon_hover_css( $attributes, $device ); } ) | |
| 82 | + ); | |
| 83 | + $css_generator->add_class_styles( | |
| 84 | + '{{WRAPPER}} .academy-single-course__content-item--instructors .course-single-instructor .instructor-info__content .instructor-name a', | |
| 85 | + $this->get_instructor_css( $attributes, '' ), | |
| 86 | + $this->get_instructor_css( $attributes, 'Tablet' ), | |
| 87 | + $this->get_instructor_css( $attributes, 'Mobile' ), | |
| 88 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_instructor_css( $attributes, $device ); } ) | |
| 89 | + ); | |
| 90 | + $css_generator->add_class_styles( | |
| 91 | + '{{WRAPPER}} .academy-single-course__content-item--instructors .course-single-instructor .instructor-info__content .instructor-name a:hover', | |
| 92 | + $this->get_instructor_hover_css( $attributes, '' ), | |
| 93 | + $this->get_instructor_hover_css( $attributes, 'Tablet' ), | |
| 94 | + $this->get_instructor_hover_css( $attributes, 'Mobile' ), | |
| 95 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_instructor_hover_css( $attributes, $device ); } ) | |
| 96 | + ); | |
| 97 | + | |
| 98 | + return $css_generator->generate_css(); | |
| 99 | + } | |
| 100 | + | |
| 101 | + public function get_avatar_image_css( $attributes, $device = '' ) { | |
| 102 | + return array_merge( | |
| 103 | + Range::get_css([ | |
| 104 | + 'attributeValue' => $attributes['avatarH'], | |
| 105 | + 'attribute_object_key' => 'value', | |
| 106 | + 'isResponsive' => true, | |
| 107 | + 'defaultValue' => 62, | |
| 108 | + 'hasUnit' => true, | |
| 109 | + 'unitDefaultValue' => 'px', | |
| 110 | + 'property' => 'height', | |
| 111 | + 'device' => $device, | |
| 112 | + ]), | |
| 113 | + Range::get_css([ | |
| 114 | + 'attributeValue' => $attributes['avatarW'], | |
| 115 | + 'attribute_object_key' => 'value', | |
| 116 | + 'isResponsive' => true, | |
| 117 | + 'defaultValue' => 62, | |
| 118 | + 'hasUnit' => true, | |
| 119 | + 'unitDefaultValue' => 'px', | |
| 120 | + 'property' => 'width', | |
| 121 | + 'device' => $device, | |
| 122 | + ]), | |
| 123 | + ); | |
| 124 | + } | |
| 125 | + | |
| 126 | + public function get_title_css( $attributes, $device = '' ) { | |
| 127 | + $typographyValueGlobal = ! empty( $attributes['titleTypographyGlobal'] ) ? $attributes['titleTypographyGlobal'] : ''; | |
| 128 | + $typography_value = ! empty( $attributes['titleTypography'] ) ? | |
| 129 | + Typography::get_css( $attributes['titleTypography'], '', $device, $typographyValueGlobal ) | |
| 130 | + : array(); | |
| 131 | + | |
| 132 | + return array_merge( | |
| 133 | + [ 'color' => Color::get_css( isset( $attributes['titleColor'] ) ? $attributes['titleColor'] : '#999' ) ], | |
| 134 | + $typography_value, | |
| 135 | + ); | |
| 136 | + } | |
| 137 | + | |
| 138 | + public function get_title_hover_css( $attributes, $device = '' ) { | |
| 139 | + return array_merge( | |
| 140 | + [ 'color' => Color::get_css( isset( $attributes['titleColorH'] ) ? $attributes['titleColorH'] : '#999' ) ], | |
| 141 | + Range::get_css([ | |
| 142 | + 'attributeValue' => $attributes['titleTransition'], | |
| 143 | + 'attribute_object_key' => 'value', | |
| 144 | + 'isResponsive' => false, | |
| 145 | + 'defaultValue' => 0, | |
| 146 | + 'hasUnit' => false, | |
| 147 | + 'unitDefaultValue' => 's', | |
| 148 | + 'property' => 'transition-duration', | |
| 149 | + 'device' => $device, | |
| 150 | + ]), | |
| 151 | + ); | |
| 152 | + | |
| 153 | + } | |
| 154 | + | |
| 155 | + public function get_review_text_css( $attributes, $device = '' ) { | |
| 156 | + $typographyValueGlobal = ! empty( $attributes['textTypographyGlobal'] ) ? $attributes['textTypographyGlobal'] : ''; | |
| 157 | + $typography_value = ! empty( $attributes['textTypography'] ) ? | |
| 158 | + Typography::get_css( $attributes['textTypography'], '', $device, $typographyValueGlobal ) | |
| 159 | + : array(); | |
| 160 | + | |
| 161 | + return array_merge( | |
| 162 | + [ 'color' => Color::get_css( isset( $attributes['textColor'] ) ? $attributes['textColor'] : '#111' ) ], | |
| 163 | + $typography_value, | |
| 164 | + ); | |
| 165 | + } | |
| 166 | + | |
| 167 | + public function get_review_text_hover_css( $attributes, $device = '' ) { | |
| 168 | + return array_merge( | |
| 169 | + [ 'color' => Color::get_css( isset( $attributes['textColorH'] ) ? $attributes['textColorH'] : '#111' ) ], | |
| 170 | + Range::get_css([ | |
| 171 | + 'attributeValue' => $attributes['textTransition'], | |
| 172 | + 'attribute_object_key' => 'value', | |
| 173 | + 'isResponsive' => false, | |
| 174 | + 'defaultValue' => 0, | |
| 175 | + 'hasUnit' => false, | |
| 176 | + 'unitDefaultValue' => 's', | |
| 177 | + 'property' => 'transition-duration', | |
| 178 | + 'device' => $device, | |
| 179 | + ]), | |
| 180 | + ); | |
| 181 | + | |
| 182 | + } | |
| 183 | + public function get_review_icon_css( $attributes, $device = '' ) { | |
| 184 | + return array_merge( | |
| 185 | + [ 'color' => Color::get_css( isset( $attributes['star_color'] ) ? $attributes['star_color'] : '#f4c150' ) ], | |
| 186 | + Range::get_css([ | |
| 187 | + 'attributeValue' => $attributes['star_size'], | |
| 188 | + 'attribute_object_key' => 'value', | |
| 189 | + 'isResponsive' => true, | |
| 190 | + 'defaultValue' => 16, | |
| 191 | + 'hasUnit' => true, | |
| 192 | + 'unitDefaultValue' => 'px', | |
| 193 | + 'property' => 'font-size', | |
| 194 | + 'device' => $device, | |
| 195 | + ]), | |
| 196 | + ); | |
| 197 | + } | |
| 198 | + | |
| 199 | + public function get_review_icon_hover_css( $attributes, $device = '' ) { | |
| 200 | + return [ 'color' => Color::get_css( isset( $attributes['star_colorH'] ) ? $attributes['star_colorH'] : '#f4c150' ) ]; | |
| 201 | + } | |
| 202 | + public function get_instructor_css( $attributes, $device = '' ) { | |
| 203 | + $typographyValueGlobal = ! empty( $attributes['insTypographyGlobal'] ) ? $attributes['insTypographyGlobal'] : ''; | |
| 204 | + $typography_value = ! empty( $attributes['insTypography'] ) ? | |
| 205 | + Typography::get_css( $attributes['insTypography'], '', $device, $typographyValueGlobal ) | |
| 206 | + : array(); | |
| 207 | + return array_merge( | |
| 208 | + [ 'color' => Color::get_css( isset( $attributes['insColor'] ) ? $attributes['insColor'] : '#111' ) ], | |
| 209 | + $typography_value | |
| 210 | + ); | |
| 211 | + } | |
| 212 | + | |
| 213 | + public function get_instructor_hover_css( $attributes, $device = '' ) { | |
| 214 | + return [ 'color' => Color::get_css( isset( $attributes['insColorH'] ) ? $attributes['insColorH'] : '#111' ) ]; | |
| 215 | + } | |
| 216 | + | |
| 217 | + | |
| 218 | + public function render_block_content( $attributes, $content, $block_instance ) { | |
| 219 | + $attr_array = []; | |
| 220 | + | |
| 221 | + $shortcode = '[academy_course_instructors ' . Helper::attr_shortcode( $attr_array ) . ']'; | |
| 222 | + echo do_shortcode( $shortcode ); | |
| 223 | + } | |
| 224 | + | |
| 225 | +} | |