src/Entity/Currency.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\CurrencyRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ApiResource(
  10.  *     security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  11.  *     normalizationContext={"groups"={"currency:read"}, "swagger_definition_name"="Read"},
  12.  *     denormalizationContext={"groups"={"currency:write"}, "swagger_definition_name"="Write"},
  13.  *     itemOperations={
  14.  *          "get"
  15.  *     },
  16.  *     collectionOperations={
  17.  *           "get",
  18.  *
  19.  *     },
  20.  *     attributes={
  21.  *          "pagination_items_per_page"=10,
  22.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  23.  *     }
  24.  * )
  25.  * @ORM\Entity(repositoryClass=CurrencyRepository::class)
  26.  */
  27. class Currency
  28. {
  29.     public const DEFAULT_CURRENCY 'MAD';
  30.     /**
  31.      * @ORM\Id
  32.      * @ORM\GeneratedValue
  33.      * @ORM\Column(type="integer")
  34.      */
  35.     private ?int $id null;
  36.     /**
  37.      * @ORM\Column(type="string", length=255)
  38.      */
  39.     private ?string $name null;
  40.     /**
  41.      * @ORM\Column(type="string", length=255, nullable=true)
  42.      */
  43.     private ?string $symbol null;
  44.     /**
  45.      * @ORM\OneToMany(targetEntity=Country::class, mappedBy="currency")
  46.      */
  47.     private ?Collection $countries null;
  48.     public function __construct()
  49.     {
  50.         $this->countries = new ArrayCollection();
  51.     }
  52.     public function getId(): ?int
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function getName(): ?string
  57.     {
  58.         return $this->name;
  59.     }
  60.     public function setName(string $name): self
  61.     {
  62.         $this->name $name;
  63.         return $this;
  64.     }
  65.     /**
  66.      * @return string|null
  67.      */
  68.     public function getSymbol(): ?string
  69.     {
  70.         return $this->symbol;
  71.     }
  72.     /**
  73.      * @param string|null $symbol
  74.      *
  75.      * @return $this
  76.      */
  77.     public function setSymbol(?string $symbol): self
  78.     {
  79.         $this->symbol $symbol;
  80.         return $this;
  81.     }
  82.     /**
  83.      * @return Collection|Country[]
  84.      */
  85.     public function getCountries(): Collection
  86.     {
  87.         return $this->countries;
  88.     }
  89.     public function addCountry(Country $country): self
  90.     {
  91.         if (!$this->countries->contains($country)) {
  92.             $this->countries[] = $country;
  93.             $country->setCurrency($this);
  94.         }
  95.         return $this;
  96.     }
  97.     public function removeCountry(Country $country): self
  98.     {
  99.         // set the owning side to null (unless already changed)
  100.         if ($this->countries->removeElement($country) && $country->getCurrency() === $this) {
  101.             $country->setCurrency(null);
  102.         }
  103.         return $this;
  104.     }
  105. }