| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Elements; |
| 3 |
|
| 4 |
use Averta\Core\Utility\Arr; |
| 5 |
use Depicter; |
| 6 |
use Depicter\Document\Models; |
| 7 |
use Depicter\Html\Html; |
| 8 |
use Depicter\Services\MediaBridge; |
| 9 |
|
| 10 |
class Video extends Models\Element |
| 11 |
{ |
| 12 |
|
| 13 |
public function render() { |
| 14 |
|
| 15 |
if ( empty( $this->options->source ) ) { |
| 16 |
return ''; |
| 17 |
} |
| 18 |
|
| 19 |
$elementsAttrs = []; |
| 20 |
|
| 21 |
if( isset( $this->options->autoPlay ) ){ |
| 22 |
$elementsAttrs['data-autoplay'] = $this->options->autoPlay ? "true" : "false"; |
| 23 |
} |
| 24 |
if( isset( $this->options->autoPause ) ){ |
| 25 |
$elementsAttrs['data-auto-pause'] = $this->options->autoPause ? "true" : "false"; |
| 26 |
} |
| 27 |
|
| 28 |
if( isset( $this->options->goNextSection ) ){ |
| 29 |
$elementsAttrs['data-goto-next'] = $this->options->goNextSection ? "true" : "false"; |
| 30 |
} |
| 31 |
if( isset( $this->options->loop ) ){ |
| 32 |
$elementsAttrs['data-loop'] = $this->options->loop ? "true" : "false"; |
| 33 |
} else { |
| 34 |
$elementsAttrs['data-loop'] = "true"; |
| 35 |
} |
| 36 |
|
| 37 |
$videoAttrs = [ |
| 38 |
'src' => Depicter::media()->getSourceUrl( $this->options->source ), |
| 39 |
'preload' => 'metadata' |
| 40 |
]; |
| 41 |
|
| 42 |
if( !empty( $this->options->controls ) ){ |
| 43 |
$videoAttrs['controls'] = ""; |
| 44 |
} |
| 45 |
if( !empty( $this->options->mute ) ){ |
| 46 |
$videoAttrs['muted'] = ""; |
| 47 |
} |
| 48 |
|
| 49 |
$elementsAttrs = Arr::merge( $this->getDefaultAttributes(), $elementsAttrs ); |
| 50 |
if ( isset( $elementsAttrs['data-height'] ) ) { |
| 51 |
$elementsAttrs['data-height'] = 'auto,,'; |
| 52 |
} |
| 53 |
|
| 54 |
$div = Html::div( $elementsAttrs ); |
| 55 |
|
| 56 |
$video = "\n\t" . Html::video( $videoAttrs ) . "\n"; |
| 57 |
|
| 58 |
if ( false !== $a = $this->getLinkTag() ) { |
| 59 |
return $a->nest( $div->nest( $video ) ); |
| 60 |
} |
| 61 |
|
| 62 |
return $div->nest( $video ) . "\n"; |
| 63 |
} |
| 64 |
} |
| 65 |
|