src/Entity/Eg/Osm/City.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Eg\Osm;
  3. use App\Entity\Eg\Admin\User;
  4. use App\Entity\Eg\Traits\ColorTrait;
  5. use App\Entity\Eg\Traits\ShapeTrait;
  6. use App\Repository\Eg\Osm\CityRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
  13. #[ORM\Table(name: 'eg_osm_cities')]
  14. #[ORM\Entity(repositoryClass: CityRepository::class)]
  15. #[Gedmo\SoftDeleteable]
  16. #[ORM\HasLifecycleCallbacks]
  17. class City
  18. {
  19.     use ColorTrait;
  20.     use ShapeTrait; // TODO: shape dla miast nie jest uzywany, do wywalenia - spr jeszcze piotrek/mateusz i z bazy sie wywali oni tez dostosuja swoje
  21.     // uzywa go tylko strefa i parking
  22.     // tak samo kolumna default_parking - czy musi byc dla organizacji skoro też miasta to mają?
  23.     use SoftDeleteableEntity;
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue(strategy: 'IDENTITY')]
  26.     #[ORM\Column(type: Types::INTEGER)]
  27.     private ?int $id = null;
  28.     #[ORM\Column(name: 'extent', type: Types::STRING, length: 255, nullable: true)]
  29.     private ?string $extent = null;
  30.     #[ORM\Column(name: 'name', type: Types::STRING, length: 255)]
  31.     private string $name;
  32.     #[ORM\Column(name: 'position_lon', type: Types::FLOAT, precision: 10, scale: 0, nullable: true)]
  33.     private ?float $positionLon = null;
  34.     #[ORM\Column(name: 'position_lat', type: Types::FLOAT, precision: 10, scale: 0, nullable: true)]
  35.     private ?float $positionLat = null;
  36.     #[ORM\Column(name: 'cpa_hash', type: Types::STRING, length: 5, nullable: true)]
  37.     private ?string $cpaHash = null;
  38.     #[ORM\ManyToOne(inversedBy: 'cities')]
  39.     private ?ParkingType $defaultParkingType = null;
  40.     /** @var Collection<int, User> */
  41.     #[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'cities')]
  42.     #[ORM\JoinTable(name: 'eg_osm_user_city_join')]
  43.     private Collection $users;
  44.     /** @var Collection<int, Organization> */
  45.     #[ORM\ManyToMany(targetEntity: Organization::class, mappedBy: 'cities')]
  46.     #[ORM\JoinTable(name: 'eg_osm_organizations_cities_join')]
  47.     private Collection $organizations;
  48.     /** @var Collection<int, Zone> */
  49.     #[ORM\OneToMany(mappedBy: 'city', targetEntity: Zone::class)]
  50.     private Collection $zones;
  51.     public function __construct()
  52.     {
  53.         $this->users = new ArrayCollection();
  54.         $this->organizations = new ArrayCollection();
  55.         $this->zones = new ArrayCollection();
  56.         $this->setColor('#90ffa0');
  57.     }
  58.     public function __toString(): string
  59.     {
  60.         return $this->name;
  61.     }
  62.     public function getId(): ?int
  63.     {
  64.         return $this->id;
  65.     }
  66.     public function getExtent(): ?string
  67.     {
  68.         return $this->extent;
  69.     }
  70.     public function setExtent(?string $extent): self
  71.     {
  72.         $this->extent = $extent;
  73.         return $this;
  74.     }
  75.     public function getName(): ?string
  76.     {
  77.         return $this->name;
  78.     }
  79.     public function setName(string $name): self
  80.     {
  81.         $this->name = $name;
  82.         return $this;
  83.     }
  84.     public function getPositionLon(): ?float
  85.     {
  86.         return $this->positionLon;
  87.     }
  88.     public function setPositionLon(?float $positionLon): self
  89.     {
  90.         $this->positionLon = $positionLon;
  91.         return $this;
  92.     }
  93.     public function getPositionLat(): ?float
  94.     {
  95.         return $this->positionLat;
  96.     }
  97.     public function setPositionLat(?float $positionLat): self
  98.     {
  99.         $this->positionLat = $positionLat;
  100.         return $this;
  101.     }
  102.     public function getCpaHash(): ?string
  103.     {
  104.         return $this->cpaHash;
  105.     }
  106.     public function setCpaHash(?string $cpaHash): self
  107.     {
  108.         $this->cpaHash = $cpaHash;
  109.         return $this;
  110.     }
  111.     public function getDefaultParkingType(): ?ParkingType
  112.     {
  113.         return $this->defaultParkingType;
  114.     }
  115.     public function setDefaultParkingType(?ParkingType $defaultParkingType): static
  116.     {
  117.         $this->defaultParkingType = $defaultParkingType;
  118.         return $this;
  119.     }
  120.     /**
  121.      * @return Collection<int, User>
  122.      */
  123.     public function getUsers(): Collection
  124.     {
  125.         return $this->users;
  126.     }
  127.     /**
  128.      * @return Collection<int, Organization>
  129.      */
  130.     public function getOrganizations(): Collection
  131.     {
  132.         return $this->organizations;
  133.     }
  134.     public function addOrganization(Organization $organization): self
  135.     {
  136.         if (!$this->organizations->contains($organization)) {
  137.             $this->organizations[] = $organization;
  138.             $organization->addCity($this);
  139.         }
  140.         return $this;
  141.     }
  142.     public function removeOrganization(Organization $organization): self
  143.     {
  144.         if ($this->organizations->removeElement($organization)) {
  145.             $organization->removeCity($this);
  146.         }
  147.         return $this;
  148.     }
  149.     /**
  150.      * @return Collection<int, Zone>
  151.      */
  152.     public function getZones(): Collection
  153.     {
  154.         return $this->zones;
  155.     }
  156.     public function addZone(Zone $zone): static
  157.     {
  158.         if (!$this->zones->contains($zone)) {
  159.             $this->zones->add($zone);
  160.             $zone->setCity($this);
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeZone(Zone $zone): static
  165.     {
  166.         if ($this->zones->removeElement($zone)) {
  167.             // set the owning side to null (unless already changed)
  168.             if ($zone->getCity() === $this) {
  169.                 $zone->setCity(null);
  170.             }
  171.         }
  172.         return $this;
  173.     }
  174. }