src/Entity/Subdivision.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SubdivisionRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. /**
  7. * @ORM\Entity(repositoryClass=SubdivisionRepository::class)
  8. * @ORM\HasLifecycleCallbacks()
  9. */
  10. class Subdivision
  11. {
  12. /**
  13. * @ORM\Id
  14. * @ORM\GeneratedValue
  15. * @ORM\Column(type="integer")
  16. */
  17. private $id;
  18. /**
  19. * @ORM\Column(type="string", length=255)
  20. */
  21. private $name;
  22. /**
  23. * @ORM\Column(type="text", nullable=true)
  24. */
  25. private $description;
  26. /**
  27. * @ORM\Column(type="datetime", nullable=true)
  28. */
  29. private $updateAt;
  30. /**
  31. * @ORM\ManyToOne(targetEntity=City::class, inversedBy="subdivisions")
  32. * @ORM\JoinColumn(nullable=false)
  33. * @Assert\NotBlank
  34. */
  35. private $city;
  36. /**
  37. * @ORM\OneToOne(targetEntity=Municipality::class, mappedBy="subdivision", cascade={"persist", "remove"})
  38. * @ORM\JoinColumn(nullable=true)
  39. */
  40. private $municipality;
  41. public function __construct() {
  42. $this->setUpdateAt(new \DateTime());
  43. }
  44. public function getId(): ?int
  45. {
  46. return $this->id;
  47. }
  48. public function getName(): ?string
  49. {
  50. return $this->name;
  51. }
  52. public function setName(string $name): self
  53. {
  54. $this->name = $name;
  55. return $this;
  56. }
  57. public function getDescription(): ?string
  58. {
  59. return $this->description;
  60. }
  61. public function setDescription(?string $description): self
  62. {
  63. $this->description = $description;
  64. return $this;
  65. }
  66. public function getUpdateAt(): ?\DateTimeInterface
  67. {
  68. return $this->updateAt;
  69. }
  70. public function setUpdateAt(?\DateTimeInterface $updateAt): self
  71. {
  72. $this->updateAt = $updateAt;
  73. return $this;
  74. }
  75. public function getCity(): ?City
  76. {
  77. return $this->city;
  78. }
  79. public function setCity(?City $city): self
  80. {
  81. $this->city = $city;
  82. return $this;
  83. }
  84. /**
  85. * @ORM\PreUpdate
  86. */
  87. public function __updateDate() {
  88. $this->setUpdateAt(new \DateTime());
  89. }
  90. public function getMunicipality(): ?Municipality
  91. {
  92. return $this->municipality;
  93. }
  94. public function setMunicipality(Municipality $municipality): self
  95. {
  96. $this->municipality = $municipality;
  97. // set the owning side of the relation if necessary
  98. if ($municipality->getSubdivision() !== $this) {
  99. $municipality->setSubdivision($this);
  100. }
  101. return $this;
  102. }
  103. public function __toString() {
  104. return $this->getName();
  105. }
  106. }