<?php
namespace App\Entity\Eg\Osm;
use App\Entity\Eg\Admin\User;
use App\Entity\Eg\Traits\ColorTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
#[ORM\Table(name: 'eg_osm_organizations')]
#[ORM\Entity]
#[Gedmo\SoftDeleteable]
#[ORM\HasLifecycleCallbacks]
class Organization
{
// TODO: po co tutaj kolumna default_parking ?? skoro to organizacja - najwyzszy poziom hierarchi
// kolumna license_expires_at też jakas pozostalosc po starym kodzie a nie wyglada na uzywana
use ColorTrait;
use SoftDeleteableEntity;
public const SYSTEMEG_GROUP = 'SystemEG Group';
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(name: 'licence_expires_at', type: 'date', nullable: true)]
private ?\DateTimeInterface $licenceExpiresAt = null;
#[ORM\Column(name: 'name', type: 'string', length: 255)]
private string $name;
#[ORM\ManyToOne(inversedBy: 'organizations')]
private ?ParkingType $defaultParkingType = null;
/** @var Collection<int, User> */
#[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'organizations')]
#[ORM\JoinTable(name: 'eg_admin_user_organization_join')]
private Collection $users;
/** @var Collection<int, City> */
#[ORM\ManyToMany(targetEntity: City::class, inversedBy: 'organizations')]
#[ORM\JoinTable(name: 'eg_osm_organizations_cities_join')]
private Collection $cities;
/** @var Collection<int, Zone> */
#[ORM\OneToMany(targetEntity: Zone::class, mappedBy: 'organization')]
#[ORM\OrderBy(['name' => 'ASC'])]
private Collection $zones;
/** @var Collection<int, Credentials> */
#[ORM\OneToMany(targetEntity: Credentials::class, mappedBy: 'organization')]
private Collection $credentials;
#[ORM\PreRemove]
public function detachZonesOnSoftDelete(): void
{
foreach ($this->getZones() as $zone) {
$zone->setOrganization(null);
}
}
public function __construct()
{
$this->users = new ArrayCollection();
$this->cities = new ArrayCollection();
$this->zones = new ArrayCollection();
$this->credentials = new ArrayCollection();
$this->setColor('#dddd00');
}
public function __toString(): string
{
return $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function getLicenceExpiresAt(): ?\DateTimeInterface
{
return $this->licenceExpiresAt;
}
public function setLicenceExpiresAt(?\DateTimeInterface $licenceExpiresAt): self
{
$this->licenceExpiresAt = $licenceExpiresAt;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDefaultParkingType(): ?ParkingType
{
return $this->defaultParkingType;
}
public function setDefaultParkingType(?ParkingType $defaultParkingType): static
{
$this->defaultParkingType = $defaultParkingType;
return $this;
}
/** @return Collection<int, User> */
public function getUsers(): Collection
{
return $this->users;
}
/**
* @return Collection<int, City>
*/
public function getCities(): Collection
{
return $this->cities;
}
public function addCity(City $city): self
{
if (!$this->cities->contains($city)) {
$this->cities[] = $city;
}
return $this;
}
public function removeCity(City $city): self
{
$this->cities->removeElement($city);
return $this;
}
/**
* @return Collection<int, Zone>
*/
public function getZones(): Collection
{
return $this->zones;
}
public function addZone(Zone $zone): self
{
if (!$this->zones->contains($zone)) {
$this->zones[] = $zone;
$zone->setOrganization($this);
}
return $this;
}
public function removeZone(Zone $zone): self
{
if ($this->zones->removeElement($zone)) {
// set the owning side to null (unless already changed)
if ($zone->getOrganization() === $this) {
$zone->setOrganization(null);
}
}
return $this;
}
/**
* @return Collection<int, Credentials>
*/
public function getCredentials(): Collection
{
return $this->credentials;
}
public function addCredential(Credentials $credential): self
{
if (!$this->credentials->contains($credential)) {
$this->credentials[] = $credential;
$credential->setOrganization($this);
}
return $this;
}
public function removeCredential(Credentials $credential): self
{
if ($this->credentials->removeElement($credential)) {
// set the owning side to null (unless already changed)
if ($credential->getOrganization() === $this) {
$credential->setOrganization(null);
}
}
return $this;
}
}