<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Controller\Api\Claiming\ClaimingRequestController;
use App\Controller\Api\Claiming\GetUserCompaniesClaimedController;
use App\Repository\ClaimingRequestRepository;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: ClaimingRequestRepository::class)]
#[ApiResource(
collectionOperations: [
'get',
'claim' => [
'method' => 'POST',
'path' => '/claim',
'controller' => ClaimingRequestController::class,
'write' => false,
],
'get_user_companies_claimed' => [
'method' => 'GET',
'path' => '/get-user-companies-claimed',
'controller' => GetUserCompaniesClaimedController::class,
'normalization_context' => [
'groups' => 'read:claimingRequest:collection:getUserCompaniesClaimed',
],
],
],
normalizationContext: [
'groups' => 'read:claimingRequest:collection',
]
)]
class ClaimingRequest
{
const STATUS_NEW = 'new';
const STATUS_VALIDATED = 'validated';
const STATUS_REJECTED = 'rejected';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups([
"read:claimingRequest:collection:getUserCompaniesClaimed",
])]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'claimingRequests')]
#[ORM\JoinColumn(nullable: false, onDelete: "CASCADE")]
private ?User $claimer = null;
#[ORM\ManyToOne(inversedBy: 'claimingRequests')]
#[ORM\JoinColumn(nullable: false, onDelete: "CASCADE")]
#[Groups([
"read:claimingRequest:collection:getUserCompaniesClaimed",
])]
private ?Company $company = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $message = null;
#[ORM\Column(length: 255)]
#[Groups([
'read:user:item:user:companies:management',
])]
private ?string $status = null;
use TimestampableEntity;
public function __construct()
{
$this->status = self::STATUS_NEW;
}
public static function getStatusList(): array
{
return [
self::STATUS_NEW => 'Nouvelle',
self::STATUS_VALIDATED => 'Validée',
self::STATUS_REJECTED => 'Rejetée',
];
}
public function getStatusLabel(): ?string
{
$list = self::getStatusList();
return ($this->status != null && array_key_exists($this->status, $list) ? $list[$this->status] : null);
}
public function getStatusClass(): ?string
{
return match ($this->status) {
self::STATUS_NEW => 'info',
self::STATUS_VALIDATED => 'success',
self::STATUS_REJECTED => 'danger',
default => null,
};
}
public function getId(): ?int
{
return $this->id;
}
#[Groups([
'read:club:collection:getCompanies',
'read:company:collection:get',
])]
public function getClaimer(): ?User
{
return $this->claimer;
}
public function setClaimer(?User $claimer): self
{
$this->claimer = $claimer;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getMessage(): ?string
{
return $this->message;
}
public function setMessage(string $message): self
{
$this->message = $message;
return $this;
}
public function getCreatedAt(): ?DateTime
{
return $this->createdAt;
}
public function getUpdatedAt(): ?DateTime
{
return $this->updatedAt;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): static
{
$this->status = $status;
return $this;
}
}