src/Entity/Association.php line 19

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Participation\Asso;
  4. use App\Entity\Traits\TimestampableTrait;
  5. use App\Repository\AssociationRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Vich\UploaderBundle\Entity\File as EmbeddedFile;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. #[ORM\Entity(repositoryClassAssociationRepository::class)]
  15. #[Vich\Uploadable]
  16. class Association
  17. {
  18.     use TimestampableTrait;
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column]
  22.     private ?int $id null;
  23.     #[ORM\Column(length255)]
  24.     private ?string $name null;
  25.     #[ORM\Embedded(class: EmbeddedFile::class)]
  26.     private ?EmbeddedFile $image null;
  27.     #[Vich\UploadableField(mapping'asso_image'fileNameProperty'image.name'size'image.size'mimeType'image.mimeType'originalName'image.originalName'dimensions'image.dimensions')]
  28.     #[Assert\File(
  29.         maxSize'15M',
  30.         mimeTypes: ['image/jpeg''image/png'],
  31.         maxSizeMessage'Le fichier ne doit pas dépasser {{ size }}',
  32.         mimeTypesMessage'Veuillez mettre une image(jpeg ou png)',
  33.     )]
  34.     private ?File $imageFile null;
  35.     #[ORM\Column(typeTypes::TEXT)]
  36.     private ?string $description null;
  37.     #[ORM\Column(length5)]
  38.     private ?string $pal null;
  39.     #[ORM\OneToMany(mappedBy'association'targetEntityAsso::class, orphanRemovaltrue)]
  40.     private Collection $participations;
  41.     public function __construct()
  42.     {
  43.         $this->image = new EmbeddedFile();
  44.         $this->participations = new ArrayCollection();
  45.     }
  46.     public function getId(): ?int
  47.     {
  48.         return $this->id;
  49.     }
  50.     public function getName(): ?string
  51.     {
  52.         return $this->name;
  53.     }
  54.     public function setName(string $name): self
  55.     {
  56.         $this->name $name;
  57.         return $this;
  58.     }
  59.     public function getImage(): ?EmbeddedFile
  60.     {
  61.         return $this->image;
  62.     }
  63.     public function setImage(?EmbeddedFile $image): Association
  64.     {
  65.         $this->image $image;
  66.         return $this;
  67.     }
  68.     public function getImageFile(): ?File
  69.     {
  70.         return $this->imageFile;
  71.     }
  72.     public function setImageFile(?File $image null): self
  73.     {
  74.         $this->imageFile $image;
  75.         if (null !== $image) {
  76.             $this->updatedAt = new \DateTimeImmutable();
  77.         }
  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 getPal(): ?string
  90.     {
  91.         return $this->pal;
  92.     }
  93.     public function setPal(string $pal): self
  94.     {
  95.         $this->pal $pal;
  96.         return $this;
  97.     }
  98.     /**
  99.      * @return Collection<int, Asso>
  100.      */
  101.     public function getParticipations(): Collection
  102.     {
  103.         return $this->participations;
  104.     }
  105.     public function addParticipation(Asso $participation): self
  106.     {
  107.         if (!$this->participations->contains($participation)) {
  108.             $this->participations->add($participation);
  109.             $participation->setAssociation($this);
  110.         }
  111.         return $this;
  112.     }
  113.     public function removeParticipation(Asso $participation): self
  114.     {
  115.         if ($this->participations->removeElement($participation)) {
  116.             // set the owning side to null (unless already changed)
  117.             if ($participation->getAssociation() === $this) {
  118.                 $participation->setAssociation(null);
  119.             }
  120.         }
  121.         return $this;
  122.     }
  123. }