src/CurrencyBundle/Entity/Currency.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\CurrencyBundle\Entity;
  3. use App\CurrencyBundle\Entity\Translation\CurrencyTranslation;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use PN\LocaleBundle\Model\LocaleTrait;
  8. use PN\LocaleBundle\Model\Translatable;
  9. use PN\ServiceBundle\Interfaces\DateTimeInterface;
  10. use PN\ServiceBundle\Model\DateTimeTrait;
  11. use PN\ServiceBundle\Model\VirtualDeleteTrait;
  12. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15. * @ORM\HasLifecycleCallbacks
  16. * @ORM\Table("currency")
  17. * @ORM\Entity(repositoryClass="App\CurrencyBundle\Repository\CurrencyRepository")
  18. * @UniqueEntity("code")
  19. */
  20. class Currency implements DateTimeInterface, Translatable
  21. {
  22. use VirtualDeleteTrait,
  23. DateTimeTrait,
  24. LocaleTrait;
  25. const EGP = 1;
  26. /**
  27. * @ORM\Id
  28. * @ORM\Column(name="id", type="integer")
  29. * @ORM\GeneratedValue(strategy="AUTO")
  30. */
  31. private ?int $id;
  32. /**
  33. * @Assert\NotBlank()
  34. * @ORM\Column(name="title", type="string", length=50)
  35. */
  36. private ?string $title;
  37. /**
  38. * @Assert\Currency()
  39. * @Assert\NotBlank()
  40. * @ORM\Column(name="code", type="string", length=3, unique=true)
  41. */
  42. private ?string $code;
  43. /**
  44. * @Assert\NotBlank()
  45. * @ORM\Column(name="symbol", type="string", length=255)
  46. */
  47. private ?string $symbol;
  48. /**
  49. * @ORM\Column(name="`default`", type="boolean")
  50. */
  51. private bool $default = false;
  52. /**
  53. * @ORM\OneToMany(targetEntity="App\CurrencyBundle\Entity\Translation\CurrencyTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
  54. */
  55. private Collection $translations;
  56. public function __construct()
  57. {
  58. $this->translations = new ArrayCollection();
  59. }
  60. public function __toString()
  61. {
  62. return $this->getTitle();
  63. }
  64. public function setId($id): self
  65. {
  66. $this->id = $id;
  67. return $this;
  68. }
  69. public function getId(): ?int
  70. {
  71. return $this->id;
  72. }
  73. public function getTitle(): ?string
  74. {
  75. return !$this->currentTranslation ? $this->title : $this->currentTranslation->getTitle();
  76. }
  77. public function getSymbol(): ?string
  78. {
  79. return !$this->currentTranslation ? $this->symbol : $this->currentTranslation->getSymbol();
  80. }
  81. public function setTitle(string $title): self
  82. {
  83. $this->title = $title;
  84. return $this;
  85. }
  86. public function getCode(): ?string
  87. {
  88. return $this->code;
  89. }
  90. public function setCode(string $code): self
  91. {
  92. $this->code = $code;
  93. return $this;
  94. }
  95. public function setSymbol(string $symbol): self
  96. {
  97. $this->symbol = $symbol;
  98. return $this;
  99. }
  100. public function isDefault(): ?bool
  101. {
  102. return $this->default;
  103. }
  104. public function setDefault(bool $default): self
  105. {
  106. $this->default = $default;
  107. return $this;
  108. }
  109. /**
  110. * @return Collection|CurrencyTranslation[]
  111. */
  112. public function getTranslations(): Collection
  113. {
  114. return $this->translations;
  115. }
  116. public function addTranslation(CurrencyTranslation $translation): self
  117. {
  118. if (!$this->translations->contains($translation)) {
  119. $this->translations[] = $translation;
  120. $translation->setTranslatable($this);
  121. }
  122. return $this;
  123. }
  124. public function removeTranslation(CurrencyTranslation $translation): self
  125. {
  126. if ($this->translations->removeElement($translation)) {
  127. // set the owning side to null (unless already changed)
  128. if ($translation->getTranslatable() === $this) {
  129. $translation->setTranslatable(null);
  130. }
  131. }
  132. return $this;
  133. }
  134. }