src/Entity/Sponsorship/SponsorshipRequest.php line 81

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Sponsorship;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Repository\Sponsorship\SponsorshipRequestRepository;
  6. use App\Controller\Api\SponsorshipRequest\PostSponsorshipRequestGodChild;
  7. use App\Controller\Api\SponsorshipRequest\PostMultipleSponsorshipRequests;
  8. use App\Controller\Api\SponsorshipRequest\GetGodFatherByGodChildEmail;
  9. use App\Controller\Api\SponsorshipRequest\GetGodChildsByGodFatherUser;
  10. use DateTime;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use App\Entity\User\User;
  13. use Gedmo\Timestampable\Traits\TimestampableEntity;
  14. use Ramsey\Uuid\Uuid;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Serializer\Annotation\SerializedName;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. use Ramsey\Uuid\Doctrine\UuidGenerator;
  19. /**
  20.  * @ORM\Entity(repositoryClass=SponsorshipRequestRepository::class)
  21.  * @ORM\Table(name="sponsorship")
  22.  *
  23.  * @ApiResource(
  24.  *     attributes={
  25.  *          "normalization_context"={"groups"={
  26.  *              "SponsorshipRequest:output",
  27.  *              "SponsorshipRequest:io",
  28.  *              "get_godfather_by_godchild_email",
  29.  *              "get_godchilds_by_godfather_user",
  30.  *          }},
  31.  *          "denormalization_context"={"groups"={
  32.  *              "SponsorshipRequest:input",
  33.  *              "SponsorshipRequest:io",
  34.  *              "get_godfather_by_godchild_email",
  35.  *              "get_godchilds_by_godfather_user",
  36.  *          }}
  37.  *      },
  38.  *     collectionOperations={
  39.  *          "get",
  40.  *          "get-recovery-godchilds-by-godfather-user"={
  41.  *              "method"="GET",
  42.  *              "path"="/sponsorship_requests/recovery-godchilds/user",
  43.  *              "access_control"="is_granted('ROLE_USER')",
  44.  *              "validation_groups"={"get_godchilds_by_godfather_user"},
  45.  *              "controller"=GetGodChildsByGodFatherUser::class,
  46.  *              "defaults"={"_api_receive"=false},
  47.  *          },
  48.  *          "post",
  49.  *          "post-godchild-by-user"={
  50.  *              "method"="POST",
  51.  *              "path"="public/sponsorship_requests/get-godchild",
  52.  *              "validation_groups"={"post_godchild_sponsorship_request"},
  53.  *              "controller"=PostSponsorshipRequestGodChild::class,
  54.  *              "defaults"={"_api_receive"=false},
  55.  *          },
  56.  *          "post-multiple-sponsorchip-requests"={
  57.  *              "method"="POST",
  58.  *              "path"="/sponsorship_requests/multiple",
  59.  *              "access_control"="is_granted('ROLE_USER')",
  60.  *              "controller"=PostMultipleSponsorshipRequests::class,
  61.  *              "defaults"={"_api_receive"=false},
  62.  *          },
  63.  *     },
  64.  *     itemOperations={
  65.  *          "get",
  66.  *          "get-recovery-godfther-by-godchild-email"={
  67.  *              "method"="GET",
  68.  *              "path"="/sponsorship_requests/recovery-godfather/user",
  69.  *              "access_control"="is_granted('ROLE_USER')",
  70.  *              "validation_groups"={"get_godfather_by_godchild_email"},
  71.  *              "controller"=GetGodFatherByGodChildEmail::class,
  72.  *              "defaults"={"_api_receive"=false},
  73.  *          },
  74.  *     }
  75.  * )
  76.  *
  77.  */
  78. class SponsorshipRequest
  79. {
  80.     const STATUS_WAITING "waiting_for_registration";
  81.     const STATUS_IN_PROGRESS "in_process_of_registration";
  82.     const STATUS_FULLY_REGISTERED "fully_registered";
  83.     const STATUS_GODCHILD_DELETED "godchild_deleted";
  84.     /**
  85.      * Hook timestampable behavior
  86.      * updates createdAt, updatedAt fields
  87.      */
  88.     use TimestampableEntity;
  89.     /**
  90.      * @ORM\Id
  91.      * @ORM\Column(type="uuid", unique=true)
  92.      * @ORM\GeneratedValue(strategy="CUSTOM")
  93.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  94.      * @SerializedName("id")
  95.      * @ApiProperty(identifier=true)
  96.      * @Assert\Uuid()
  97.      * @Groups({
  98.      *     "SponsorshipRequest:output",
  99.      *     "post_godchild_sponsorship_request",
  100.      *     "get_godchilds_by_godfather_user",
  101.      * })
  102.      */
  103.     private string $id;
  104.     /**
  105.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="sponsorshipsRequest")
  106.      * @Groups({
  107.      *     "SponsorshipRequest:io",
  108.      *     "post_godchild_sponsorship_request",
  109.      *     "get_godfather_by_godchild_email",
  110.      *     "get_godchilds_by_godfather_user",
  111.      * })
  112.      * @Assert\NotBlank()
  113.      */
  114.     private $user;
  115.     /**
  116.      * @ORM\Column(type="string", length=180)
  117.      * @SerializedName("email")
  118.      * @Assert\Email(normalizer="trim")
  119.      * @Groups({
  120.      *     "SponsorshipRequest:io",
  121.      *     "post_godchild_sponsorship_request",
  122.      *     "get_godfather_by_godchild_email",
  123.      *     "get_godchilds_by_godfather_user",
  124.      * })
  125.      * @Assert\NotBlank()
  126.      */
  127.     private string $email;
  128.     /**
  129.      * @ORM\Column(type="string", length=2048, nullable=true)
  130.      * @Groups({
  131.      *     "SponsorshipRequest:io",
  132.      *     "post_godchild_sponsorship_request",
  133.      *     "get_godfather_by_godchild_email",
  134.      * })
  135.      */
  136.     private ?string $godsonMessage null;
  137.     /**
  138.      * @var DateTime
  139.      *
  140.      * @ORM\Column(name="used_at", type="datetime", nullable=true)
  141.      * @Groups({
  142.      *     "post_godchild_sponsorship_request",
  143.      *     "get_godfather_by_godchild_email",
  144.      *     "get_godchilds_by_godfather_user",
  145.      * })
  146.      */
  147.     private $usedAt;
  148.     /**
  149.      * @ORM\Column(type="string", length=30)
  150.      * @Groups({
  151.      *     "SponsorshipRequest:io",
  152.      *     "post_godchild_sponsorship_request",
  153.      *     "get_godfather_by_godchild_email",
  154.      *     "get_godchilds_by_godfather_user",
  155.      * })
  156.      */
  157.     private $status self::STATUS_WAITING;
  158.     public function __construct()
  159.     {
  160.         $this->id Uuid::uuid4();
  161.     }
  162.     public function getId(): string
  163.     {
  164.         return $this->id;
  165.     }
  166.     public function getUser(): ?User
  167.     {
  168.         return $this->user;
  169.     }
  170.     public function setUser(?User $user): self
  171.     {
  172.         $this->user $user;
  173.         return $this;
  174.     }
  175.     public function getEmail(): string
  176.     {
  177.         return $this->email;
  178.     }
  179.     public function setEmail(string $email): self
  180.     {
  181.         $this->email $email;
  182.         return $this;
  183.     }
  184.     public function getGodsonMessage(): ?string
  185.     {
  186.         return $this->godsonMessage;
  187.     }
  188.     public function setGodsonMessage(string $godsonMessage): self
  189.     {
  190.         $this->godsonMessage $godsonMessage;
  191.         return $this;
  192.     }
  193.     public function setUsedAt($usedAt)
  194.     {
  195.         $this->usedAt $usedAt;
  196.         return $this;
  197.     }
  198.     public function getUsedAt()
  199.     {
  200.         return $this->usedAt;
  201.     }
  202.     public function getStatus(): ?string
  203.     {
  204.         return $this->status;
  205.     }
  206.     public function setStatus(string $status): self
  207.     {
  208.         $this->status $status;
  209.         return $this;
  210.     }
  211. }