<?php
namespace App\Entity\Reference;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Mandate;
use App\Repository\Reference\ReferenceMandateTypeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* normalizationContext={"groups"={"reference-mandate-type:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"reference-mandate-type:write"}, "swagger_definition_name"="Write"},
* itemOperations={
* "get"
* },
* collectionOperations={
* "get",
*
* },
* attributes={
* "pagination_items_per_page"=10,
* "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
* }
* )
* @ORM\Entity(repositoryClass=ReferenceMandateTypeRepository::class)
*/
class ReferenceMandateType
{
public const TRANSLATION_DOMAIN = 'reference_mandate';
public const REFERENCE_MANDATE_TYPE_SIMPLE = 'reference.mandate.type.SIMPLE';
public const REFERENCE_MANDATE_TYPE_EXCLUSIVE = 'reference.mandate.type.EXCLUSIVE';
public const CODE_REFERENCE_MANDATE_TYPE_SIMPLE = '0';
public const CODE_REFERENCE_MANDATE_TYPE_EXCLUSIVE = '-1';
public const ALL_REFERENCE_MANDATE_TYPE = [self::REFERENCE_MANDATE_TYPE_SIMPLE, self::REFERENCE_MANDATE_TYPE_EXCLUSIVE];
public const ALL_CODE_REFERENCE_MANDATE_TYPE = [self::CODE_REFERENCE_MANDATE_TYPE_SIMPLE,self::CODE_REFERENCE_MANDATE_TYPE_EXCLUSIVE];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Groups({
* "mandate:read",
* "transaction-item:read",
* "reference-mandate-type:read"
* })
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*
* @Groups({
* "mandate:read",
* "transaction-item:read",
* "reference-mandate-type:read"
* })
*/
private ?string $name;
/**
* @ORM\Column(type="string", length=255)
*
* @Groups({
* "mandate:read",
* "transaction-item:read",
* "reference-mandate-type:read"
* })
*/
private ?string $code;
/**
* @ORM\OneToMany(targetEntity=Mandate::class, mappedBy="referenceMandateType")
*/
private $mandates;
public function __construct()
{
$this->mandates = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
/**
* @return Collection|Mandate[]
*/
public function getMandates(): Collection
{
return $this->mandates;
}
public function addMandate(Mandate $mandate): self
{
if (!$this->mandates->contains($mandate)) {
$this->mandates[] = $mandate;
$mandate->setReferenceMandateType($this);
}
return $this;
}
public function removeMandate(Mandate $mandate): self
{
if ($this->mandates->removeElement($mandate)) {
// set the owning side to null (unless already changed)
if ($mandate->getReferenceMandateType() === $this) {
$mandate->setReferenceMandateType(null);
}
}
return $this;
}
}