src/Entity/WinWOP/File/Documentation.php line 18

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2019, MND Next GmbH - www.mndnext.de
  4.  */
  5. namespace App\Entity\WinWOP\File;
  6. use App\Entity\WinWOP\Update;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. /**
  11.  * @ORM\Entity
  12.  * @ORM\Table(name="winwop_docu_files")
  13.  * @Vich\Uploadable
  14.  */
  15. class Documentation
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\Column(type="integer")
  20.      * @ORM\GeneratedValue(strategy="AUTO")
  21.      */
  22.     private $id;
  23.     /**
  24.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  25.      *
  26.      * @Vich\UploadableField(mapping="update_documentation", fileNameProperty="localName", size="size", originalName="originalName", mimeType="mimeType")
  27.      *
  28.      * @var File
  29.      */
  30.     private $file;
  31.     /**
  32.      * @ORM\Column(type="string", length=190)
  33.      *
  34.      * @var string
  35.      */
  36.     private $name;
  37.     /**
  38.      * @ORM\Column(type="string", length=190)
  39.      *
  40.      * @var string
  41.      */
  42.     private $localName;
  43.     /**
  44.      * @ORM\Column(type="string", length=190)
  45.      *
  46.      * @var string
  47.      */
  48.     private $originalName;
  49.     /**
  50.      * @ORM\Column(type="integer")
  51.      *
  52.      * @var integer
  53.      */
  54.     private $size;
  55.     /**
  56.      * @ORM\Column(type="string", length=190)
  57.      *
  58.      * @var string
  59.      */
  60.     private $mimeType;
  61.     /**
  62.      * @ORM\Column(type="datetime")
  63.      *
  64.      * @var \DateTime
  65.      */
  66.     private $created;
  67.     /**
  68.      * @ORM\ManyToOne(targetEntity="App\Entity\WinWOP\Update", inversedBy="docuFiles", cascade={"persist"})
  69.      * @ORM\JoinColumn(name="winwop_version", referencedColumnName="version")
  70.      */
  71.     private $winwop;
  72.     public function getId()
  73.     {
  74.         return $this->id;
  75.     }
  76.     /**
  77.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  78.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  79.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  80.      * must be able to accept an instance of 'File' as the bundle will inject one here
  81.      * during Doctrine hydration.
  82.      *
  83.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $file
  84.      * @throws \Exception
  85.      */
  86.     public function setFile(?File $file null): void
  87.     {
  88.         $this->file $file;
  89.         if (null !== $file) {
  90.             // It is required that at least one field changes if you are using doctrine
  91.             // otherwise the event listeners won't be called and the file is lost
  92.             $this->created = new \DateTimeImmutable();
  93.         }
  94.     }
  95.     public function getFile(): ?File
  96.     {
  97.         return $this->file;
  98.     }
  99.     public function setName(?string $name): void
  100.     {
  101.         $this->name $name;
  102.     }
  103.     public function getName(): ?string
  104.     {
  105.         return $this->name;
  106.     }
  107.     public function setLocalName(?string $localName): void
  108.     {
  109.         $this->localName $localName;
  110.     }
  111.     public function getLocalName(): ?string
  112.     {
  113.         return $this->localName;
  114.     }
  115.     public function setOriginalName(?string $name): void
  116.     {
  117.         $this->originalName $name;
  118.     }
  119.     public function getOriginalName(): ?string
  120.     {
  121.         return $this->originalName;
  122.     }
  123.     public function setSize(?int $size): void
  124.     {
  125.         $this->size $size;
  126.     }
  127.     public function getSize(): ?int
  128.     {
  129.         return $this->size;
  130.     }
  131.     function getFormattedSize()
  132.     {
  133.         $units = array( 'B''KB''MB''GB''TB''PB''EB''ZB''YB');
  134.         $power $this->size floor(log($this->size1024)) : 0;
  135.         return number_format($this->size pow(1024$power), 2'.'',') . ' ' $units[$power];
  136.     }
  137.     public function setMimeType(?string $mimeType): void
  138.     {
  139.         $this->mimeType $mimeType;
  140.     }
  141.     public function getMimeType(): ?string
  142.     {
  143.         return $this->mimeType;
  144.     }
  145.     public function setWinWOP(Update $update null): void
  146.     {
  147.         $this->winwop $update;
  148.     }
  149.     public function getWinWOP() : ?Update
  150.     {
  151.         return $this->winwop;
  152.     }
  153.     public function getCreated(): ?\DateTime
  154.     {
  155.         return $this->created;
  156.     }
  157.     public function __toString()
  158.     {
  159.         return $this->getName();
  160.     }
  161. }