src/Core/Entity/State.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Core\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. /**
  8. * @ORM\Entity(repositoryClass="App\Core\Repository\StateRepository")
  9. */
  10. class State
  11. {
  12. /**
  13. * @ORM\Id()
  14. * @ORM\GeneratedValue()
  15. * @ORM\Column(type="integer")
  16. * @Groups("main")
  17. */
  18. private $id;
  19. /**
  20. * @ORM\Column(type="string", length=50)
  21. * @Groups("main")
  22. */
  23. private $nombre;
  24. /**
  25. * @ORM\OneToMany(targetEntity="App\Core\Entity\City", mappedBy="state")
  26. */
  27. private $cities;
  28. /**
  29. * @ORM\ManyToOne(targetEntity="App\Core\Entity\Country", inversedBy="states")
  30. */
  31. private $country;
  32. public function __construct()
  33. {
  34. $this->cities = new ArrayCollection();
  35. }
  36. public function getId(): ?int
  37. {
  38. return $this->id;
  39. }
  40. public function getNombre(): ?string
  41. {
  42. return $this->nombre;
  43. }
  44. public function setNombre(string $nombre): self
  45. {
  46. $this->nombre = $nombre;
  47. return $this;
  48. }
  49. /**
  50. * @return Collection|City[]
  51. */
  52. public function getCities(): Collection
  53. {
  54. return $this->cities;
  55. }
  56. public function addCity(City $city): self
  57. {
  58. if (!$this->cities->contains($city)) {
  59. $this->cities[] = $city;
  60. $city->setState($this);
  61. }
  62. return $this;
  63. }
  64. public function removeCity(City $city): self
  65. {
  66. if ($this->cities->contains($city)) {
  67. $this->cities->removeElement($city);
  68. // set the owning side to null (unless already changed)
  69. if ($city->getState() === $this) {
  70. $city->setState(null);
  71. }
  72. }
  73. return $this;
  74. }
  75. public function getCountry(): ?Country
  76. {
  77. return $this->country;
  78. }
  79. public function setCountry(?Country $country): self
  80. {
  81. $this->country = $country;
  82. return $this;
  83. }
  84. }