src/Entity/Eg/Osm/Organization.php line 17

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 Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
  10. #[ORM\Table(name: 'eg_osm_organizations')]
  11. #[ORM\Entity]
  12. #[Gedmo\SoftDeleteable]
  13. #[ORM\HasLifecycleCallbacks]
  14. class Organization
  15. {
  16.     // TODO: po co tutaj kolumna default_parking ?? skoro to organizacja - najwyzszy poziom hierarchi
  17.     // kolumna license_expires_at też jakas pozostalosc po starym kodzie a nie wyglada na uzywana
  18.     use ColorTrait;
  19.     use SoftDeleteableEntity;
  20.     public const SYSTEMEG_GROUP = 'SystemEG Group';
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue(strategy: 'IDENTITY')]
  23.     #[ORM\Column(type: 'integer')]
  24.     private ?int $id = null;
  25.     #[ORM\Column(name: 'licence_expires_at', type: 'date', nullable: true)]
  26.     private ?\DateTimeInterface $licenceExpiresAt = null;
  27.     #[ORM\Column(name: 'name', type: 'string', length: 255)]
  28.     private string $name;
  29.     #[ORM\ManyToOne(inversedBy: 'organizations')]
  30.     private ?ParkingType $defaultParkingType = null;
  31.     /** @var Collection<int, User> */
  32.     #[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'organizations')]
  33.     #[ORM\JoinTable(name: 'eg_admin_user_organization_join')]
  34.     private Collection $users;
  35.     /** @var Collection<int, City> */
  36.     #[ORM\ManyToMany(targetEntity: City::class, inversedBy: 'organizations')]
  37.     #[ORM\JoinTable(name: 'eg_osm_organizations_cities_join')]
  38.     private Collection $cities;
  39.     /** @var Collection<int, Zone> */
  40.     #[ORM\OneToMany(targetEntity: Zone::class, mappedBy: 'organization')]
  41.     #[ORM\OrderBy(['name' => 'ASC'])]
  42.     private Collection $zones;
  43.     /** @var Collection<int, Credentials> */
  44.     #[ORM\OneToMany(targetEntity: Credentials::class, mappedBy: 'organization')]
  45.     private Collection $credentials;
  46.     #[ORM\PreRemove]
  47.     public function detachZonesOnSoftDelete(): void
  48.     {
  49.         foreach ($this->getZones() as $zone) {
  50.             $zone->setOrganization(null);
  51.         }
  52.     }
  53.     public function __construct()
  54.     {
  55.         $this->users = new ArrayCollection();
  56.         $this->cities = new ArrayCollection();
  57.         $this->zones = new ArrayCollection();
  58.         $this->credentials = new ArrayCollection();
  59.         $this->setColor('#dddd00');
  60.     }
  61.     public function __toString(): string
  62.     {
  63.         return $this->name;
  64.     }
  65.     public function getId(): ?int
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function getLicenceExpiresAt(): ?\DateTimeInterface
  70.     {
  71.         return $this->licenceExpiresAt;
  72.     }
  73.     public function setLicenceExpiresAt(?\DateTimeInterface $licenceExpiresAt): self
  74.     {
  75.         $this->licenceExpiresAt = $licenceExpiresAt;
  76.         return $this;
  77.     }
  78.     public function getName(): ?string
  79.     {
  80.         return $this->name;
  81.     }
  82.     public function setName(string $name): self
  83.     {
  84.         $this->name = $name;
  85.         return $this;
  86.     }
  87.     public function getDefaultParkingType(): ?ParkingType
  88.     {
  89.         return $this->defaultParkingType;
  90.     }
  91.     public function setDefaultParkingType(?ParkingType $defaultParkingType): static
  92.     {
  93.         $this->defaultParkingType = $defaultParkingType;
  94.         return $this;
  95.     }
  96.     /** @return Collection<int, User> */
  97.     public function getUsers(): Collection
  98.     {
  99.         return $this->users;
  100.     }
  101.     /**
  102.      * @return Collection<int, City>
  103.      */
  104.     public function getCities(): Collection
  105.     {
  106.         return $this->cities;
  107.     }
  108.     public function addCity(City $city): self
  109.     {
  110.         if (!$this->cities->contains($city)) {
  111.             $this->cities[] = $city;
  112.         }
  113.         return $this;
  114.     }
  115.     public function removeCity(City $city): self
  116.     {
  117.         $this->cities->removeElement($city);
  118.         return $this;
  119.     }
  120.     /**
  121.      * @return Collection<int, Zone>
  122.      */
  123.     public function getZones(): Collection
  124.     {
  125.         return $this->zones;
  126.     }
  127.     public function addZone(Zone $zone): self
  128.     {
  129.         if (!$this->zones->contains($zone)) {
  130.             $this->zones[] = $zone;
  131.             $zone->setOrganization($this);
  132.         }
  133.         return $this;
  134.     }
  135.     public function removeZone(Zone $zone): self
  136.     {
  137.         if ($this->zones->removeElement($zone)) {
  138.             // set the owning side to null (unless already changed)
  139.             if ($zone->getOrganization() === $this) {
  140.                 $zone->setOrganization(null);
  141.             }
  142.         }
  143.         return $this;
  144.     }
  145.     /**
  146.      * @return Collection<int, Credentials>
  147.      */
  148.     public function getCredentials(): Collection
  149.     {
  150.         return $this->credentials;
  151.     }
  152.     public function addCredential(Credentials $credential): self
  153.     {
  154.         if (!$this->credentials->contains($credential)) {
  155.             $this->credentials[] = $credential;
  156.             $credential->setOrganization($this);
  157.         }
  158.         return $this;
  159.     }
  160.     public function removeCredential(Credentials $credential): self
  161.     {
  162.         if ($this->credentials->removeElement($credential)) {
  163.             // set the owning side to null (unless already changed)
  164.             if ($credential->getOrganization() === $this) {
  165.                 $credential->setOrganization(null);
  166.             }
  167.         }
  168.         return $this;
  169.     }
  170. }