<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\CurrencyRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ApiResource(
* security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* normalizationContext={"groups"={"currency:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"currency: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=CurrencyRepository::class)
*/
class Currency
{
public const DEFAULT_CURRENCY = 'MAD';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\Column(type="string", length=255)
*/
private ?string $name = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $symbol = null;
/**
* @ORM\OneToMany(targetEntity=Country::class, mappedBy="currency")
*/
private ?Collection $countries = null;
public function __construct()
{
$this->countries = 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;
}
/**
* @return string|null
*/
public function getSymbol(): ?string
{
return $this->symbol;
}
/**
* @param string|null $symbol
*
* @return $this
*/
public function setSymbol(?string $symbol): self
{
$this->symbol = $symbol;
return $this;
}
/**
* @return Collection|Country[]
*/
public function getCountries(): Collection
{
return $this->countries;
}
public function addCountry(Country $country): self
{
if (!$this->countries->contains($country)) {
$this->countries[] = $country;
$country->setCurrency($this);
}
return $this;
}
public function removeCountry(Country $country): self
{
// set the owning side to null (unless already changed)
if ($this->countries->removeElement($country) && $country->getCurrency() === $this) {
$country->setCurrency(null);
}
return $this;
}
}