← Back
Editing: Adresse.php
<?php namespace App\Entity; use App\Contract\PersistableUserInterface; use App\Repository\AdresseRepository; use App\Solution\Annotation\SolutionAware; use App\Solution\SolutionTrait; use App\Validator as CustomAssert; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\SerializedName; use Symfony\Component\Validator\Constraints as Assert; /** * @SolutionAware(solutionFieldName="solution_id") */ #[ORM\Table(name: 'adresse')] #[ORM\Index(columns: ['agency_id'], name: 'IDX_C35F081619EB6921')] #[ORM\Index(columns: ['manager_id'])] #[ORM\Index(columns: ['manager_id', 'solution_id'])] #[ORM\Index(columns: ['ville'], name: 'city')] #[ORM\Entity(repositoryClass: AdresseRepository::class)] #[CustomAssert\ItemsForAddress] class Adresse { use SolutionTrait; #[ORM\Column(name: 'id', type: 'integer', nullable: false)] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[Groups([ 'session', 'show_address', 'show_address_detail', 'show_address_list', 'show_user', 'manager', 'show_reminder', 'supervisor_base', 'organization_base', ])] private ?int $id = null; #[ORM\Column(name: 'voie', type: 'string', length: 255, nullable: false)] #[Assert\Length(max: 255, maxMessage: 'La voie doit contenir au maximum {{ limit }} caractères')] #[Groups(['show_address', 'show_address_detail', 'show_address_list', 'manager', 'show_user'])] private string $voie; #[ORM\Column(name: 'numero', type: 'string', length: 8, nullable: true)] #[Assert\Length(max: 8, maxMessage: 'Le numéro doit contenir au maximum {{ limit }} caractères')] #[Groups(['show_address', 'show_address_detail', 'show_address_list', 'show_user', 'manager'])] private ?string $numero = null; #[ORM\Column(name: 'repetition', type: 'string', length: 10, nullable: true)] #[Assert\Length(max: 10, maxMessage: 'La répétition doit contenir au maximum {{ limit }} caractères')] #[Groups(['show_address', 'show_address_detail', 'manager', 'show_user', 'show_address_list'])] private ?string $repetition = null; #[ORM\Column(name: 'code_postal', type: 'string', length: 5, nullable: false)] #[Assert\Length(max: 5, maxMessage: 'Le code postal doit contenir au maximum {{ limit }} caractères')] #[Groups(['show_address', 'show_address_detail', 'show_user', 'show_address_list'])] private string $codePostal; #[ORM\Column(name: 'ville', type: 'string', length: 255, nullable: false)] #[Groups(['show_address', 'show_address_detail', 'show_user', 'show_address_list'])] private string $ville; #[ORM\Column(name: 'batiment', type: 'string', length: 255, nullable: true)] #[Groups(['show_address', 'show_address_detail', 'show_user', 'show_address_list'])] private ?string $batiment = null; #[ORM\Column(name: 'residence', type: 'string', length: 255, nullable: true)] #[Groups(['show_address', 'show_address_detail', 'show_user', 'show_address_list'])] private ?string $residence = null; /** @todo Replace batiment by code programme */ #[ORM\Column(type: 'string', nullable: true)] #[Groups(['show_address', 'show_address_detail', 'show_user', 'show_address_list'])] private ?string $codeProgramme = null; #[ORM\Column(type: 'string', nullable: true)] #[Groups(['show_address', 'show_address_detail', 'show_user', 'show_address_list'])] private ?string $numeroAscenseur = null; #[ORM\Column(name: 'ascenseur_is_active', type: 'boolean', nullable: false)] #[Groups(['show_address', 'show_address_detail', 'show_user'])] private bool $ascenseurIsActive = true; #[ORM\Column(name: 'start_date_inactive', type: 'datetime', nullable: true)] #[Groups(['show_address', 'show_address_detail', 'show_user'])] private ?\DateTimeInterface $startDateInactive = null; #[ORM\JoinColumn(onDelete: 'CASCADE')] #[ORM\ManyToOne(targetEntity: 'Agency', inversedBy: 'adresses')] private ?Agency $agency = null; #[ORM\ManyToOne(targetEntity: 'User', inversedBy: 'managerAddresses')] #[ORM\JoinColumn(name: 'manager_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')] private ?PersistableUserInterface $manager = null; /** * @var Collection<array-key, Item> */ #[ORM\JoinTable(name: 'tl_adresse_item')] #[ORM\JoinColumn(name: 'adresse_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\InverseJoinColumn(name: 'item_id', referencedColumnName: 'id')] #[ORM\ManyToMany(targetEntity: 'Item', inversedBy: 'adresses')] #[Groups(['show_address', 'show_address_detail', 'show_user'])] private Collection $items; /** * @var Collection<array-key, Prestataire> */ #[ORM\JoinTable(name: 'tl_adresse_prestataire')] #[ORM\JoinColumn(name: 'adresse_id', referencedColumnName: 'id', onDelete: 'CASCADE')] #[ORM\InverseJoinColumn(name: 'prestataire_id', referencedColumnName: 'id')] #[ORM\ManyToMany(targetEntity: 'Prestataire', inversedBy: 'adresses')] private Collection $prestataires; /** * @var Collection<array-key, Controle> */ #[ORM\OneToMany(mappedBy: 'adresse', targetEntity: 'Controle', cascade: ['persist'])] private Collection $controles; /** * @var Collection<array-key, ElevatorBreakdown> */ #[ORM\OneToMany(mappedBy: 'adresse', targetEntity: ElevatorBreakdown::class, cascade: ['remove'])] private Collection $elevatorBreakdowns; private bool $notifyBreakdown = true; /** * @var Collection<array-key, User> */ #[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'addressesAccess')] private Collection $usersAccess; /** * @var Collection<array-key, AddressReminder> */ #[ORM\OneToMany(mappedBy: 'address', targetEntity: AddressReminder::class)] private Collection $addressReminders; private string $addressString = ''; /** * @var Collection<array-key, UserAddress> */ #[ORM\OneToMany(mappedBy: 'address', targetEntity: UserAddress::class, cascade: [ 'persist', 'remove', ], orphanRemoval: true)] private Collection $userAddresses; #[ORM\Column(type: 'decimal', precision: 10, scale: 8, nullable: true)] private ?string $lat = null; #[ORM\Column(type: 'decimal', precision: 11, scale: 8, nullable: true)] private ?string $lng = null; #[ORM\ManyToMany(targetEntity: ControlTemplate::class, mappedBy: 'adresses')] private Collection $controlTemplates; /** * Constructor. */ public function __construct() { $this->items = new ArrayCollection(); $this->prestataires = new ArrayCollection(); $this->controles = new ArrayCollection(); $this->elevatorBreakdowns = new ArrayCollection(); $this->usersAccess = new ArrayCollection(); $this->addressReminders = new ArrayCollection(); $this->userAddresses = new ArrayCollection(); $this->controlTemplates = new ArrayCollection(); } public function getId(): ?int { return $this->id; } /** * @return $this */ public function setId($id): self { $this->id = $id; return $this; } public function getVoie(): ?string { return $this->voie; } /** * @return $this */ public function setVoie(string $voie): self { $this->voie = $voie; return $this; } public function getNumero(): ?string { return $this->numero; } /** * @return $this */ public function setNumero(?string $numero): self { $this->numero = $numero; return $this; } public function getRepetition(): ?string { return $this->repetition; } /** * @return $this */ public function setRepetition(?string $repetition): self { $this->repetition = $repetition; return $this; } public function getCodePostal(): ?string { return $this->codePostal; } /** * @return $this */ public function setCodePostal(string $codePostal): self { $this->codePostal = $codePostal; return $this; } public function getVille(): ?string { return $this->ville; } /** * @return $this */ public function setVille(string $ville): self { $this->ville = $ville; return $this; } public function getBatiment(): ?string { return $this->batiment; } public function setBatiment(?string $batiment): self { $this->batiment = $batiment; return $this; } public function getResidence(): ?string { return $this->residence; } /** * @return $this */ public function setResidence(?string $residence): self { $this->residence = $residence; return $this; } public function getAscenseurIsActive(): ?bool { return $this->ascenseurIsActive; } /** * @return $this */ public function setAscenseurIsActive(bool $ascenseurIsActive): self { $this->ascenseurIsActive = $ascenseurIsActive; return $this; } public function getStartDateInactive(): ?\DateTimeInterface { return $this->startDateInactive; } public function setStartDateInactive(?\DateTimeInterface $date): self { $this->startDateInactive = $date; return $this; } public function getAgency(): ?Agency { return $this->agency; } public function setAgency(?Agency $agency): self { $this->agency = $agency; return $this; } public function getMainAgent(): ?User { foreach ($this->userAddresses as $userAddress) { if (in_array('ROLE_AGENT', $userAddress->getUser()->getArrayRoles())) { return $userAddress->getUser(); } } return null; } /** * @return Collection<array-key, Item> */ public function getItems(): Collection { return $this->items; } /** * @return $this */ public function addItem(Item $item): self { if (!$this->items->contains($item)) { $this->items[] = $item; } return $this; } public function removeItem(Item $item): self { if ($this->items->contains($item)) { $this->items->removeElement($item); } return $this; } /** * @return Collection<array-key, Prestataire> */ public function getPrestataires(): Collection { return $this->prestataires; } public function addPrestataire(Prestataire $prestataire): self { if (!$this->prestataires->contains($prestataire)) { $this->prestataires[] = $prestataire; } return $this; } public function removePrestataire(Prestataire $prestataire): self { if ($this->prestataires->contains($prestataire)) { $this->prestataires->removeElement($prestataire); } return $this; } public function getControles(): ?Collection { return $this->controles; } /** * @return $this */ public function addControle(Controle $controle): self { if (!$this->controles->contains($controle)) { $this->controles[] = $controle; } return $this; } /** * @return $this */ public function removeControle(Controle $controle): self { if ($this->controles->contains($controle)) { $this->controles->removeElement($controle); } return $this; } public function getElevatorBreakdowns(): Collection { return $this->elevatorBreakdowns; } /** * @return $this */ public function addElevatorBreakdown(ElevatorBreakdown $elevatorBreakdown): self { if (!$this->elevatorBreakdowns->contains($elevatorBreakdown)) { $this->elevatorBreakdowns[] = $elevatorBreakdown; $elevatorBreakdown->setAdresse($this); } return $this; } public function getLastElevatorBreakdown(): ?ElevatorBreakdown { $criteria = Criteria::create()->orderBy(['startDate' => Criteria::DESC])->setMaxResults(1); $result = $this->elevatorBreakdowns->matching($criteria); if ($result->count()) { return $result->first(); } return null; } public function isBreakdown(): bool { $lastBreakdown = $this->getLastElevatorBreakdown(); if ($lastBreakdown && !$lastBreakdown->getEndDate()) { return true; } return false; } public function getFullAddress(): string { return $this->getResidence().' '. $this->getNumero().' '. $this->getRepetition().' '. $this->getVoie().' '. $this->getCodePostal().' '. $this->getVille().' '. ($this->getBatiment() ? ', Code programme : '.$this->getBatiment() : ''). ($this->getNumeroAscenseur() ? ' Ascenseur '.$this->getNumeroAscenseur() : ''); } public function getCodeProgramme(): ?string { return $this->codeProgramme; } /** * @return $this */ public function setCodeProgramme(?string $codeProgramme): self { $this->codeProgramme = $codeProgramme; return $this; } public function getNumeroAscenseur(): ?string { return $this->numeroAscenseur; } /** * @deprecated Replace app with numeroAscenseur */ #[Groups(['show_address', 'show_address_detail', 'show_user', 'show_address_list'])] public function getNumeroAscenceur(): ?string { return $this->numeroAscenseur; } /** * @return $this */ public function setNumeroAscenseur(?string $numeroAscenseur): self { $this->numeroAscenseur = $numeroAscenseur; return $this; } public function isNotifyBreakdown(): bool { return $this->notifyBreakdown; } public function setNotifyBreakdown(bool $notifyBreakdown): void { $this->notifyBreakdown = $notifyBreakdown; } public function __toString(): string { return $this->getAddressString(); } #[Groups(['show_reminder'])] #[SerializedName('address_string')] public function getAddressString(): string { if (!$this->addressString) { $address = $this->getNumero().' '.$this->getRepetition().''.$this->getVoie().' '.$this->getCodePostal( ).' '.$this->getVille(); if ($this->getNumeroAscenseur()) { $address .= ' asc. '.$this->getNumeroAscenseur(); } if ($this->getBatiment()) { $address .= ' bat. '.$this->getBatiment(); } if ($this->getResidence()) { $address .= ' res. '.$this->getResidence(); } $this->addressString = preg_replace('/\s+/', ' ', $address); } return $this->addressString; } public function getUsersAccess(): Collection { return $this->usersAccess; } /** * @return $this */ public function addUsersAccess(User $usersAccess): self { if (!$this->usersAccess->contains($usersAccess)) { $this->usersAccess[] = $usersAccess; $usersAccess->addAddressesAccess($this); } return $this; } /** * @return $this */ public function removeUsersAccess(User $usersAccess): self { if ($this->usersAccess->removeElement($usersAccess)) { $usersAccess->removeAddressesAccess($this); } return $this; } public function getAddressReminders(): Collection { return $this->addressReminders; } /** * @return $this */ public function addAddressReminder(AddressReminder $addressReminder): self { if (!$this->addressReminders->contains($addressReminder)) { $this->addressReminders[] = $addressReminder; $addressReminder->setAddress($this); } return $this; } /** * @return $this */ public function removeAddressReminder(AddressReminder $addressReminder): self { if ($this->addressReminders->removeElement($addressReminder)) { // set the owning side to null (unless already changed) if ($addressReminder->getAddress() === $this) { $addressReminder->setAddress(null); } } return $this; } /** * @return Collection<array-key, UserAddress> */ public function getUserAddresses(): Collection { return $this->userAddresses; } public function containsAgent(User $agent): bool { foreach ($this->getUserAddresses() as $userAddress) { if ($userAddress->getUser()->getId() === $agent->getId()) { return true; } } return false; } /** * @return ArrayCollection|Collection */ public function getValidControls() { $criteria = Criteria::create(); $criteria->andWhere(Criteria::expr()->eq('valide', true)); return $this->controles->matching($criteria); } public function getManager(): ?PersistableUserInterface { return $this->manager; } public function setManager(?PersistableUserInterface $manager): self { $this->manager = $manager; return $this; } public function getLat(): ?string { return $this->lat; } public function setLat(?string $lat): self { $this->lat = $lat; return $this; } public function getLng(): ?string { return $this->lng; } public function setLng(?string $lng): self { $this->lng = $lng; return $this; } /** * @return Collection<int, ControlTemplate> */ public function getControlTemplates(): Collection { return $this->controlTemplates; } public function addControlTemplate(ControlTemplate $controlTemplate): self { if (!$this->controlTemplates->contains($controlTemplate)) { $this->controlTemplates[] = $controlTemplate; $controlTemplate->addAdress($this); } return $this; } public function removeControlTemplate(ControlTemplate $controlTemplate): self { if ($this->controlTemplates->removeElement($controlTemplate)) { $controlTemplate->removeAdress($this); } return $this; } public function isAscenseurIsActive(): ?bool { return $this->ascenseurIsActive; } public function removeElevatorBreakdown(ElevatorBreakdown $elevatorBreakdown): self { if ($this->elevatorBreakdowns->removeElement($elevatorBreakdown)) { // set the owning side to null (unless already changed) if ($elevatorBreakdown->getAdresse() === $this) { $elevatorBreakdown->setAdresse(null); } } return $this; } public function addUserAddress(UserAddress $userAddress): self { if (!$this->userAddresses->contains($userAddress)) { $userAddress->setAddress($this); $this->userAddresses->add($userAddress); } return $this; } public function clearUserAddresses(): self { $this->userAddresses->clear(); return $this; } public function removeUserAddress(UserAddress $userAddress): self { if ($this->userAddresses->removeElement($userAddress)) { // set the owning side to null (unless already changed) if ($userAddress->getAddress() === $this) { $userAddress->setAddress(null); } } return $this; } /** * @return Thematic[] */ public function getThematics(): array { /** @var Collection<array-key, Zone> $zones */ $zones = new ArrayCollection(); foreach ($this->getItems() as $item) { $zone = $item->getZone(); if (null !== $zone) { $zones->add($zone); } } return Thematic::getFromZones($zones); } }
Save File
Cancel