<?php
namespace App\Entity\Gos;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\Gos\FileRepository")
* @ORM\HasLifecycleCallbacks()
*/
class File
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\FileVersion", mappedBy="fileEntity", cascade={"persist"})
*/
private $versions;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $master_file_id;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Gos\ProductVariant", mappedBy="files")
*/
private $productVariants;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $fileLabel;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $url;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $playerCode;
public function __construct()
{
$this->versions = new ArrayCollection();
$this->productVariants = new ArrayCollection();
}
public function isVideo()
{
if (!is_null($this->getUrl()) || !is_null($this->getPlayerCode()))
{
return true;
}
return false;
}
public function __toString()
{
return $this->name;
}
/** @ORM\PrePersist() */
public function onPrePersist()
{
$this->createdAt = new \DateTime();
}
/** @ORM\PreUpdate() */
public function onPreUpdate()
{
$this->updatedAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection|FileVersion[]
*/
public function getVersions()
{
return $this->versions;
}
public function getVersionType($type): ?FileVersion
{
foreach ($this->getVersions() as $version)
{
if (strtolower($version->getLabel()) === strtolower($type))
{
return $version;
}
}
return null;
}
public function addVersion(FileVersion $version): self
{
if (!$this->versions->contains($version)) {
$this->versions[] = $version;
$version->setFileEntity($this);
}
return $this;
}
public function removeVersion(FileVersion $version): self
{
if ($this->versions->contains($version)) {
$this->versions->removeElement($version);
// set the owning side to null (unless already changed)
if ($version->getFileEntity() === $this) {
$version->setFileEntity(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function getMasterFileId()
{
return $this->master_file_id;
}
/**
* @param mixed $master_file_id
*/
public function setMasterFileId($master_file_id): void
{
$this->master_file_id = $master_file_id;
}
public function haveMasterFileId(){
return !($this->master_file_id == null);
}
public function setSpecyficVersions($vesrsions){
$this->versions = $vesrsions;
}
/**
* @return Collection|ProductVariant[]
*/
public function getProductVariants(): Collection
{
return $this->productVariants;
}
public function addProductVariant(ProductVariant $productVariant): self
{
if (!$this->productVariants->contains($productVariant)) {
$this->productVariants[] = $productVariant;
$productVariant->addFile($this);
}
return $this;
}
public function removeProductVariant(ProductVariant $productVariant): self
{
if ($this->productVariants->contains($productVariant)) {
$this->productVariants->removeElement($productVariant);
$productVariant->removeFile($this);
}
return $this;
}
public function getFileLabel(): ?string
{
return $this->fileLabel;
}
public function setFileLabel(?string $fileLabel): self
{
$this->fileLabel = $fileLabel;
return $this;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(?string $url): self
{
$this->url = $url;
return $this;
}
public function getPlayerCode(): ?string
{
return $this->playerCode;
}
public function setPlayerCode(?string $playerCode): self
{
$this->playerCode = $playerCode;
return $this;
}
}