src/Entity/Gift.php line 39

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use App\Repository\GiftRepository;
  7. use App\Trait\DateTimeTrait;
  8. use DateTimeImmutable;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\DBAL\Types\Types;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Serializable;
  14. use Symfony\Component\HttpFoundation\File\File;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  17. #[ORM\Entity(repositoryClassGiftRepository::class)]
  18. #[ORM\HasLifecycleCallbacks]
  19. #[Vich\Uploadable]
  20. #[ORM\Table(name'`gift`')]
  21. #[ApiResource(
  22.     operations: [
  23.         new Get(
  24.             normalizationContext: [
  25.                 'groups' => 'gift:item'
  26.             ]
  27.         ),
  28.         new GetCollection(
  29.             normalizationContext: [
  30.                 'groups' => 'gift:list'
  31.             ]
  32.         ),
  33.     ],
  34.     paginationEnabledfalse,
  35. )]
  36. class Gift implements Serializable
  37. {
  38.     use DateTimeTrait;
  39.     #[ORM\Id]
  40.     #[ORM\GeneratedValue]
  41.     #[ORM\Column]
  42.     #[Groups(['gift:item''gift:list'])]
  43.     private ?int $id null;
  44.     #[ORM\Column(length255)]
  45.     #[Groups(['gift:item''gift:list'])]
  46.     private ?string $libelle null;
  47.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueoptions: [
  48.         "default" => null
  49.     ])]
  50.     #[Groups(['gift:item''gift:list'])]
  51.     private ?string $imageName null;
  52.     #[Vich\UploadableField(mapping'gift_img'fileNameProperty'imageName'size'imageSize')]
  53.     private ?File $imageFile null;
  54.     #[ORM\Column(type'integer'nullabletrue)]
  55.     private ?int $imageSize null;
  56.     #[ORM\OneToMany(mappedBy'gift'targetEntityGiftPompiste::class)]
  57.     private Collection $giftPompistes;
  58.     public function __construct()
  59.     {
  60.         $this->giftPompistes = new ArrayCollection();
  61.     }
  62.     public function getId(): ?int
  63.     {
  64.         return $this->id;
  65.     }
  66.     public function getLibelle(): ?string
  67.     {
  68.         return $this->libelle;
  69.     }
  70.     public function setLibelle(string $libelle): self
  71.     {
  72.         $this->libelle $libelle;
  73.         return $this;
  74.     }
  75.     /**
  76.      * @return string|null
  77.      */
  78.     public function getImageName(): ?string
  79.     {
  80.         return $this->imageName;
  81.     }
  82.     /**
  83.      * @param string|null $imageName
  84.      */
  85.     public function setImageName(?string $imageName): void
  86.     {
  87.         $this->imageName $imageName;
  88.     }
  89.     /**
  90.      * @param File|null $imageFile
  91.      */
  92.     public function setImageFile(?File $imageFile null): void
  93.     {
  94.         $this->imageFile $imageFile;
  95.         if (null !== $imageFile) {
  96.             $this->updatedAt = new DateTimeImmutable;
  97.         }
  98.     }
  99.     public function getImageFile(): ?File
  100.     {
  101.         return $this->imageFile;
  102.     }
  103.     public function setImageSize(?int $imageSize): void
  104.     {
  105.         $this->imageSize $imageSize;
  106.     }
  107.     public function getImageSize(): ?int
  108.     {
  109.         return $this->imageSize;
  110.     }
  111.     /** @see \Serializable::serialize() */
  112.     public function serialize(): ?string
  113.     {
  114.         return serialize(array(
  115.             $this->id,
  116.             $this->libelle,
  117.             $this->isActivated,
  118.         ));
  119.     }
  120.     /** @param $serialized
  121.      * @see \Serializable::unserialize()
  122.      */
  123.     public function unserialize($serialized)
  124.     {
  125.         list (
  126.             $this->id,
  127.             $this->libelle,
  128.             $this->isActivated,
  129.             ) = unserialize($serialized, array('allowed_classes' => false));
  130.     }
  131.     /**
  132.      * @return Collection<int, GiftPompiste>
  133.      */
  134.     public function getGiftPompistes(): Collection
  135.     {
  136.         return $this->giftPompistes;
  137.     }
  138.     public function addGiftPompiste(GiftPompiste $giftPompiste): self
  139.     {
  140.         if (!$this->giftPompistes->contains($giftPompiste)) {
  141.             $this->giftPompistes->add($giftPompiste);
  142.             $giftPompiste->setGift($this);
  143.         }
  144.         return $this;
  145.     }
  146.     public function removeGiftPompiste(GiftPompiste $giftPompiste): self
  147.     {
  148.         if ($this->giftPompistes->removeElement($giftPompiste)) {
  149.             // set the owning side to null (unless already changed)
  150.             if ($giftPompiste->getGift() === $this) {
  151.                 $giftPompiste->setGift(null);
  152.             }
  153.         }
  154.         return $this;
  155.     }
  156. }