src/Entity/ModuleTest/Attachment.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\ModuleTest;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use EightMarq\CoreComponent\Entity\BaseEntity;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. /**
  12.  * @ORM\Table(name="attchments")
  13.  * @ORM\Entity()
  14.  *
  15.  * @Vich\Uploadable()
  16.  */
  17. class Attachment extends BaseEntity
  18. {
  19.     /**
  20.      * @var string|null
  21.      *
  22.      * @ORM\Column(type="string", length=255)
  23.      */
  24.     protected $attachment;
  25.     /**
  26.      * @Vich\UploadableField(
  27.      *     mapping="module_tests_attachments",
  28.      *     fileNameProperty="attachment",
  29.      *     size="attachmentSize",
  30.      *     mimeType="attachmentMimeType",
  31.      *     originalName="attachmentOriginalName",
  32.      *     dimensions="attachmentDimensions"
  33.      * )
  34.      *
  35.      * @var File|null
  36.      *
  37.      * @Assert\File(maxSize="20M", )
  38.      */
  39.     protected $attachmentFile;
  40.     /**
  41.      * @ORM\Column(type="integer")
  42.      *
  43.      * @var int|null
  44.      */
  45.     protected $attachmentSize;
  46.     /**
  47.      * @var string|null
  48.      *
  49.      * @ORM\Column(type="string", length=255)
  50.      */
  51.     protected $attachmentMimeType;
  52.     /**
  53.      * @var string|null
  54.      *
  55.      * @ORM\Column(type="string", length=255)
  56.      */
  57.     protected $attachmentOriginalName;
  58.     /**
  59.      * @var array|null
  60.      *
  61.      * @ORM\Column(type="array", length=255)
  62.      */
  63.     protected $attachmentDimensions;
  64.     /**
  65.      * @var ArrayCollection
  66.      *
  67.      * @ORM\ManyToMany(targetEntity="App\Entity\ModuleTest\ModuleTest", inversedBy="attachments")
  68.      */
  69.     protected $moduleTests;
  70.     public function __toString()
  71.     {
  72.         return $this->getAttachmentOriginalName() ?? '';
  73.     }
  74.     public function __construct()
  75.     {
  76.         $this->moduleTests = new ArrayCollection();
  77.     }
  78.     /**
  79.      * @return string|null
  80.      */
  81.     public function getAttachment(): ?string
  82.     {
  83.         return $this->attachment;
  84.     }
  85.     /**
  86.      * @param string|null $attachment
  87.      */
  88.     public function setAttachment(?string $attachment): void
  89.     {
  90.         $this->attachment $attachment;
  91.     }
  92.     /**
  93.      * @return File|null
  94.      */
  95.     public function getAttachmentFile(): ?File
  96.     {
  97.         return $this->attachmentFile;
  98.     }
  99.     /**
  100.      * @param File|null $attachmentFile
  101.      */
  102.     public function setAttachmentFile(?File $attachmentFile): void
  103.     {
  104.         $this->attachmentFile $attachmentFile;
  105.         // VERY IMPORTANT:
  106.         // It is required that at least one field changes if you are using Doctrine,
  107.         // otherwise the event listeners won't be called and the file is lost
  108.         if ($attachmentFile) {
  109.             // if 'updatedAt' is not defined in your entity, use another property
  110.             $this->updatedAt = new DateTime('now');
  111.         }
  112.     }
  113.     /**
  114.      * @return int|null
  115.      */
  116.     public function getAttachmentSize(): ?int
  117.     {
  118.         return $this->attachmentSize;
  119.     }
  120.     /**
  121.      * @param int|null $attachmentSize
  122.      */
  123.     public function setAttachmentSize(?int $attachmentSize): void
  124.     {
  125.         $this->attachmentSize $attachmentSize;
  126.     }
  127.     /**
  128.      * @return string|null
  129.      */
  130.     public function getAttachmentMimeType(): ?string
  131.     {
  132.         return $this->attachmentMimeType;
  133.     }
  134.     /**
  135.      * @param string|null $attachmentMimeType
  136.      */
  137.     public function setAttachmentMimeType(?string $attachmentMimeType): void
  138.     {
  139.         $this->attachmentMimeType $attachmentMimeType;
  140.     }
  141.     /**
  142.      * @return string|null
  143.      */
  144.     public function getAttachmentOriginalName(): ?string
  145.     {
  146.         return $this->attachmentOriginalName;
  147.     }
  148.     /**
  149.      * @param string|null $attachmentOriginalName
  150.      */
  151.     public function setAttachmentOriginalName(?string $attachmentOriginalName): void
  152.     {
  153.         $this->attachmentOriginalName $attachmentOriginalName;
  154.     }
  155.     /**
  156.      * @return array|null
  157.      */
  158.     public function getAttachmentDimensions(): ?array
  159.     {
  160.         return $this->attachmentDimensions;
  161.     }
  162.     /**
  163.      * @param array|null $attachmentDimensions
  164.      */
  165.     public function setAttachmentDimensions(?array $attachmentDimensions): void
  166.     {
  167.         $this->attachmentDimensions $attachmentDimensions;
  168.     }
  169.     /**
  170.      * @return ArrayCollection|Collection
  171.      */
  172.     public function getModuleTests(): Collection
  173.     {
  174.         return $this->moduleTests;
  175.     }
  176.     /**
  177.      * @param ArrayCollection|Collection $moduleTests
  178.      */
  179.     public function setModuleTests(Collection $moduleTests): void
  180.     {
  181.         $this->moduleTests $moduleTests;
  182.     }
  183.     /**
  184.      * @param ModuleTest $moduleTest
  185.      */
  186.     public function addModuleTest(ModuleTest $moduleTest): void
  187.     {
  188.         if (!$this->moduleTests->contains($moduleTest)) {
  189.             $this->moduleTests->add($moduleTest);
  190.         }
  191.     }
  192.     /**
  193.      * @param ModuleTest $moduleTest
  194.      */
  195.     public function removeModuleTest(ModuleTest $moduleTest): void
  196.     {
  197.         if ($this->moduleTests->contains($moduleTest)) {
  198.             $this->moduleTests->removeElement($moduleTest);
  199.         }
  200.     }
  201. }