src/Entity/AnnonceImage.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AnnonceImageRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\HttpFoundation\File\File;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  8. #[ORM\Entity(repositoryClassAnnonceImageRepository::class)]
  9. #[Vich\Uploadable]
  10. class AnnonceImage
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\ManyToOne(inversedBy'images')]
  17.     private ?OffreDeTravail $offre null;
  18.     #[ORM\ManyToOne(inversedBy'images')]
  19.     private ?DemandeDeTravail $demande null;
  20.     #[Vich\UploadableField(mapping'annonce_images'fileNameProperty'imageName')]
  21.     #[Assert\Image(
  22.         maxSize'5M',
  23.         mimeTypes: ['image/jpeg''image/png''image/webp''image/gif'],
  24.         mimeTypesMessage'Formats acceptés: JPEG, PNG, WEBP, GIF',
  25.         maxSizeMessage'Taille maximale 5 Mo'
  26.     )]
  27.     private ?File $imageFile null;
  28.     #[ORM\Column(length255nullabletrue)]
  29.     private ?string $imageName null;
  30.     #[ORM\Column(nullabletrue)]
  31.     private ?\DateTimeImmutable $updatedAt null;
  32.     public function getId(): ?int { return $this->id; }
  33.     public function getOffre(): ?OffreDeTravail { return $this->offre; }
  34.     public function setOffre(?OffreDeTravail $offre): static { $this->offre $offre; return $this; }
  35.     public function getDemande(): ?DemandeDeTravail { return $this->demande; }
  36.     public function setDemande(?DemandeDeTravail $demande): static { $this->demande $demande; return $this; }
  37.     public function setImageFile(?File $imageFile null): void
  38.     {
  39.         $this->imageFile $imageFile;
  40.         if (null !== $imageFile) { $this->updatedAt = new \DateTimeImmutable(); }
  41.     }
  42.     public function getImageFile(): ?File { return $this->imageFile; }
  43.     public function getImageName(): ?string { return $this->imageName; }
  44.     public function setImageName(?string $imageName): void $this->imageName $imageName; }
  45.     public function getUpdatedAt(): ?\DateTimeImmutable { return $this->updatedAt; }
  46.     public function setUpdatedAt(?\DateTimeImmutable $updatedAt): static { $this->updatedAt $updatedAt; return $this; }
  47. }