src/Entity/ClaimingRequest.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Controller\Api\Claiming\ClaimingRequestController;
  5. use App\Controller\Api\Claiming\GetUserCompaniesClaimedController;
  6. use App\Repository\ClaimingRequestRepository;
  7. use DateTime;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Timestampable\Traits\TimestampableEntity;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. #[ORM\Entity(repositoryClassClaimingRequestRepository::class)]
  13. #[ApiResource(
  14.     collectionOperations: [
  15.         'get',
  16.         'claim' => [
  17.             'method' => 'POST',
  18.             'path' => '/claim',
  19.             'controller' => ClaimingRequestController::class,
  20.             'write' => false,
  21.         ],
  22.         'get_user_companies_claimed' => [
  23.             'method' => 'GET',
  24.             'path' => '/get-user-companies-claimed',
  25.             'controller' => GetUserCompaniesClaimedController::class,
  26.             'normalization_context' => [
  27.                 'groups' => 'read:claimingRequest:collection:getUserCompaniesClaimed',
  28.             ],
  29.         ],
  30.     ],
  31.     normalizationContext: [
  32.         'groups' => 'read:claimingRequest:collection',
  33.     ]
  34. )]
  35. class ClaimingRequest
  36. {
  37.     const STATUS_NEW 'new';
  38.     const STATUS_VALIDATED 'validated';
  39.     const STATUS_REJECTED 'rejected';
  40.     #[ORM\Id]
  41.     #[ORM\GeneratedValue]
  42.     #[ORM\Column]
  43.     #[Groups([
  44.         "read:claimingRequest:collection:getUserCompaniesClaimed",
  45.     ])]
  46.     private ?int $id null;
  47.     #[ORM\ManyToOne(inversedBy'claimingRequests')]
  48.     #[ORM\JoinColumn(nullablefalseonDelete"CASCADE")]
  49.     private ?User $claimer null;
  50.     #[ORM\ManyToOne(inversedBy'claimingRequests')]
  51.     #[ORM\JoinColumn(nullablefalseonDelete"CASCADE")]
  52.     #[Groups([
  53.         "read:claimingRequest:collection:getUserCompaniesClaimed",
  54.     ])]
  55.     private ?Company $company null;
  56.     #[ORM\Column(typeTypes::TEXT)]
  57.     private ?string $message null;
  58.     #[ORM\Column(length255)]
  59.     #[Groups([
  60.         'read:user:item:user:companies:management',
  61.     ])]
  62.     private ?string $status null;
  63.     use TimestampableEntity;
  64.     public function __construct()
  65.     {
  66.         $this->status self::STATUS_NEW;
  67.     }
  68.     public static function getStatusList(): array
  69.     {
  70.         return [
  71.             self::STATUS_NEW => 'Nouvelle',
  72.             self::STATUS_VALIDATED => 'Validée',
  73.             self::STATUS_REJECTED => 'Rejetée',
  74.         ];
  75.     }
  76.     public function getStatusLabel(): ?string
  77.     {
  78.         $list self::getStatusList();
  79.         return ($this->status != null && array_key_exists($this->status$list) ? $list[$this->status] : null);
  80.     }
  81.     public function getStatusClass(): ?string
  82.     {
  83.         return match ($this->status) {
  84.             self::STATUS_NEW => 'info',
  85.             self::STATUS_VALIDATED => 'success',
  86.             self::STATUS_REJECTED => 'danger',
  87.             default => null,
  88.         };
  89.     }
  90.     public function getId(): ?int
  91.     {
  92.         return $this->id;
  93.     }
  94.     #[Groups([
  95.         'read:club:collection:getCompanies',
  96.         'read:company:collection:get',
  97.     ])]
  98.     public function getClaimer(): ?User
  99.     {
  100.         return $this->claimer;
  101.     }
  102.     public function setClaimer(?User $claimer): self
  103.     {
  104.         $this->claimer $claimer;
  105.         return $this;
  106.     }
  107.     public function getCompany(): ?Company
  108.     {
  109.         return $this->company;
  110.     }
  111.     public function setCompany(?Company $company): self
  112.     {
  113.         $this->company $company;
  114.         return $this;
  115.     }
  116.     public function getMessage(): ?string
  117.     {
  118.         return $this->message;
  119.     }
  120.     public function setMessage(string $message): self
  121.     {
  122.         $this->message $message;
  123.         return $this;
  124.     }
  125.     public function getCreatedAt(): ?DateTime
  126.     {
  127.         return $this->createdAt;
  128.     }
  129.     public function getUpdatedAt(): ?DateTime
  130.     {
  131.         return $this->updatedAt;
  132.     }
  133.     public function getStatus(): ?string
  134.     {
  135.         return $this->status;
  136.     }
  137.     public function setStatus(string $status): static
  138.     {
  139.         $this->status $status;
  140.         return $this;
  141.     }
  142. }