<?php
namespace App\Entity\ModuleTest;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use EightMarq\CoreComponent\Entity\BaseEntity;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Table(name="attchments")
* @ORM\Entity()
*
* @Vich\Uploadable()
*/
class Attachment extends BaseEntity
{
/**
* @var string|null
*
* @ORM\Column(type="string", length=255)
*/
protected $attachment;
/**
* @Vich\UploadableField(
* mapping="module_tests_attachments",
* fileNameProperty="attachment",
* size="attachmentSize",
* mimeType="attachmentMimeType",
* originalName="attachmentOriginalName",
* dimensions="attachmentDimensions"
* )
*
* @var File|null
*
* @Assert\File(maxSize="20M", )
*/
protected $attachmentFile;
/**
* @ORM\Column(type="integer")
*
* @var int|null
*/
protected $attachmentSize;
/**
* @var string|null
*
* @ORM\Column(type="string", length=255)
*/
protected $attachmentMimeType;
/**
* @var string|null
*
* @ORM\Column(type="string", length=255)
*/
protected $attachmentOriginalName;
/**
* @var array|null
*
* @ORM\Column(type="array", length=255)
*/
protected $attachmentDimensions;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="App\Entity\ModuleTest\ModuleTest", inversedBy="attachments")
*/
protected $moduleTests;
public function __toString()
{
return $this->getAttachmentOriginalName() ?? '';
}
public function __construct()
{
$this->moduleTests = new ArrayCollection();
}
/**
* @return string|null
*/
public function getAttachment(): ?string
{
return $this->attachment;
}
/**
* @param string|null $attachment
*/
public function setAttachment(?string $attachment): void
{
$this->attachment = $attachment;
}
/**
* @return File|null
*/
public function getAttachmentFile(): ?File
{
return $this->attachmentFile;
}
/**
* @param File|null $attachmentFile
*/
public function setAttachmentFile(?File $attachmentFile): void
{
$this->attachmentFile = $attachmentFile;
// VERY IMPORTANT:
// It is required that at least one field changes if you are using Doctrine,
// otherwise the event listeners won't be called and the file is lost
if ($attachmentFile) {
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new DateTime('now');
}
}
/**
* @return int|null
*/
public function getAttachmentSize(): ?int
{
return $this->attachmentSize;
}
/**
* @param int|null $attachmentSize
*/
public function setAttachmentSize(?int $attachmentSize): void
{
$this->attachmentSize = $attachmentSize;
}
/**
* @return string|null
*/
public function getAttachmentMimeType(): ?string
{
return $this->attachmentMimeType;
}
/**
* @param string|null $attachmentMimeType
*/
public function setAttachmentMimeType(?string $attachmentMimeType): void
{
$this->attachmentMimeType = $attachmentMimeType;
}
/**
* @return string|null
*/
public function getAttachmentOriginalName(): ?string
{
return $this->attachmentOriginalName;
}
/**
* @param string|null $attachmentOriginalName
*/
public function setAttachmentOriginalName(?string $attachmentOriginalName): void
{
$this->attachmentOriginalName = $attachmentOriginalName;
}
/**
* @return array|null
*/
public function getAttachmentDimensions(): ?array
{
return $this->attachmentDimensions;
}
/**
* @param array|null $attachmentDimensions
*/
public function setAttachmentDimensions(?array $attachmentDimensions): void
{
$this->attachmentDimensions = $attachmentDimensions;
}
/**
* @return ArrayCollection|Collection
*/
public function getModuleTests(): Collection
{
return $this->moduleTests;
}
/**
* @param ArrayCollection|Collection $moduleTests
*/
public function setModuleTests(Collection $moduleTests): void
{
$this->moduleTests = $moduleTests;
}
/**
* @param ModuleTest $moduleTest
*/
public function addModuleTest(ModuleTest $moduleTest): void
{
if (!$this->moduleTests->contains($moduleTest)) {
$this->moduleTests->add($moduleTest);
}
}
/**
* @param ModuleTest $moduleTest
*/
public function removeModuleTest(ModuleTest $moduleTest): void
{
if ($this->moduleTests->contains($moduleTest)) {
$this->moduleTests->removeElement($moduleTest);
}
}
}