Background.php
1 year ago
BackgroundDefaults.php
2 years ago
BackgroundImage.php
1 year ago
BackgroundOverlay.php
1 year ago
BackgroundSlideshow.php
1 year ago
BackgroundVideo.php
1 year ago
BackgroundSlideshow.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\Core\Background; |
| 4 | |
| 5 | use Kubio\Core\Element; |
| 6 | use Kubio\Core\ElementBase; |
| 7 | use Kubio\Core\LodashBasic; |
| 8 | use Kubio\Core\StyleManager\ParserUtils; |
| 9 | use Kubio\Core\Utils; |
| 10 | |
| 11 | use function array_merge; |
| 12 | |
| 13 | class BackgroundSlideshow extends ElementBase { |
| 14 | |
| 15 | function __construct( $value ) { |
| 16 | parent::__construct( $value, BackgroundDefaults::getDefaultSlideShow() ); |
| 17 | } |
| 18 | |
| 19 | function getMergedValue() { |
| 20 | if ( ! $this->_merged ) { |
| 21 | $this->_merged = LodashBasic::mergeSkipSeqArray( $this->default, $this->value ); |
| 22 | } |
| 23 | return $this->_merged; |
| 24 | } |
| 25 | |
| 26 | |
| 27 | function __toString() { |
| 28 | $slides = $this->get( 'slides' ); |
| 29 | $duration_str = ParserUtils::toValueUnitString( $this->get( 'duration' ) ); |
| 30 | $speed_str = ParserUtils::toValueUnitString( $this->get( 'speed' ) ); |
| 31 | |
| 32 | $slides_els = array(); |
| 33 | |
| 34 | foreach ( $slides as $index => $slide ) { |
| 35 | $slides_els[] = new Element( |
| 36 | Element::DIV, |
| 37 | array( |
| 38 | 'style' => $this->getSlideStyle( $slide, $index ), |
| 39 | 'className' => array( 'slideshow-image' ), |
| 40 | ) |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | $slideshow = Utils::useJSComponentProps( |
| 45 | 'slideshow', |
| 46 | array( |
| 47 | 'duration' => $duration_str, |
| 48 | 'speed' => $speed_str, |
| 49 | ) |
| 50 | ); |
| 51 | return new Element( |
| 52 | Element::DIV, |
| 53 | array_merge( |
| 54 | $slideshow, |
| 55 | array( |
| 56 | 'className' => array( |
| 57 | 'background-layer', |
| 58 | 'kubio-slideshow', |
| 59 | ), |
| 60 | ) |
| 61 | ), |
| 62 | $slides_els |
| 63 | ) . ''; |
| 64 | } |
| 65 | |
| 66 | function getSlideStyle( $slide, $index ) { |
| 67 | $url = $slide['url']; |
| 68 | $url = kubio_wpml_get_translated_media_url( $url ); |
| 69 | $style = array( |
| 70 | 'backgroundImage' => "url(\"$url\")", |
| 71 | 'zIndex' => $index, |
| 72 | ); |
| 73 | return $style; |
| 74 | } |
| 75 | } |
| 76 |