src/Entity/Attachment.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\DBAL\Types\Types;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\AttachmentRepository;
  6. use Symfony\Component\HttpFoundation\File\File;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use Symfony\Component\Serializer\Annotation\Ignore;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. use Symfony\Component\HttpFoundation\File\UploadedFile;
  11. #[Vich\Uploadable]
  12. #[ORM\Entity(repositoryClassAttachmentRepository::class)]
  13. class Attachment extends RootEntity
  14. {
  15.   #[ORM\Id]
  16.   #[ORM\GeneratedValue]
  17.   #[ORM\Column(type'integer')]
  18.   #[Groups(['api_index''api_view'])]
  19.   private $id;
  20.   #[ORM\Column(type'string'length255nullabletrue)]
  21.   #[Groups(['api_index''api_view'])]
  22.   private $fileName;
  23.   #[Vich\UploadableField(mapping'upload_file'fileNameProperty'filename')]
  24.   #[Ignore]
  25.   private $file;
  26.   #[ORM\Column(type'text'nullabletrue)]
  27.   #[Groups(['api_index''api_view'])]
  28.   private $description;
  29.   #[ORM\Column(type'string'length255)]
  30.   private string $foldername "manual";
  31.   #[ORM\Column(type'array'nullabletrue)]
  32.   private $metadata = [];
  33.   #[Groups(['api_index''api_view'])]
  34.   public $filePath null;
  35.   #[Groups(['api_index''api_view'])]
  36.   public $thumbnail null;
  37.   #[ORM\Column(type'integer'nullabletrue)]
  38.   private $entityId;
  39.   #[ORM\Column(type'string'length255nullabletrue)]
  40.   private $entityName;
  41.   #[ORM\Column(nullabletrue)]
  42.   private ?array $allowForRoles = [];
  43.   #[ORM\Column(nullabletrue)]
  44.   private ?array $allowForUsers = [];
  45.   #[ORM\ManyToOne]
  46.   private ?User $user null;
  47.   public function __toString()
  48.   {
  49.     return "Файл: " $this->id;
  50.   }
  51.   public function getFile(): ?File
  52.   {
  53.     return $this->file;
  54.   }
  55.   /**
  56.    * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  57.    */
  58.   public function setFile(?File $imageFile null): void
  59.   {
  60.     $this->file $imageFile;
  61.     if ($imageFile) {
  62.       $oldMetaData $this->getMetadata();
  63.       $oldMetaData['temp'] = (new \DateTimeImmutable())->getTimestamp();
  64.       $this->setMetadata($oldMetaData);
  65.     }
  66.   }
  67.   public function getId(): ?int
  68.   {
  69.     return $this->id;
  70.   }
  71.   public function getFileName(): ?string
  72.   {
  73.     return $this->fileName;
  74.   }
  75.   public function setFileName(?string $fileName): self
  76.   {
  77.     $this->fileName $fileName;
  78.     return $this;
  79.   }
  80.   public function getDescription(): ?string
  81.   {
  82.     return $this->description;
  83.   }
  84.   public function setDescription(?string $description): self
  85.   {
  86.     $this->description $description;
  87.     return $this;
  88.   }
  89.   public function getFoldername(): ?string
  90.   {
  91.     return $this->foldername;
  92.   }
  93.   public function setFoldername(string $foldername): self
  94.   {
  95.     $this->foldername $foldername;
  96.     return $this;
  97.   }
  98.   public function getMetadata(): ?array
  99.   {
  100.     return $this->metadata;
  101.   }
  102.   public function setMetadata(?array $metadata): self
  103.   {
  104.     $this->metadata $metadata;
  105.     return $this;
  106.   }
  107.   public function getEntityId(): ?int
  108.   {
  109.     return $this->entityId;
  110.   }
  111.   public function setEntityId(?int $entityId): self
  112.   {
  113.     $this->entityId $entityId;
  114.     return $this;
  115.   }
  116.   public function getEntityName(): ?string
  117.   {
  118.     return $this->entityName;
  119.   }
  120.   public function setEntityName(?string $entityName): self
  121.   {
  122.     $this->entityName $entityName;
  123.     return $this;
  124.   }
  125.   public function getAllowForRoles(): array
  126.   {
  127.     return $this->allowForRoles;
  128.   }
  129.   public function setAllowForRoles(?array $allowForRoles): self
  130.   {
  131.     $this->allowForRoles $allowForRoles;
  132.     return $this;
  133.   }
  134.   public function getAllowForUsers(): array
  135.   {
  136.     return $this->allowForUsers;
  137.   }
  138.   public function setAllowForUsers(?array $allowForUsers): self
  139.   {
  140.     $this->allowForUsers $allowForUsers;
  141.     return $this;
  142.   }
  143.   public function getUser(): ?User
  144.   {
  145.     return $this->user;
  146.   }
  147.   public function setUser(?User $user): self
  148.   {
  149.     $this->user $user;
  150.     return $this;
  151.   }
  152. }