<?php
namespace App\Entity\Media;
use App\Entity\Educational\Lesson\Exercise\ObjectExercise;
use App\Model\TimestampableTrait;
use Bo\DomainBundle\Entity\SubChapterDomain;
use Bo\MainBundle\Entity\Comment;
use Bo\MainBundle\Entity\PublishableTrait;
use Bo\MainBundle\Model\Publishable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Entity\Educational\SubChapterDomainVideo;
/**
* Bo\MediaBundle\Entity\Video
*
* @ORM\Table(name="Video")
* @ORM\Entity()
* @ORM\HasLifecycleCallbacks()
*/
class Video //implements WorkListTable
{
use TimestampableTrait;
//use HideableTrait;
const CONTENT_TYPE = 1;
const CONTENT_NAME = 'Video';
/**
* @var integer
*subChapterDomainsVideo
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/*
* @ORM\ManyToOne(targetEntity="\Bo\WorkListBundle\Entity\Notion", inversedBy="videos")
* @ORM\JoinColumn(name="notion_id", referencedColumnName="id")
*/
private $notion;
/**
* @var string
*
* @ORM\Column(name="filename", type="string", length=255,nullable=true)
*/
private $filename;
/**
* @var string $vimeoFile
*
* @ORM\Column(name="vimeo_file", type="string", length=255, nullable=true)
*/
private $vimeoFile;
/**
* @var string
*
* @ORM\Column(name="video_id", type="string", length=255, nullable=true)
*/
private $videoId;
/**
* @var string
*
* @ORM\Column(name="vimeo_id", type="string", length=255, nullable=true)
*/
private $vimeoId;
/**
* @var string
*
* @ORM\Column(name="picture", type="string", length=255, nullable=true)
*/
private $picture;
/**
* @var string $title
*
* @ORM\Column(name="title", type="string", length=255)
*
*/
private $title;
/**
* @var string $description
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @var string $description
*
* @ORM\Column(name="correction", type="text", nullable=true)
*/
private $correction;
/**
* @var string $description
*
* @ORM\Column(name="transcription", type="text", nullable=true)
*/
private $transcription;
/**
* @var integer $position
*
* @ORM\Column(name="position", type="integer",nullable=true)
*
*/
private $position;
/**
* @var integer $duration
*
* @ORM\Column(name="duration", type="integer",nullable=true)
*
*/
private $duration;
/**
* @var integer $poster
*
* @ORM\Column(name="poster", type="string", length=255, nullable=true)
*/
private $poster;
/**
* @var integer $pictureMobileId
*
* @ORM\Column(name="picture_mobile_id", type="integer", nullable=true)
*/
private $pictureMobileId;
/**
* @var boolean $visibleForAll
*
* @ORM\Column(name="visible_for_all", type="boolean")
*/
private $visibleForAll = false;
/**
* @var String $AnswersQuestion
* @ORM\Column(name="answers_question",type="text",nullable=true)
*/
private $AnswersQuestion;
/**
* @var String $Resume
* @ORM\Column(name="resume",type="text",nullable=true)
*/
private $resume;
/**
* @var string $title
*
* @ORM\Column(name="title_youtube", type="string", length=255,nullable=true)
*
*/
private $titleYoutube;
/**
* @var boolean
*
* @ORM\Column(type="boolean")
*/
private $published = false;
/**
* @var integer
*
* @ORM\Column(name="weight", type="integer", nullable=true, options={"unsigned"=true, "default"=0})
*/
private $weight;
/**
* @var string
*
* @ORM\Column(name="caption", type="text",nullable=true)
*
*/
private $caption;
/**
* @Gedmo\Slug(fields={"title","id"}, updatable=true)
* @ORM\Column(length=128, unique=true)
*/
private $slug;
/**
* @var
* @ORM\Column(name="duration_youtube", type="text",nullable=true)
*/
private $durationYoutube;
/**
* @var
* @ORM\Column(name="publish_date_youtube", type="text",nullable=true)
*/
private $publishDateYoutube;
/**
* @var string
* @ORM\Column(name="meta_description",type="string",length=255,nullable=true)
*/
private $metaDescription;
/**
* @var string
* @ORM\Column(name="transcript",type="string",nullable=true)
*/
private $transcript;
/**
* @var string
* @ORM\Column(name="transcript_auto",type="string",nullable=true)
*/
private $transcriptAuto;
private $transcriptFile;
/************************************************** Association ********************************************************/
/**
* @var $subchapters
* @ORM\OneToMany(targetEntity=SubChapterDomainVideo::class,mappedBy="video",cascade={"remove"})
*/
private $subChapterDomainsVideo;
/*
* @var $exercises
* @ORM\ManyToMany(targetEntity="\Bo\MediaBundle\Entity\Tags" , inversedBy="videos", cascade={"remove"})
* @ORM\JoinTable(name="lnk_video_tags")
*/
private $tags;
/*
* @var ArrayCollection
* @ORM\ManyToMany(targetEntity="Bo\MainBundle\Entity\Comment", cascade={"persist"})
* @ORM\OrderBy({"created" = "DESC"})
* @deprecated
*/
private $comments;
/**
* @var string $linkKumulus
*
* @ORM\Column(name="link_kumulus", type="string", length=255, nullable=true)
*/
private $linkKumulus;
/************************************************* Fin ***********************************************************/
/**
* Return all mobile pictures values
* NOTE : the index is the ID of the picture do note change or remove !
* @return array
*/
public static function getMobilePictures()
{
$mobilePictures = array_flip([
1 => 'Adeline-PC.png',
2 => 'Alain-HG.png',
3 => 'Alexandre-Anglais.png',
4 => 'Alexis-HG.png',
5 => 'Ana-espagnol.png',
6 => 'Anne-laure-Maths.png',
7 => 'Anne-Maths.png',
8 => 'Anne-Sophie-SVT.png',
9 => 'Antoine-Maths.png',
10 => 'Arnaud-HG.png',
11 => 'Benjamin-SVT.png',
12 => 'Benoit-Philo.png',
13 => 'Berenice-Francais.png',
14 => 'Bertrand-Maths.png',
15 => 'Camille-Allemand.png',
16 => 'Caroline-Francais.png',
17 => 'Cedric-Anglais.png',
18 => 'Cedric-Geopo.png',
19 => 'CharlotteB-Francais.png',
20 => 'CharlotteG-Francais.png',
21 => 'Damien-HG.png',
22 => 'Elodie-Francais.png',
23 => 'Emmanuel-Anglais.png',
24 => 'Francoise-Philo.png',
25 => 'Guillaume-PC.png',
26 => 'Hugo-HG.png',
27 => 'Jean-Francois-Maths.png',
28 => 'Joaquim-Espagnol.png',
29 => 'Juliette-Francais.png',
30 => 'Linda-PFEG.png',
31 => 'Marie-Anne-Maths.png',
32 => 'Marielle-Maths.png',
33 => 'Marie-PC.png',
34 => 'Maxime-SES.png',
35 => 'Melanie-Francais.png',
36 => 'Nolwenn-SES.png',
37 => 'Olivier-Maths.png',
38 => 'Ombeline-Anglais.png',
39 => 'Ophelie-SES.png',
40 => 'Pablo-SI.png',
41 => 'PierreB-PC.png',
42 => 'PierreS-Philo.png',
43 => 'Sarra-PC.png',
44 => 'Simon-PC.png',
45 => 'Sonia-Maths.png',
46 => 'Stephanie-SVT.png',
47 => 'Thomas-SVT.png',
48 => 'Valentine-FLE.png',
49 => 'Daphne-HG.png',
50 => 'Alexandra-Espagnol.png',
51 => 'Maud-Espagnol.png',
52 => 'Melanie-Anglais.png',
53 => 'Eudoxie-Maths.png',
54 => 'Helene-Geopo.png',
55 => 'CharlotteF-fr.png',
56 => 'Sandrine-SVT.png',
57 => 'Emilien-SVT.png',
58 => 'Pierre-Derrycke.jpg',
59 => 'Aure-Elise.jpg',
60 => 'Anais-Maths.png',
61 => 'Alexandra-Maths.png',
62 => 'Jean-Marie-Geopo.png',
63 => 'Maud-Français.png',
64 => 'Veronique-PC.png',
65 => 'Agnes-SVT.png',
66 => 'Betty-EMC.png',
67 => 'Guillaume-maths.png',
68 => 'Jeanne-HG.png',
69 => 'Miguel-SES.png',
70 => 'Francois-maths.png',
71 => 'Axel-LLCE.jpg',
72 => 'DamienL-Methode.png',
73 => 'Francky.png',
74 => 'Marion-SES.png',
]);
asort($mobilePictures);
return $mobilePictures;
}
/**
* Video constructor.
*/
public function __construct()
{
$this->subChapterDomainsVideo = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->comments = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @param $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return ArrayCollection
*/
public function getComments()
{
return $this->comments;
}
/**
* @param ArrayCollection $comments
*/
public function setComments(ArrayCollection $comments)
{
$this->comments = $comments;
}
/**
* @param Comment $comment
*/
public function addComment($comment)
{
if (!$this->comments->contains($comment)) {
$this->comments->add($comment);
}
}
/**
* @param Comment $comment
*/
public function removeComment($comment)
{
if ($this->comments->contains($comment)) {
$this->comments->removeElement($comment);
}
}
/**
* @return String
*/
public function getResume()
{
return $this->resume;
}
/**
* @param String $resume
*/
public function setResume($resume)
{
$this->resume = $resume;
}
/**
* @return mixed
*/
public function getSubChapterDomainsVideo()
{
return $this->subChapterDomainsVideo;
}
/**
* @param mixed $subChapterDomainsVideo
*/
public function setSubChapterDomainsVideo($subChapterDomainsVideo)
{
$this->subChapterDomainsVideo = $subChapterDomainsVideo;
}
/**
* @param mixed $subChapterDomainsVideo
*/
public function addSubChapterDomainsVideo($subChapterDomainsVideo)
{
$this->subChapterDomainsVideo[] = $subChapterDomainsVideo;
}
/**
* Set filename
*
* @param string $filename
*/
public function setFilename($filename)
{
$this->filename = $filename;
}
/**
* Get filename
*
* @param array $options
* @return string
*/
public function getFilename(array $options = array())
{
return $this->filename;
}
/**
* Set vimeoFile
*
* @param string $vimeoFile
*/
public function setVimeoFile($vimeoFile)
{
$this->vimeoFile = $vimeoFile;
}
/**
* Get vimeoFile
*
* @return string
*/
public function getVimeoFile()
{
return $this->vimeoFile;
}
public function getVideoMp4(array $options = array())
{
return $this->filename . '.mp4';
}
/**
* Set title
*
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set description
*
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set position
*
* @param integer $position
*/
public function setPosition($position)
{
$this->position = $position;
}
/**
* Get position
*
* @return integer
*/
public function getPosition()
{
return $this->position;
}
/**
* Set duration
*
* @param integer $duration
*/
public function setDuration($duration)
{
$this->duration = $duration;
}
/**
* Get duration
*
* @return integer
*/
public function getDuration()
{
return $this->duration;
}
/**
* Set poster
*
* @param string $poster
*/
public function setPoster($poster)
{
$this->poster = $poster;
}
/**
* Get poster
*
* @return string
*/
public function getPoster()
{
return $this->poster;
}
/**
* @return integer
*/
public function getPictureMobileId()
{
return $this->pictureMobileId;
}
/**
* @param integer $pictureMobileId
*/
public function setPictureMobileId($pictureMobileId)
{
$this->pictureMobileId = $pictureMobileId;
}
/**
* Set visibleForAll
*
* @param boolean $visibleForAll
*/
public function setVisibleForAll($visibleForAll)
{
$this->visibleForAll = $visibleForAll;
}
/**
* is visibleForAll
*
* @return boolean
*/
public function isVisibleForAll()
{
return $this->visibleForAll;
}
/**
* Return human friendly duration
* @return string
*/
public function getHumanDuration()
{
$duration = $this->getDuration();
$format = '%d:%s';
$minutes = 0;
$seconds = 0;
if ($duration < 60) {
$seconds = $duration;
} else {
$seconds = floor($duration % 60);
$minutes = floor($duration / 60);
}
$seconds = $seconds > 9 ? $seconds : '0' . $seconds;
return sprintf($format, $minutes, $seconds);
}
public function __toString()
{
return $this->getTitle();
}
/**
* @return String
*/
public function getAnswersQuestion()
{
return $this->AnswersQuestion;
}
/**
* @param String $AnswersQuestion
*/
public function setAnswersQuestion($AnswersQuestion)
{
$this->AnswersQuestion = $AnswersQuestion;
}
/**
* @return string
*/
public function getVideoId()
{
return $this->videoId;
}
/**
* @param string $videoId
*/
public function setVideoId($videoId)
{
$this->videoId = $videoId;
}
/**
* @return string
*/
public function getVimeoId(): ?string
{
return $this->vimeoId;
}
/**
* @param string $vimeoId
*/
public function setVimeoId(string $vimeoId): void
{
$this->vimeoId = $vimeoId;
}
/**
* @return string
*/
public function getPicture()
{
return $this->picture;
}
/**
* @param string $picture
*/
public function setPicture($picture)
{
$this->picture = $picture;
}
/**
* @return boolean
*/
public function isPublished()
{
return $this->published;
}
/**
* @param boolean $published
*/
public function setPublished($published)
{
$this->published = $published;
}
/**
* @return int
*/
public function getWeight()
{
return $this->weight;
}
/**
* @param int $weight
*/
public function setWeight($weight)
{
$this->weight = $weight;
}
/**
* @return string
*/
public function getCaption()
{
return $this->caption;
}
/**
* @param string $caption
*/
public function setCaption($caption)
{
$this->caption = $caption;
}
/**
* @return mixed
*/
public function getSlug()
{
return $this->slug;
}
/**
* @param mixed $slug
*/
public function setSlug($slug)
{
$this->slug = $slug;
}
/**
* @return HomeWork
*/
public function getExercises()
{
return $this->exercises;
}
/**
* @param HomeWork $exercises
*/
public function setExercises($exercises)
{
$this->exercises = $exercises;
}
/**
* @param HomeWork $exercises
*/
public function addExercises($exercises)
{
$this->exercises[] = $exercises;
}
public function hasExercises()
{
return 0 < count($this->exercises);
}
/**
* @return string
*/
public function getTitleYoutube()
{
return $this->titleYoutube;
}
/**
* @param string $titleYoutube
*/
public function setTitleYoutube($titleYoutube)
{
$this->titleYoutube = $titleYoutube;
}
/**
* @return mixed
*/
public function getNotion()
{
return $this->notion;
}
/**
* @param mixed $notion
*/
public function setNotion($notion)
{
$this->notion = $notion;
}
/**
* @return mixed
*/
public function getTags()
{
return $this->tags;
}
/**
* @param mixed $tags
*/
public function setTags($tags)
{
$this->tags = $tags;
}
/**
* @param mixed $tags
*/
public function addTags($tags)
{
$verif = false;
if (!$this->tags->isEmpty()) {
foreach ($this->tags as $tmp) {
if ($tmp->getId() == $tags->getId()) {
$verif = true;
}
}
}
if (!$verif) {
$this->tags[] = $tags;
$tags->addVideo($this);
}
}
public function isSubDomainChapter($idSubchapter)
{
foreach ($this->getSubChapterDomains() as $gsd) {
if ($gsd->getId() == $idSubchapter) {
return true;
}
}
return false;
}
/**
* @return mixed
*/
public function getDurationYoutube()
{
if ($this->durationYoutube != '') {
return $this->durationYoutube;
} else {
return ' n/a ';
}
}
/**
* @param mixed $durationYoutube
*/
public function setDurationYoutube($durationYoutube)
{
$this->durationYoutube = $durationYoutube;
}
/**
* @return mixed
*/
public function getPublishDateYoutube()
{
return $this->publishDateYoutube;
}
/**
* @param mixed $publishDateYoutube
*/
public function setPublishDateYoutube($publishDateYoutube)
{
$this->publishDateYoutube = $publishDateYoutube;
}
/* public function getVideoSubchapterDomainByDomainId($domainId)
{
if(empty($this->subChapterDomains) || empty($domainId))
{
return array();
}
foreach($this->subChapterDomains as $sub)
{
if($sub->getDomain()->getId() == $domainId)
{
return $sub->getVideos();
}
}
}
*/
/********************** Interface *************************/
public function getTypeWI()
{
// TODO: Implement getTypeWI() method.
}
public function getTitleWI()
{
// TODO: Implement getTitleWI() method.
}
/**
* Get visibleForAll
*
* @return boolean
*/
public function getVisibleForAll()
{
return $this->visibleForAll;
}
/**
* Get published
*
* @return boolean
*/
public function getPublished()
{
return $this->published;
}
/**
* Add exercises
*
* @param \Bo\ExerciseBundle\Entity\ObjectExercise $exercises
* @return Video
*/
public function addExercise(ObjectExercise $exercises)
{
$this->exercises[] = $exercises;
return $this;
}
/**
* Remove exercises
*
* @param \Bo\ExerciseBundle\Entity\ObjectExercise $exercises
*/
public function removeExercise(ObjectExercise $exercises)
{
$this->exercises->removeElement($exercises);
}
/**
* Add tags
*
* @param \Bo\MediaBundle\Entity\Tags $tags
* @return Video
*/
public function addTag( $tags)
{
$this->tags[] = $tags;
return $this;
}
/**
* Remove tags
*
* @param \Bo\MediaBundle\Entity\Tags $tags
*/
public function removeTag($tags)
{
$this->tags->removeElement($tags);
}
public function getMinutes()
{
return ceil($this->duration / 60);
}
/**
* @return string
*/
public function getMetaDescription()
{
return $this->metaDescription;
}
/**
* @param string $metaDescription
*/
public function setMetaDescription($metaDescription)
{
$this->metaDescription = $metaDescription;
}
public function getMaxResPicture()
{
if (!$this->getVideoId()) {
return $this->getPicture();
}
return 'https://i.ytimg.com/vi/' . $this->getVideoId() . '/maxresdefault.jpg';
}
public function getMQPicture()
{
if (!$this->getVideoId()) {
return $this->getPicture();
}
return 'https://i.ytimg.com/vi/' . $this->getVideoId() . '/mqdefault.jpg';
}
/**
* @return mixed
*/
public function getActor()
{
return $this->actor;
}
/**
* @param mixed $actor
*/
public function setActor($actor)
{
$this->actor = $actor;
}
/**
* @return string
*/
public function getTranscript()
{
return $this->transcript;
}
/**
* @param ?string $transcript
*/
public function setTranscript(?string $transcript): void
{
$this->transcript = $transcript;
}
/**
* @return mixed
*/
public function getTranscriptFile()
{
return $this->transcriptFile;
}
/**
* @param mixed $transcriptFile
*/
public function setTranscriptFile($transcriptFile): void
{
$this->transcriptFile = $transcriptFile;
}
public function getAbsolutePath()
{
return null === $this->transcript ? null : sprintf("%s/%s", $this->getUploadRootDir(), $this->transcript);
}
public function getWebPath()
{
return null === $this->transcript ? null : sprintf("/%s/%s", $this->getUploadDir(), $this->transcript);
}
protected function getUploadRootDir()
{
// le chemin absolu du répertoire où les documents uploadés doivent être sauvegardés
return __DIR__ . '/../../../../public/' . $this->getUploadDir();
}
protected function getUploadDir()
{
// on se débarrasse de « __DIR__ » afin de ne pas avoir de problème lorsqu'on affiche
// le document/image dans la vue.
return 'gatewayImages/front/videos/transcripts/';
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function PreUpdate()
{
if (null !== $this->transcriptFile) {
$this->transcript = sha1(uniqid(mt_rand(), true)) . '.' . $this->transcriptFile->guessExtension();
}
}
/**
* @ORM\PostPersist
* @ORM\PostUpdate
*/
public function PostUpdate()
{
if (null === $this->transcriptFile) {
return;
}
// s'il y a une erreur lors du déplacement du fichier, une exception
// va automatiquement être lancée par la méthode move(). Cela va empêcher
// proprement l'entité d'être persistée dans la base de données si
// erreur il y a
if (!is_dir($this->getUploadRootDir())) {
mkdir($this->getUploadRootDir(), '0777', true);
}
$this->transcriptFile->move($this->getUploadRootDir(), $this->transcript);
unset($this->transcriptFile);
}
/**
* @return mixed
*/
public function __toArray()
{
$data['id'] = $this->getId();
$data['title'] = $this->getTitle();
$data['description'] = str_replace(array('.', "\n", "\t", "\r"), '',strip_tags(html_entity_decode($this->getDescription())));
$data['resume'] = str_replace(array('.', "\n", "\t", "\r"), '',strip_tags(html_entity_decode($this->getResume())));
$data['poster'] = $this->getPoster() ? $this->getPoster() : $this->getPicture();
$data['slug'] = $this->getSlug();
return $data;
}
/**
* @return string
*/
public function getLinkKumulus()
{
return $this->linkKumulus;
}
/**
* @param string $linkKumulus
*/
public function setLinkKumulus($linkKumulus)
{
$this->linkKumulus = $linkKumulus;
}
public function getTranscriptAuto()
{
return $this->transcriptAuto;
}
public function setTranscriptAuto($transcriptAuto): void
{
$this->transcriptAuto = $transcriptAuto;
}
public function getCorrection(): ?string
{
return $this->correction;
}
public function setCorrection(string $correction): void
{
$this->correction = $correction;
}
public function getTranscription(): ?string
{
return $this->transcription;
}
public function setTranscription(string $transcription): void
{
$this->transcription = $transcription;
}
}