<?phpnamespace App\Entity;use App\Repository\CityRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity(repositoryClass=CityRepository::class) * @ORM\HasLifecycleCallbacks() */class City{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $name; /** * @ORM\Column(type="text", nullable=true) */ private $description; /** * @ORM\Column(type="datetime", nullable=true) */ private $updateAt; /** * @ORM\ManyToOne(targetEntity=Department::class, inversedBy="cities", cascade ={"persist"}) * @ORM\JoinColumn(nullable=false) */ private $department; /** * @ORM\OneToMany(targetEntity=Subdivision::class, mappedBy="city", orphanRemoval=true) */ private $subdivisions; public function __construct() { $this->subdivisions = new ArrayCollection(); $this->setUpdateAt(new \DateTime()); } 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; } public function getDescription(): ?string { return $this->description; } public function setDescription(?string $description): self { $this->description = $description; return $this; } public function getUpdateAt(): ?\DateTimeInterface { return $this->updateAt; } public function setUpdateAt(?\DateTimeInterface $updateAt): self { $this->updateAt = $updateAt; return $this; } public function getDepartment(): ?Department { return $this->department; } public function setDepartment(?Department $department): self { $this->department = $department; return $this; } /** * @return Collection|Subdivision[] */ public function getSubdivisions(): Collection { return $this->subdivisions; } public function addSubdivision(Subdivision $subdivision): self { if (!$this->subdivisions->contains($subdivision)) { $this->subdivisions[] = $subdivision; $subdivision->setCity($this); } return $this; } public function removeSubdivision(Subdivision $subdivision): self { if ($this->subdivisions->contains($subdivision)) { $this->subdivisions->removeElement($subdivision); // set the owning side to null (unless already changed) if ($subdivision->getCity() === $this) { $subdivision->setCity(null); } } return $this; } public function __toString() { return $this->getName(); } /** * @ORM\PreUpdate */ public function __updateDate() { $this->setUpdateAt(new \DateTime()); }}