src/Entity/Gift.php line 39
<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Repository\GiftRepository;
use App\Trait\DateTimeTrait;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Serializable;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: GiftRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[Vich\Uploadable]
#[ORM\Table(name: '`gift`')]
#[ApiResource(
operations: [
new Get(
normalizationContext: [
'groups' => 'gift:item'
]
),
new GetCollection(
normalizationContext: [
'groups' => 'gift:list'
]
),
],
paginationEnabled: false,
)]
class Gift implements Serializable
{
use DateTimeTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['gift:item', 'gift:list'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['gift:item', 'gift:list'])]
private ?string $libelle = null;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, options: [
"default" => null
])]
#[Groups(['gift:item', 'gift:list'])]
private ?string $imageName = null;
#[Vich\UploadableField(mapping: 'gift_img', fileNameProperty: 'imageName', size: 'imageSize')]
private ?File $imageFile = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $imageSize = null;
#[ORM\OneToMany(mappedBy: 'gift', targetEntity: GiftPompiste::class)]
private Collection $giftPompistes;
public function __construct()
{
$this->giftPompistes = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLibelle(): ?string
{
return $this->libelle;
}
public function setLibelle(string $libelle): self
{
$this->libelle = $libelle;
return $this;
}
/**
* @return string|null
*/
public function getImageName(): ?string
{
return $this->imageName;
}
/**
* @param string|null $imageName
*/
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
/**
* @param File|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
$this->updatedAt = new DateTimeImmutable;
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageSize(?int $imageSize): void
{
$this->imageSize = $imageSize;
}
public function getImageSize(): ?int
{
return $this->imageSize;
}
/** @see \Serializable::serialize() */
public function serialize(): ?string
{
return serialize(array(
$this->id,
$this->libelle,
$this->isActivated,
));
}
/** @param $serialized
* @see \Serializable::unserialize()
*/
public function unserialize($serialized)
{
list (
$this->id,
$this->libelle,
$this->isActivated,
) = unserialize($serialized, array('allowed_classes' => false));
}
/**
* @return Collection<int, GiftPompiste>
*/
public function getGiftPompistes(): Collection
{
return $this->giftPompistes;
}
public function addGiftPompiste(GiftPompiste $giftPompiste): self
{
if (!$this->giftPompistes->contains($giftPompiste)) {
$this->giftPompistes->add($giftPompiste);
$giftPompiste->setGift($this);
}
return $this;
}
public function removeGiftPompiste(GiftPompiste $giftPompiste): self
{
if ($this->giftPompistes->removeElement($giftPompiste)) {
// set the owning side to null (unless already changed)
if ($giftPompiste->getGift() === $this) {
$giftPompiste->setGift(null);
}
}
return $this;
}
}