src/Entity/Location.php line 15

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\LocationRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=LocationRepository::class)
  9.  * @ORM\Table(name="location")
  10.  * @ORM\HasLifecycleCallbacks()
  11.  */
  12. class Location
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private ?int $id null;
  20.     /**
  21.      * @ORM\ManyToOne(targetEntity=City::class, inversedBy="locations")
  22.      * @ORM\JoinColumn(nullable=false)
  23.      */
  24.     private City $city;
  25.     /**
  26.      * @ORM\Column(type="string", length=150)
  27.      */
  28.     private string $name;
  29.     /**
  30.      * Armenian name (optional). Falls back to $name when empty.
  31.      * @ORM\Column(type="string", length=150, nullable=true)
  32.      */
  33.     private ?string $nameHy null;
  34.     /**
  35.      * Russian name (optional). Falls back to $name when empty.
  36.      * @ORM\Column(type="string", length=150, nullable=true)
  37.      */
  38.     private ?string $nameRu null;
  39.     /**
  40.      * @ORM\Column(type="string", length=170, unique=true)
  41.      */
  42.     private string $slug;
  43.     /**
  44.      * @ORM\Column(type="string", length=255, nullable=true)
  45.      */
  46.     private ?string $address null;
  47.     /**
  48.      * @ORM\Column(type="decimal", precision=10, scale=7, nullable=true)
  49.      */
  50.     private ?float $latitude null;
  51.     /**
  52.      * @ORM\Column(type="decimal", precision=10, scale=7, nullable=true)
  53.      */
  54.     private ?float $longitude null;
  55.     /**
  56.      * e.g. "museum", "landmark", "restaurant"
  57.      * @ORM\Column(type="string", length=50, nullable=true)
  58.      */
  59.     private ?string $category null;
  60.     /**
  61.      * @ORM\Column(type="boolean", options={"default": true})
  62.      */
  63.     private bool $isActive true;
  64.     /**
  65.      * @ORM\Column(type="datetime_immutable")
  66.      */
  67.     private \DateTimeImmutable $createdAt;
  68.     /**
  69.      * @ORM\Column(type="datetime_immutable", nullable=true)
  70.      */
  71.     private ?\DateTimeImmutable $updatedAt null;
  72.     /**
  73.      * @ORM\OneToMany(targetEntity=LocationDetail::class, mappedBy="location", cascade={"persist"}, orphanRemoval=true)
  74.      * @ORM\OrderBy({"sortOrder" = "ASC"})
  75.      */
  76.     private Collection $details;
  77.     public function __construct()
  78.     {
  79.         $this->details   = new ArrayCollection();
  80.         $this->createdAt = new \DateTimeImmutable();
  81.     }
  82.     /**
  83.      * @ORM\PreUpdate()
  84.      */
  85.     public function onPreUpdate(): void
  86.     {
  87.         $this->updatedAt = new \DateTimeImmutable();
  88.     }
  89.     public function getId(): ?int
  90.     {
  91.         return $this->id;
  92.     }
  93.     public function getCity(): City
  94.     {
  95.         return $this->city;
  96.     }
  97.     public function setCity(?City $city): self
  98.     {
  99.         $this->city $city;
  100.         return $this;
  101.     }
  102.     public function getName(): string
  103.     {
  104.         return $this->name;
  105.     }
  106.     public function setName(string $name): self
  107.     {
  108.         $this->name $name;
  109.         return $this;
  110.     }
  111.     public function getNameHy(): ?string
  112.     {
  113.         return $this->nameHy;
  114.     }
  115.     public function setNameHy(?string $nameHy): self
  116.     {
  117.         $this->nameHy $nameHy;
  118.         return $this;
  119.     }
  120.     public function getNameRu(): ?string
  121.     {
  122.         return $this->nameRu;
  123.     }
  124.     public function setNameRu(?string $nameRu): self
  125.     {
  126.         $this->nameRu $nameRu;
  127.         return $this;
  128.     }
  129.     public function getSlug(): string
  130.     {
  131.         return $this->slug;
  132.     }
  133.     public function setSlug(string $slug): self
  134.     {
  135.         $this->slug $slug;
  136.         return $this;
  137.     }
  138.     public function getAddress(): ?string
  139.     {
  140.         return $this->address;
  141.     }
  142.     public function setAddress(?string $address): self
  143.     {
  144.         $this->address $address;
  145.         return $this;
  146.     }
  147.     public function getLatitude(): ?float
  148.     {
  149.         return $this->latitude;
  150.     }
  151.     public function setLatitude(?float $latitude): self
  152.     {
  153.         $this->latitude $latitude;
  154.         return $this;
  155.     }
  156.     public function getLongitude(): ?float
  157.     {
  158.         return $this->longitude;
  159.     }
  160.     public function setLongitude(?float $longitude): self
  161.     {
  162.         $this->longitude $longitude;
  163.         return $this;
  164.     }
  165.     public function getCategory(): ?string
  166.     {
  167.         return $this->category;
  168.     }
  169.     public function setCategory(?string $category): self
  170.     {
  171.         $this->category $category;
  172.         return $this;
  173.     }
  174.     public function isActive(): bool
  175.     {
  176.         return $this->isActive;
  177.     }
  178.     public function setIsActive(bool $isActive): self
  179.     {
  180.         $this->isActive $isActive;
  181.         return $this;
  182.     }
  183.     public function getCreatedAt(): \DateTimeImmutable
  184.     {
  185.         return $this->createdAt;
  186.     }
  187.     public function getUpdatedAt(): ?\DateTimeImmutable
  188.     {
  189.         return $this->updatedAt;
  190.     }
  191.     public function getDetails(): Collection
  192.     {
  193.         return $this->details;
  194.     }
  195.     public function addDetail(LocationDetail $detail): self
  196.     {
  197.         if (!$this->details->contains($detail)) {
  198.             $this->details->add($detail);
  199.             $detail->setLocation($this);
  200.         }
  201.         return $this;
  202.     }
  203.     public function removeDetail(LocationDetail $detail): self
  204.     {
  205.         if ($this->details->removeElement($detail)) {
  206.             if ($detail->getLocation() === $this) {
  207.                 $detail->setLocation(null);
  208.             }
  209.         }
  210.         return $this;
  211.     }
  212.     public function __toString(): string
  213.     {
  214.         return ($this->title ?? '');
  215.     }
  216. }