← Back
Editing: Agency.php
<?php namespace App\Entity; use App\Entity\Traits\ActivableTrait; use App\Enum\AgencyPermission; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; #[ORM\Table(name: 'agency')] #[ORM\Entity] #[UniqueEntity('email')] class Agency { use ActivableTrait; #[ORM\Column(name: 'id', type: 'integer', nullable: false)] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[Groups(['show_user', 'session', 'organization_base'])] private ?int $id = null; #[ORM\Column(name: 'nom', type: 'string', length: 255, nullable: false)] #[Assert\NotBlank] #[Groups(['show_user', 'supervisor_base', 'organization_base'])] private string $nom; #[ORM\Column(name: 'email', type: 'string', length: 255, nullable: true)] #[Assert\Email] #[Groups(['show_user'])] private ?string $email = null; #[ORM\Column(name: 'telephone_fixe', type: 'string', length: 255, nullable: true)] #[Groups(['show_user'])] private ?string $telephoneFixe = null; #[ORM\Column(name: 'logo', type: 'string', length: 255, nullable: true)] #[Groups(['show_user', 'supervisor_base', 'organization_base'])] private ?string $logo = null; #[ORM\Column(name: 'date_debut_contrat', type: 'date', nullable: true)] #[Groups(['show_user'])] private ?\DateTimeInterface $dateDebutContrat = null; #[ORM\Column(name: 'date_fin_contrat', type: 'date', nullable: true)] #[Groups(['show_user'])] private ?\DateTimeInterface $dateFinContrat = null; /** @deprecated */ #[ORM\Column(name: 'nombre_licence', type: 'integer', nullable: true)] #[Assert\Type(type: 'integer')] #[Groups(['show_user'])] private ?int $nombreLicence = null; #[ORM\Column(name: 'nom_contact', type: 'string', length: 255, nullable: true)] #[Groups(['show_user'])] private ?string $nomContact = null; #[ORM\Column(name: 'prenom_contact', type: 'string', length: 255, nullable: true)] #[Groups(['show_user'])] private ?string $prenomContact = null; #[ORM\Column(name: 'mail_contact', type: 'string', length: 255, nullable: true)] #[Assert\Email] #[Groups(['show_user'])] private ?string $mailContact = null; #[ORM\Column(name: 'telephone_contact', type: 'string', length: 255, nullable: true)] #[Groups(['show_user'])] private ?string $telephoneContact = null; #[ORM\Column(name: 'photo_obligatoire_contact', type: 'boolean', nullable: true)] #[Assert\Type(type: 'bool')] #[Groups(['show_user'])] private ?bool $photoObligatoireContact = null; #[ORM\OneToMany(mappedBy: 'agency', targetEntity: User::class)] #[Groups(['supervisor_agent'])] private Collection $users; #[ORM\ManyToMany(targetEntity: 'App\Entity\Solution')] #[Groups(['supervisor_base', 'organization_base'])] private Collection $solutions; #[ORM\OneToMany(mappedBy: 'agency', targetEntity: Adresse::class, cascade: ['remove'])] private Collection $adresses; #[ORM\OneToMany(mappedBy: 'agency', targetEntity: AgencyPrestataire::class)] private Collection $prestas; #[ORM\OneToMany(mappedBy: 'agency', targetEntity: PenaltyTemplate::class)] private Collection $penaltyTemplates; #[ORM\OneToOne(mappedBy: 'agency', targetEntity: SettlementTemplate::class, cascade: ['all'])] private ?SettlementTemplate $settlementTemplate = null; /** @deprecated Replace with permissions */ #[ORM\Column(type: 'boolean', options: ['default' => 0])] private bool $hasServiceOption = false; #[ORM\ManyToOne(targetEntity: Organization::class, inversedBy: 'agencies')] #[Groups(['show_user'])] private ?Organization $organization = null; /** @var string[] $permissions */ #[ORM\Column(type: Types::SIMPLE_ARRAY, nullable: true)] #[Groups(['show_user'])] private array $permissions = []; #[ORM\Column(type: 'string', length: 255, nullable: true)] private ?string $letterHead = null; private bool $eraseLetterHead = false; #[ORM\ManyToMany(targetEntity: Item::class, inversedBy: 'agencies')] private Collection $defaultAddressItems; public function __construct() { $this->users = new ArrayCollection(); $this->solutions = new ArrayCollection(); $this->adresses = new ArrayCollection(); $this->prestas = new ArrayCollection(); $this->penaltyTemplates = new ArrayCollection(); $this->defaultAddressItems = new ArrayCollection(); } public function getId(): ?int { return $this->id; } /** * @return $this */ public function setId($id): self { $this->id = $id; return $this; } public function getNom(): ?string { return $this->nom; } public function setNom(string $nom): self { $this->nom = $nom; return $this; } public function getEmail(): ?string { return $this->email; } public function setEmail(?string $email): self { $this->email = $email; return $this; } public function getTelephoneFixe(): ?string { return $this->telephoneFixe; } public function setTelephoneFixe(?string $telephoneFixe): self { $this->telephoneFixe = $telephoneFixe; return $this; } public function getLogo(): ?string { return $this->logo; } public function setLogo(?string $logo): self { $this->logo = $logo; return $this; } public function getDateDebutContrat(): ?\DateTimeInterface { return $this->dateDebutContrat; } public function setDateDebutContrat(?\DateTimeInterface $dateDebutContrat): self { $this->dateDebutContrat = $dateDebutContrat; return $this; } public function getDateFinContrat(): ?\DateTimeInterface { return $this->dateFinContrat; } public function setDateFinContrat(?\DateTimeInterface $dateFinContrat): self { $this->dateFinContrat = $dateFinContrat; return $this; } public function getNombreLicence(): ?int { return $this->nombreLicence; } public function setNombreLicence(?int $nombreLicence): self { $this->nombreLicence = $nombreLicence; return $this; } public function getNomContact(): ?string { return $this->nomContact; } public function setNomContact(?string $nomContact): self { $this->nomContact = $nomContact; return $this; } public function getPrenomContact(): ?string { return $this->prenomContact; } public function setPrenomContact(?string $prenomContact): self { $this->prenomContact = $prenomContact; return $this; } public function getMailContact(): ?string { return $this->mailContact; } public function setMailContact(?string $mailContact): self { $this->mailContact = $mailContact; return $this; } public function getTelephoneContact(): ?string { return $this->telephoneContact; } public function setTelephoneContact(?string $telephoneContact): self { $this->telephoneContact = $telephoneContact; return $this; } public function getPhotoObligatoireContact(): ?bool { return $this->photoObligatoireContact; } public function setPhotoObligatoireContact(?bool $photoObligatoireContact): self { $this->photoObligatoireContact = $photoObligatoireContact; return $this; } /** * @return Collection<int, User>|null */ public function getUsers(): ?Collection { return $this->users; } public function addUser(User $user): self { if (!$this->users->contains($user)) { $this->users[] = $user; $user->setAgency($this); } return $this; } public function removeUser(User $user): self { if ($this->users->contains($user)) { $this->users->removeElement($user); // set the owning side to null (unless already changed) if ($user->getAgency() === $this) { $user->setAgency(null); } } return $this; } public function getSolutions(): ?Collection { return $this->solutions; } public function addSolution(Solution $solution): self { if (!$this->solutions->contains($solution)) { $this->solutions[] = $solution; } return $this; } public function removeSolution(Solution $solution): self { if ($this->solutions->contains($solution)) { $this->solutions->removeElement($solution); } return $this; } public function __sleep() { return []; } public function getAdresses(): Collection { return $this->adresses; } public function addAdress(Adresse $adress): self { if (!$this->adresses->contains($adress)) { $this->adresses[] = $adress; $adress->setAgency($this); } return $this; } public function removeAdress(Adresse $adress): self { if ($this->adresses->contains($adress)) { $this->adresses->removeElement($adress); // set the owning side to null (unless already changed) if ($adress->getAgency() === $this) { $adress->setAgency(null); } } return $this; } public function getPrestas(): Collection { return $this->prestas; } public function addPresta(AgencyPrestataire $presta): self { if (!$this->prestas->contains($presta)) { $this->prestas[] = $presta; $presta->setAgency($this); } return $this; } public function removePresta(AgencyPrestataire $presta): self { if ($this->prestas->contains($presta)) { $this->prestas->removeElement($presta); // set the owning side to null (unless already changed) if ($presta->getAgency() === $this) { $presta->setAgency(null); } } return $this; } /** * @return User[] */ #[Groups(['supervisor_agent'])] public function getAgents() { $criteria = Criteria::create() ->where(Criteria::expr()->contains('roles', 'ROLE_AGENT')); return $this->getUsers()->matching($criteria); } public function __toString(): string { return $this->getNom() ?? 'Sans nom'; } public function getPenaltyTemplates(): Collection { return $this->penaltyTemplates; } public function addPenaltyTemplate(PenaltyTemplate $penaltyTemplate): self { if (!$this->penaltyTemplates->contains($penaltyTemplate)) { $this->penaltyTemplates[] = $penaltyTemplate; $penaltyTemplate->setAgency($this); } return $this; } public function getSettlementTemplate(): ?SettlementTemplate { return $this->settlementTemplate; } public function setSettlementTemplate(?SettlementTemplate $settlementTemplate): self { // unset the owning side of the relation if necessary if (null === $settlementTemplate && null !== $this->settlementTemplate) { $this->settlementTemplate->setAgency(null); } // set the owning side of the relation if necessary if (null !== $settlementTemplate && $settlementTemplate->getAgency() !== $this) { $settlementTemplate->setAgency($this); } $this->settlementTemplate = $settlementTemplate; return $this; } /** @deprecated */ public function getHasServiceOption(): ?bool { return $this->hasServiceOption; } /** @deprecated */ public function setHasServiceOption(bool $hasServiceOption): self { $this->hasServiceOption = $hasServiceOption; return $this; } public function isPhotoObligatoireContact(): ?bool { return $this->photoObligatoireContact; } /** @deprecated */ public function isHasServiceOption(): ?bool { return $this->hasServiceOption; } public function getOrganization(): ?Organization { return $this->organization; } public function setOrganization(?Organization $organization): self { $this->organization = $organization; return $this; } public function removePenaltyTemplate(PenaltyTemplate $penaltyTemplate): self { if ($this->penaltyTemplates->removeElement($penaltyTemplate)) { // set the owning side to null (unless already changed) if ($penaltyTemplate->getAgency() === $this) { $penaltyTemplate->setAgency(null); } } return $this; } public function getLetterHead(): ?string { return $this->letterHead; } public function setLetterHead(?string $letterHead): self { $this->letterHead = $letterHead; return $this; } public function isEraseLetterHead(): bool { return $this->eraseLetterHead; } public function setEraseLetterHead(bool $eraseLetterHead): self { $this->eraseLetterHead = $eraseLetterHead; return $this; } /** * @return Collection<int, User> */ public function getManagers(): Collection { return $this->users->filter(fn (User $user) => in_array('ROLE_MANAGER', $user->getArrayRoles())); } public function getPermissions(): array { return $this->permissions; } public function setPermissions(array $permissions): self { $this->permissions = $permissions; return $this; } public function addPermission(AgencyPermission $permission): self { $this->permissions[] = $permission->value; return $this; } public function hasPermission(AgencyPermission $permission): bool { return in_array($permission->value, $this->permissions); } /** * @return Collection<int, Item> */ public function getDefaultAddressItems(): Collection { return $this->defaultAddressItems; } public function addDefaultAddressItem(Item $defaultAddressItem): static { if (!$this->defaultAddressItems->contains($defaultAddressItem)) { $this->defaultAddressItems->add($defaultAddressItem); } return $this; } public function removeDefaultAddressItem(Item $defaultAddressItem): static { $this->defaultAddressItems->removeElement($defaultAddressItem); return $this; } }
Save File
Cancel