<?php

if ( ! defined( 'ABSPATH' ) ) exit;

require_once "DigitalSignage4_Entity.php";

class DigitalSignage4_DemandeEntity extends DigitalSignage4_Entity
{
    private $id_demande = null;
    private $data = null;
    private $AE_version = null;
    private $flag = null;
    private $video_comment = "";
    private $video_name = "";
    private $date_begin = null;
    private $automatique = null;
    private $date_end = null;
    private $date_demande = null;
    private $gabarit = null;
    private $product_id = null;
    private $downloaded = null;
    private $video_url = null;
    private $video_hash = null;
    private $video_deleted = null;
    private $youtube_data = null;
    private $youtube_id = null;


    /**
     * @return null
     */
    public function getIdDemande()
    {
        return $this->id_demande;
    }

    /**
     * @param $id_demande
     * @return DigitalSignage4_DemandeEntity
     */
    public function setIdDemande($id_demande)
    {
        $this->id_demande = $id_demande;
        return $this;
    }

    /**
     * @return null
     */
    public function getData()
    {
        return $this->data;
    }

    /**
     * @param $data
     * @return DigitalSignage4_DemandeEntity
     */
    public function setData($data)
    {
        $this->data = $data;
        return $this;
    }


    public function getYoutubeId()
    {
        return $this->youtube_id;
    }
    public function setYoutubeId($data)
    {
        $this->youtube_id = $data;
        return $this;
    }

    public function getYoutubeData()
    {
        //return stripslashes($this->youtube_data);
        return $this->youtube_data;
    }
    public function setYoutubeData($data)
    {
        $this->youtube_data = $data;
        return $this;
    }



    /**
     * @return null
     */
    public function getAEVersion()
    {
        return $this->AE_version;
    }

    /**
     * @param $AE_version
     * @return DigitalSignage4_DemandeEntity
     */
    public function setAEVersion($AE_version)
    {
        $this->AE_version = $AE_version;
        return $this;
    }

    /**
     * @return null
     */
    public function getFlag()
    {
        return $this->flag;
    }

    /**
     * @param $flag
     * @return DigitalSignage4_DemandeEntity
     */
    public function setFlag($flag)
    {
        $this->flag = $flag;
        return $this;
    }

    /**
     * @return null
     */
    public function getVideoComment()
    {
        return $this->video_comment;
    }

    /**
     * @param $video_comment
     * @return DigitalSignage4_DemandeEntity
     */
    public function setVideoComment($video_comment)
    {
        $this->video_comment = $video_comment;
        return $this;
    }

    /**
     * @return null
     */
    public function getVideoName()
    {
        return $this->video_name;
    }

    /**
     * @param $video_name
     * @return DigitalSignage4_DemandeEntity
     */
    public function setVideoName($video_name)
    {
        $this->video_name = $video_name;
        return $this;
    }

    /**
     * @return null
     */
    public function getDateBegin()
    {
        return $this->date_begin;
    }

    /**
     * @param $date_begin
     * @return DigitalSignage4_DemandeEntity
     */
    public function setDateBegin($date_begin)
    {
        $this->date_begin = $date_begin;
        return $this;
    }

    /**
     * @return null
     */
    public function getAutomatique()
    {
        return $this->automatique;
    }

    /**
     * @param $automatique
     * @return DigitalSignage4_DemandeEntity
     */
    public function setAutomatique($automatique)
    {
        $this->automatique = $automatique;
        return $this;
    }

    /**
     * @return null
     */
    public function getDateEnd()
    {
        return $this->date_end;
    }

    /**
     * @param $date_end
     * @return DigitalSignage4_DemandeEntity
     */
    public function setDateEnd($date_end)
    {
        $this->date_end = $date_end;
        return $this;
    }

    /**
     * @return null
     */
    public function getDateDemande()
    {
        return $this->date_demande;
    }

    /**
     * @param $date_demande
     * @return DigitalSignage4_DemandeEntity
     */
    public function setDateDemande($date_demande)
    {
        $this->date_demande = $date_demande;
        return $this;
    }

    /**
     * @return null
     */
    public function getGabarit()
    {
        return $this->gabarit;
    }

    /**
     * @param $gabarit
     * @return DigitalSignage4_DemandeEntity
     */
    public function setGabarit($gabarit)
    {
        $this->gabarit = $gabarit;
        return $this;
    }

    /**
     * @return null
     */
    public function getProductId()
    {
        return $this->product_id;
    }

    /**
     * @param $product_id
     * @return DigitalSignage4_DemandeEntity
     */
    public function setProductId($product_id)
    {
        $this->product_id = $product_id;
        return $this;
    }

    /**
     * @return null
     */
    public function getDownloaded()
    {
        return $this->downloaded;
    }

    /**
     * @param $downloaded
     * @return DigitalSignage4_DemandeEntity
     */
    public function setDownloaded($downloaded)
    {
        $this->downloaded = $downloaded;
        return $this;
    }

    /**
     * @return null
     */
    public function getVideoUrl()
    {
        return $this->video_url;
    }

    public function getVideoUrlOgv()
    {
        return str_replace(".mp4", ".ogv", $this->video_url);
    }

    /**
     * @param $video_url
     * @return DigitalSignage4_DemandeEntity
     */
    public function setVideoUrl($video_url)
    {
        $this->video_url = $video_url;
        return $this;
    }

    /**
     * @return null
     */
    public function getVideoHash()
    {
        return $this->video_hash;
    }

    /**
     * @param $video_hash
     * @return DigitalSignage4_DemandeEntity
     */
    public function setVideoHash($video_hash)
    {
        $this->video_hash = $video_hash;
        return $this;
    }

    /**
     * @return null
     */
    public function getVideoDeleted()
    {
        return $this->video_deleted;
    }

    /**
     * @param $video_deleted
     * @return DigitalSignage4_DemandeEntity
     */
    public function setVideoDeleted($video_deleted)
    {
        $this->video_deleted = $video_deleted;
        return $this;
    }

    public function getVideoPlayer($width='width: 200.25px', $height='height: 100px', $loop='0', $autoplay='0',$no_decalage=false)
    {
        $retour="";

        $css="";
        //il va falloir selon le gabarit retrouver le format
        if ($this->getGabarit()->getOrientation()==1) {
            //mode paysage width:100%;aspect-ratio:16/9; pour les vidéos horizontales
            $css="width:100%;aspect-ratio:16/9;";
        } else {
            //portrait heigfht:100%;aspect-ratio:9/16; pour les vidéos verticales
            $css="height:100%;aspect-ratio:9/16;";
        }
		
        if ($no_decalage) {
            //$css2='top:0;left:50%;';
            $css2='top:0;';
        } else {
            //$css2='position:absolute;top:0;left:50%;transform:translateX(-50%);';
            $css2='position:absolute;top:0;transform:translateX(-50%);';
        }
		
        $id_video = $this->getYoutubeId();
        if (($id_video!='') && ($id_video!='-1')) {
            $retour="<object  type='video/mp4'
  style='".$css2."max-width:100%;max-height:100%;".$css."' 
  data='https://www.youtube.com/embed/".$id_video."?autoplay=".$autoplay."&mute=1&loop=".$loop."&playlist=".$id_video."&rel=0' name='".$this->getIdDemande()."'>
</object>";
        } else {
            $retour="<video style='".$css2."max-width:100%;max-height:100%;".$css."' controls muted='muted' preload='auto' loop autoplay>
                                                <source src='".$this->getVideoUrl()."' type='video/mp4'></video>";
        }

        return $retour;
    }
}
