src/Entity/Gos/File.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\Gos\FileRepository")
  8.  * @ORM\HasLifecycleCallbacks()
  9.  */
  10. class File
  11. {
  12.     /**
  13.      * @ORM\Id()
  14.      * @ORM\GeneratedValue()
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\Column(type="text", nullable=true)
  24.      */
  25.     private $description;
  26.     /**
  27.      * @ORM\Column(type="datetime")
  28.      */
  29.     private $createdAt;
  30.     /**
  31.      * @ORM\Column(type="datetime", nullable=true)
  32.      */
  33.     private $updatedAt;
  34.     /**
  35.      * @ORM\OneToMany(targetEntity="App\Entity\Gos\FileVersion", mappedBy="fileEntity", cascade={"persist"})
  36.      */
  37.     private $versions;
  38.     /**
  39.      * @ORM\Column(type="string", length=255, nullable=true)
  40.      */
  41.     private $master_file_id;
  42.     /**
  43.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\ProductVariant", mappedBy="files")
  44.      */
  45.     private $productVariants;
  46.     /**
  47.      * @ORM\Column(type="string", length=255, nullable=true)
  48.      */
  49.     private $fileLabel;
  50.     /**
  51.      * @ORM\Column(type="string", length=255, nullable=true)
  52.      */
  53.     private $url;
  54.     /**
  55.      * @ORM\Column(type="text", nullable=true)
  56.      */
  57.     private $playerCode;
  58.     public function __construct()
  59.     {
  60.         $this->versions = new ArrayCollection();
  61.         $this->productVariants = new ArrayCollection();
  62.     }
  63.     public function isVideo()
  64.     {
  65.         if (!is_null($this->getUrl()) || !is_null($this->getPlayerCode()))
  66.         {
  67.             return true;
  68.         }
  69.         return false;
  70.     }
  71.     public function __toString()
  72.     {
  73.         return $this->name;
  74.     }
  75.     /** @ORM\PrePersist() */
  76.     public function onPrePersist()
  77.     {
  78.         $this->createdAt = new \DateTime();
  79.     }
  80.     /** @ORM\PreUpdate() */
  81.     public function onPreUpdate()
  82.     {
  83.         $this->updatedAt = new \DateTime();
  84.     }
  85.     public function getId(): ?int
  86.     {
  87.         return $this->id;
  88.     }
  89.     public function getName(): ?string
  90.     {
  91.         return $this->name;
  92.     }
  93.     public function setName(string $name): self
  94.     {
  95.         $this->name $name;
  96.         return $this;
  97.     }
  98.     public function getDescription(): ?string
  99.     {
  100.         return $this->description;
  101.     }
  102.     public function setDescription(?string $description): self
  103.     {
  104.         $this->description $description;
  105.         return $this;
  106.     }
  107.     public function getCreatedAt(): ?\DateTimeInterface
  108.     {
  109.         return $this->createdAt;
  110.     }
  111.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  112.     {
  113.         $this->createdAt $createdAt;
  114.         return $this;
  115.     }
  116.     public function getUpdatedAt(): ?\DateTimeInterface
  117.     {
  118.         return $this->updatedAt;
  119.     }
  120.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  121.     {
  122.         $this->updatedAt $updatedAt;
  123.         return $this;
  124.     }
  125.     /**
  126.      * @return Collection|FileVersion[]
  127.      */
  128.     public function getVersions()
  129.     {
  130.         return $this->versions;
  131.     }
  132.     public function getVersionType($type): ?FileVersion
  133.     {
  134.         foreach ($this->getVersions() as $version)
  135.         {
  136.             if (strtolower($version->getLabel()) === strtolower($type))
  137.             {
  138.                 return $version;
  139.             }
  140.         }
  141.         return null;
  142.     }
  143.     public function addVersion(FileVersion $version): self
  144.     {
  145.         if (!$this->versions->contains($version)) {
  146.             $this->versions[] = $version;
  147.             $version->setFileEntity($this);
  148.         }
  149.         return $this;
  150.     }
  151.     public function removeVersion(FileVersion $version): self
  152.     {
  153.         if ($this->versions->contains($version)) {
  154.             $this->versions->removeElement($version);
  155.             // set the owning side to null (unless already changed)
  156.             if ($version->getFileEntity() === $this) {
  157.                 $version->setFileEntity(null);
  158.             }
  159.         }
  160.         return $this;
  161.     }
  162.     /**
  163.      * @return mixed
  164.      */
  165.     public function getMasterFileId()
  166.     {
  167.         return $this->master_file_id;
  168.     }
  169.     /**
  170.      * @param mixed $master_file_id
  171.      */
  172.     public function setMasterFileId($master_file_id): void
  173.     {
  174.         $this->master_file_id $master_file_id;
  175.     }
  176.     public function haveMasterFileId(){
  177.         return !($this->master_file_id == null);
  178.     }
  179.     public function setSpecyficVersions($vesrsions){
  180.         $this->versions $vesrsions;
  181.     }
  182.     /**
  183.      * @return Collection|ProductVariant[]
  184.      */
  185.     public function getProductVariants(): Collection
  186.     {
  187.         return $this->productVariants;
  188.     }
  189.     public function addProductVariant(ProductVariant $productVariant): self
  190.     {
  191.         if (!$this->productVariants->contains($productVariant)) {
  192.             $this->productVariants[] = $productVariant;
  193.             $productVariant->addFile($this);
  194.         }
  195.         return $this;
  196.     }
  197.     public function removeProductVariant(ProductVariant $productVariant): self
  198.     {
  199.         if ($this->productVariants->contains($productVariant)) {
  200.             $this->productVariants->removeElement($productVariant);
  201.             $productVariant->removeFile($this);
  202.         }
  203.         return $this;
  204.     }
  205.     public function getFileLabel(): ?string
  206.     {
  207.         return $this->fileLabel;
  208.     }
  209.     public function setFileLabel(?string $fileLabel): self
  210.     {
  211.         $this->fileLabel $fileLabel;
  212.         return $this;
  213.     }
  214.     public function getUrl(): ?string
  215.     {
  216.         return $this->url;
  217.     }
  218.     public function setUrl(?string $url): self
  219.     {
  220.         $this->url $url;
  221.         return $this;
  222.     }
  223.     public function getPlayerCode(): ?string
  224.     {
  225.         return $this->playerCode;
  226.     }
  227.     public function setPlayerCode(?string $playerCode): self
  228.     {
  229.         $this->playerCode $playerCode;
  230.         return $this;
  231.     }
  232. }