src/Entity/Eligibility.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Entity\Operation\Operation;
  6. use App\Repository\EligibilityRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Timestampable\Traits\TimestampableEntity;
  11. use Ramsey\Uuid\Doctrine\UuidGenerator;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Serializer\Annotation\SerializedName;
  14. /**
  15.  * @ApiResource(
  16.  *     attributes={
  17.  *          "normalization_context"={"groups"={
  18.  *              "Eligibility:output",
  19.  *              "Eligibility:io"
  20.  *          }},
  21.  *          "denormalization_context"={"groups"={
  22.  *              "Eligibility:input",
  23.  *              "Eligibility:io"
  24.  *          }}
  25.  *      },
  26.  *     collectionOperations={
  27.  *          "get"={
  28.  *              "method"="GET",
  29.  *              "access_control"="is_granted('ROLE_USER')",
  30.  *          },
  31.  *     },
  32.  *     itemOperations={
  33.  *          "get"={
  34.  *              "method"="GET",
  35.  *              "access_control"="is_granted('ROLE_USER')",
  36.  *          },
  37.  *      }
  38.  * )
  39.  * @ORM\Entity(repositoryClass=EligibilityRepository::class)
  40.  */
  41. class Eligibility
  42. {
  43.     public const ELIGIBILITY_LIST = [
  44.         self::ELIGIBILITY_LABEL_ALL,
  45.         self::ELIGIBILITY_LABEL_BIRTHDAY,
  46.         self::ELIGIBILITY_LABEL_DEPARTMENT,
  47.         self::ELIGIBILITY_NEW_CLIENT
  48.     ];
  49.     public const ELIGIBILITY_LABEL_ALL 'all';
  50.     public const ELIGIBILITY_LABEL_BIRTHDAY 'birthday';
  51.     public const ELIGIBILITY_LABEL_DEPARTMENT 'department';
  52.     public const ELIGIBILITY_NEW_CLIENT 'new_client';
  53.     /**
  54.      * Hook timestampable behavior
  55.      * updates createdAt, updatedAt fields
  56.      */
  57.     use TimestampableEntity;
  58.     /**
  59.      * @ORM\Id
  60.      * @ORM\Column(type="uuid", unique=true)
  61.      * @ORM\GeneratedValue(strategy="CUSTOM")
  62.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  63.      * @SerializedName("id")
  64.      * @ApiProperty(identifier=true)
  65.      * @Groups({
  66.      *     "Eligibility:output",
  67.      *     "get_all_public_coupons",
  68.      *     "get_coupons_by_user_department",
  69.      *     "OperationOdr:io",
  70.      *     "Operation:io",
  71.      * })
  72.      */
  73.     private string $id;
  74.     /**
  75.      * @ORM\Column(type="string", length=255)
  76.      * @SerializedName("label")
  77.      * @Groups({
  78.      *     "Eligibility:output",
  79.      *     "get_all_public_coupons",
  80.      *     "get_coupons_by_user_department",
  81.      *     "OperationOdr:io",
  82.      *     "Operation:io",
  83.      * })
  84.      */
  85.     private ?string $label;
  86.     /**
  87.      * @ORM\ManyToMany(targetEntity=Operation::class, inversedBy="eligibilities")
  88.      */
  89.     private Collection $operation;
  90.     public function __construct()
  91.     {
  92.         $this->operation = new ArrayCollection();
  93.     }
  94.     public function getId(): ?string
  95.     {
  96.         return $this->id;
  97.     }
  98.     public function getLabel(): ?string
  99.     {
  100.         return $this->label;
  101.     }
  102.     public function setLabel(string $label): self
  103.     {
  104.         $this->label $label;
  105.         return $this;
  106.     }
  107.     /**
  108.      * @return Collection|Operation[]
  109.      */
  110.     public function getOperation(): Collection
  111.     {
  112.         return $this->operation;
  113.     }
  114.     public function addOperation(Operation $operation): self
  115.     {
  116.         if (!$this->operation->contains($operation)) {
  117.             $this->operation[] = $operation;
  118.         }
  119.         return $this;
  120.     }
  121.     public function removeOperation(Operation $operation): self
  122.     {
  123.         $this->operation->removeElement($operation);
  124.         return $this;
  125.     }
  126.     public function checkEligibility(): bool
  127.     {
  128.         return in_array($this->labelself::ELIGIBILITY_LISTtrue);
  129.     }
  130.     public function __toString()
  131.     {
  132.         return $this->label;
  133.     }
  134. }