<?php
namespace App\Entity\Details\Operation;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\MediaObject\MediaCoupon;
use App\Repository\Details\DetailsCouponRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Ramsey\Uuid\Doctrine\UuidGenerator;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
/**
* @ApiResource(
* attributes={
* "normalization_context"={
* "groups"={
* "DetailsCoupon:output",
* "DetailsCoupon:io"
* }
* },
* "denormalization_context"={
* "groups"={
* "DetailsCoupon:input",
* "DetailsCoupon:io"
* }
* },
* },
* collectionOperations={
* "post"={
* "method"="POST",
* "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
* },
* "get"={
* "method"="GET",
* "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
* },
* },
* itemOperations={
* "put"={
* "method"="PUT",
* "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
* },
* "get"={
* "method"="GET"
* },
* }
* )
* @ORM\Entity(repositoryClass=DetailsCouponRepository::class)
*/
class DetailsCoupon
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
* @SerializedName("id")
* @ApiProperty(identifier=true)
* @Groups({
* "DetailsCoupon:output",
* "get_all_public_coupons",
* "get_coupons_by_user_department",
* })
*/
private string $id;
/**
* @ORM\Column(type="float")
* @SerializedName("amount")
* @Groups({
* "DetailsCoupon:io",
* "OperationCoupon:io",
* "get_all_public_coupons",
* "get_coupons_by_user_department",
* })
*/
private ?float $amount;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Operation\Coupon")
* @ORM\JoinColumn(name="coupon_id", referencedColumnName="id")
* @Groups({
* "get_all_public_coupons",
* "get_coupons_by_user_department",
* })
*/
private $coupon;
/**
* @var Collection
* @ORM\OneToMany(targetEntity=MediaCoupon::class, mappedBy="detailsCoupon")
* @Groups({
* "DetailsCoupon:io",
* "OperationCoupon:io"
* })
*/
private Collection $images;
/**
* @SerializedName("image")
* @Groups({
* "DetailsCoupon:output",
* "OperationCoupon:output",
* "get_all_public_coupons",
* "get_coupons_by_user_department",
* })
*/
private $image;
/**
* @ORM\Column(type="string", length=255)
* @SerializedName("name")
*
* @Groups({
* "DetailsCoupon:io",
* "OperationCoupon:io",
* "get_all_public_coupons",
* "get_coupons_by_user_department",
* })
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
* @SerializedName("description")
*
* @Groups({
* "DetailsCoupon:io",
* "OperationCoupon:io",
* "get_all_public_coupons",
* "get_coupons_by_user_department",
* })
*/
private $description;
/**
* @ORM\Column(type="text", nullable=true)
* @SerializedName("link_extern")
*
* @Groups({
* "DetailsCoupon:io",
* "OperationCoupon:io",
* "get_all_public_coupons",
* "get_coupons_by_user_department",
* })
*/
private $linkExtern;
public function __construct()
{
$this->images = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getAmount(): ?float
{
return $this->amount;
}
public function setAmount(?float $amount): self
{
$this->amount = $amount;
return $this;
}
public function getCoupon()
{
return $this->coupon;
}
public function setCoupon($coupon)
{
$this->coupon = $coupon;
return $this;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name): DetailsCoupon
{
$this->name = $name;
return $this;
}
/**
* @return mixed
*/
public function getDescription()
{
return $this->description;
}
/**
* @param mixed $description
*/
public function setDescription($description): DetailsCoupon
{
$this->description = $description;
return $this;
}
/**
* @return mixed
*/
public function getLinkExtern()
{
return $this->linkExtern;
}
/**
* @param mixed $linkExtern
*/
public function setLinkExtern($linkExtern): DetailsCoupon
{
$this->linkExtern = $linkExtern;
return $this;
}
/**
* @param mixed $image
*/
public function addImage($image)
{
$this->images->add($image);
// uncomment if you want to update other side
$image->setDetailsCoupon($this);
}
/**
* @param mixed $image
*/
public function removeImage($image)
{
$this->images->removeElement($image);
// uncomment if you want to update other side
//$image->setDetailsCoupon(null);
}
/**
* @return Collection
*/
public function getImages(): Collection
{
return $this->images;
}
/**
* @param Collection $images
* @return DetailsCoupon
*/
public function setImages(Collection $images): DetailsCoupon
{
$this->images = $images;
return $this;
}
/**
* @return mixed
*/
public function getImage()
{
return $this->images->first();
}
}