<?php
namespace App\Entity;
use App\Repository\ContactRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Serializer\Annotation\Ignore;
/**
* @ORM\Entity(repositoryClass=ContactRepository::class)
* @Vich\Uploadable
* @UniqueEntity(fields="email", message="Il existe déjà un utilisateur avec cet email")
*/
class Contact
{
const TYPE_CANDIDAT = "candidat";
const TYPE_EMPLOYE = "employé";
const TYPE_ENFANT = "enfant";
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $lastName;
/**
* @Ignore()
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $img;
/**
* @Ignore()
* @Vich\UploadableField(mapping="contact_image", fileNameProperty="img")
*
* @var File|null
*
*/
private ?File $imgFile = null;
/**
* @ORM\OneToOne(targetEntity=User::class, mappedBy="contact", cascade={"persist", "remove"})
*/
private $user;
/**
* @ORM\Column(type="json")
*/
private $type = [];
/**
* @ORM\OneToMany(targetEntity=ContactPropertyValue::class, mappedBy="contact",cascade={"persist","remove"})
*/
private $contactPropertyValues;
/**
* @ORM\Column(type="string", length=1, nullable=true)
*/
private $sexe;
/**
* @ORM\Column(type="boolean",options={"default": false})
*/
private $droitIlmg;
/**
* @ORM\ManyToOne(targetEntity=Location::class, inversedBy="contacts",cascade={"persist"})
*/
private $location;
/**
* @ORM\OneToMany(targetEntity=Inscription::class, mappedBy="enfant",cascade={"remove"})
*/
private $inscriptions;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $birthDate;
/**
* @ORM\OneToMany(targetEntity=Inscription::class, mappedBy="parent",cascade={"remove"})
*/
private $inscriptionParents;
/**
* @ORM\OneToMany(targetEntity=Equipier::class, mappedBy="contact")
*/
private $equipiers;
/**
* @ORM\OneToMany(targetEntity=SejourSessionEquipier::class, mappedBy="contact")
*/
private $sejourSessionEquipiers;
/**
* @ORM\Column(type="string", length=255, nullable=true, unique=true)
* @Assert\Email
*/
private $email;
/**
* @ORM\ManyToOne(targetEntity=Contact::class, inversedBy="children")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity=Contact::class, mappedBy="parent")
*/
private $children;
/**
* @ORM\OneToMany(targetEntity=Candidature::class, mappedBy="contact")
*/
private $candidatures;
/**
* @ORM\OneToMany(targetEntity=Compta::class, mappedBy="contact")
*/
private $comptas;
/**
* @ORM\OneToMany(targetEntity=Media::class, mappedBy="contact",cascade={"persist","remove"})
*/
private $medias;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $legacyId;
/**
* @ORM\OneToOne(targetEntity=Enterprise::class, mappedBy="contact", cascade={"persist", "remove"})
*/
private $enterprise;
/**
* @ORM\OneToMany(targetEntity=ContactComment::class, mappedBy="contact")
* @ORM\OrderBy({"createdDate" = "DESC"})
*
*/
private $contactComments;
/**
* @ORM\OneToMany(targetEntity=DemandeSejourCorse::class, mappedBy="contact")
*/
private $demandeSejourCorses;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $legacyPrefix;
/**
* @ORM\OneToMany(targetEntity=LegacyEmploye::class, mappedBy="contact")
*/
private $legacyEmployes;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $legacyProfessionelId;
/**
* @ORM\OneToMany(targetEntity=EmployeeContract::class, mappedBy="contact")
*/
private $employeeContracts;
/**
* @ORM\OneToMany(targetEntity=ReductionRequest::class, mappedBy="contact")
*/
private $reductionRequests;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\OneToMany(targetEntity=TiersDeConfiance::class, mappedBy="main")
*/
private $tiersDeConfiances;
/**
* @ORM\OneToMany(targetEntity=TiersDeConfiance::class, mappedBy="tiers")
*/
private $tiersDeConfianceRelations;
public function __construct()
{
$this->contactPropertyValues = new ArrayCollection();
$this->inscriptions = new ArrayCollection();
$this->inscriptionParents = new ArrayCollection();
$this->equipiers = new ArrayCollection();
$this->sejourSessionEquipiers = new ArrayCollection();
$this->children = new ArrayCollection();
$this->candidatures = new ArrayCollection();
$this->comptas = new ArrayCollection();
$this->medias = new ArrayCollection();
$this->contactComments = new ArrayCollection();
$this->demandeSejourCorses = new ArrayCollection();
$this->legacyEmployes = new ArrayCollection();
$this->employeeContracts = new ArrayCollection();
$this->reductionRequests = new ArrayCollection();
$this->tiersDeConfiances = new ArrayCollection();
$this->tiersDeConfianceRelations = new ArrayCollection();
$this->droitIlmg = false;
}
public function getOrderSejourSessionEquipiers(){
$sejourSessionEquipiers = $this->getSejourSessionEquipiers();
$output = [];
foreach($sejourSessionEquipiers as $sse){
$output[$sse->getSejourSession()->getDateDebut()->format('Ymd').$sse->getId()] = $sse;
}
return $output;
}
public function getId(): ?int
{
return $this->id;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = strtoupper($lastName);
return $this;
}
public function getImg(): ?string
{
return $this->img;
}
public function setImg(?string $img): self
{
$this->img = $img;
return $this;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImgFile(?File $imageFile = null): void
{
$this->imgFile = $imageFile;
if ($imageFile) {
$this->SetImg($imageFile->getFilename());
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedDate = new \DateTime('now');
}
}
public function getImgFile(): ?File
{
return $this->imgFile;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(User $user): self
{
// set the owning side of the relation if necessary
if ($user->getContact() !== $this) {
$user->setContact($this);
}
$this->user = $user;
return $this;
}
public function getType(): ?array
{
return $this->type;
}
public function setType(array $type): self
{
$this->type = $type;
return $this;
}
/**
* @return Collection|ContactPropertyValue[]
*/
public function getContactPropertyValues(): Collection
{
return $this->contactPropertyValues;
}
/**
* @return Collection|ContactPropertyValue[]
*/
public function getOrderedContactPropertyValues(): array
{
$cpvs = $this->getContactPropertyValues();
$output1 = ['Informations générales' => [],
'Mensurations' => [],
'Santé' => [],
'Contacts' => [],
];
foreach ($cpvs as $cpv) {
$output1[$cpv->getProperty()->getSubType()][] = $cpv;
}
foreach($output1 as $key => $value){
if(count($value)==0){
unset($output1[$key]);
}
}
foreach($output1 as $key => $value){
usort($value, function($a, $b) {
return $a->getProperty()->getPosition() > $b->getProperty()->getPosition();
});
$output1[$key] = $value;
}
return $output1;
}
public function addContactPropertyValue(ContactPropertyValue $contactPropertyValue): self
{
if (!$this->contactPropertyValues->contains($contactPropertyValue)) {
$this->contactPropertyValues[] = $contactPropertyValue;
$contactPropertyValue->setContact($this);
}
return $this;
}
public function removeContactPropertyValue(ContactPropertyValue $contactPropertyValue): self
{
if ($this->contactPropertyValues->removeElement($contactPropertyValue)) {
// set the owning side to null (unless already changed)
if ($contactPropertyValue->getContact() === $this) {
$contactPropertyValue->setContact(null);
}
}
return $this;
}
public function getSexe(): ?string
{
return $this->sexe;
}
public function setSexe(?string $Sexe): self
{
$this->sexe = $Sexe;
return $this;
}
public function getLocation(): ?Location
{
return $this->location;
}
public function setLocation(?Location $location): self
{
$this->location = $location;
return $this;
}
/**
* @return Collection|Inscription[]
*/
public function getInscriptions(): Collection
{
return $this->inscriptions;
}
public function addInscription(Inscription $inscription): self
{
if (!$this->inscriptions->contains($inscription)) {
$this->inscriptions[] = $inscription;
$inscription->setEnfant($this);
}
return $this;
}
public function removeInscription(Inscription $inscription): self
{
if ($this->inscriptions->removeElement($inscription)) {
// set the owning side to null (unless already changed)
if ($inscription->getEnfant() === $this) {
$inscription->setEnfant(null);
}
}
return $this;
}
public function getBirthDate(): ?\DateTimeInterface
{
return $this->birthDate;
}
public function setBirthDate(?\DateTimeInterface $birthDate): self
{
$this->birthDate = $birthDate;
return $this;
}
/**
* @return Collection|Inscription[]
*/
public function getInscriptionParents(): Collection
{
return $this->inscriptionParents;
}
public function addInscriptionParent(Inscription $inscriptionParent): self
{
if (!$this->inscriptionParents->contains($inscriptionParent)) {
$this->inscriptionParents[] = $inscriptionParent;
$inscriptionParent->setParent($this);
}
return $this;
}
public function removeInscriptionParent(Inscription $inscriptionParent): self
{
if ($this->inscriptionParents->removeElement($inscriptionParent)) {
// set the owning side to null (unless already changed)
if ($inscriptionParent->getParent() === $this) {
$inscriptionParent->setParent(null);
}
}
return $this;
}
/**
* @return Collection|Equipier[]
*/
public function getEquipiers(): Collection
{
return $this->equipiers;
}
public function addEquipier(Equipier $equipier): self
{
if (!$this->equipiers->contains($equipier)) {
$this->equipiers[] = $equipier;
$equipier->setContact($this);
}
return $this;
}
public function removeEquipier(Equipier $equipier): self
{
if ($this->equipiers->removeElement($equipier)) {
// set the owning side to null (unless already changed)
if ($equipier->getContact() === $this) {
$equipier->setContact(null);
}
}
return $this;
}
/**
* @return Collection|SejourSessionEquipier[]
*/
public function getSejourSessionEquipiers(): Collection
{
return $this->sejourSessionEquipiers;
}
public function addSejourSessionEquipier(SejourSessionEquipier $sejourSessionEquipier): self
{
if (!$this->sejourSessionEquipiers->contains($sejourSessionEquipier)) {
$this->sejourSessionEquipiers[] = $sejourSessionEquipier;
$sejourSessionEquipier->setContact($this);
}
return $this;
}
public function removeSejourSessionEquipier(SejourSessionEquipier $sejourSessionEquipier): self
{
if ($this->sejourSessionEquipiers->removeElement($sejourSessionEquipier)) {
// set the owning side to null (unless already changed)
if ($sejourSessionEquipier->getContact() === $this) {
$sejourSessionEquipier->setContact(null);
}
}
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
public function getDroitIlmg(): bool
{
return $this->droitIlmg;
}
public function setDroitIlmg(bool $droitIlmg): self
{
$this->droitIlmg = $droitIlmg;
return $this;
}
/**
* @return Collection|self[]
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(self $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(self $child): self
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
/**
* @return Collection|Candidature[]
*/
public function getCandidatures(): Collection
{
return $this->candidatures;
}
public function addCandidature(Candidature $candidature): self
{
if (!$this->candidatures->contains($candidature)) {
$this->candidatures[] = $candidature;
$candidature->setContact($this);
}
return $this;
}
public function removeCandidature(Candidature $candidature): self
{
if ($this->candidatures->removeElement($candidature)) {
// set the owning side to null (unless already changed)
if ($candidature->getContact() === $this) {
$candidature->setContact(null);
}
}
return $this;
}
/**
* @return Collection|Compta[]
*/
public function getComptas(): Collection
{
return $this->comptas;
}
public function addCompta(Compta $compta): self
{
if (!$this->comptas->contains($compta)) {
$this->comptas[] = $compta;
$compta->setContact($this);
}
return $this;
}
public function removeCompta(Compta $compta): self
{
if ($this->comptas->removeElement($compta)) {
// set the owning side to null (unless already changed)
if ($compta->getContact() === $this) {
$compta->setContact(null);
}
}
return $this;
}
/**
* @return Collection|Media[]
*/
public function getMedias(): Collection
{
return $this->medias;
}
public function addMedia(Media $media): self
{
if (!$this->medias->contains($media)) {
$this->medias[] = $media;
$media->setContact($this);
}
return $this;
}
public function removeMedia(Media $media): self
{
if ($this->medias->removeElement($media)) {
// set the owning side to null (unless already changed)
if ($media->getContact() === $this) {
$media->setContact(null);
}
}
return $this;
}
public function getLegacyId(): ?string
{
return $this->legacyId;
}
public function setLegacyId(?string $legacyId): self
{
$this->legacyId = $legacyId;
return $this;
}
public function getEnterprise(): ?Enterprise
{
return $this->enterprise;
}
public function setEnterprise(Enterprise $enterprise): self
{
// set the owning side of the relation if necessary
if ($enterprise->getContact() !== $this) {
$enterprise->setContact($this);
}
$this->enterprise = $enterprise;
return $this;
}
/**
* @return Collection|ContactComment[]
*/
public function getContactComments(): Collection
{
return $this->contactComments;
}
public function addContactComment(ContactComment $contactComment): self
{
if (!$this->contactComments->contains($contactComment)) {
$this->contactComments[] = $contactComment;
$contactComment->setContact($this);
}
return $this;
}
public function removeContactComment(ContactComment $contactComment): self
{
if ($this->contactComments->removeElement($contactComment)) {
// set the owning side to null (unless already changed)
if ($contactComment->getContact() === $this) {
$contactComment->setContact(null);
}
}
return $this;
}
/**
* @return Collection|DemandeSejourCorse[]
*/
public function getDemandeSejourCorses(): Collection
{
return $this->demandeSejourCorses;
}
public function addDemandeSejourCorse(DemandeSejourCorse $demandeSejourCorse): self
{
if (!$this->demandeSejourCorses->contains($demandeSejourCorse)) {
$this->demandeSejourCorses[] = $demandeSejourCorse;
$demandeSejourCorse->setContact($this);
}
return $this;
}
public function removeDemandeSejourCorse(DemandeSejourCorse $demandeSejourCorse): self
{
if ($this->demandeSejourCorses->removeElement($demandeSejourCorse)) {
// set the owning side to null (unless already changed)
if ($demandeSejourCorse->getContact() === $this) {
$demandeSejourCorse->setContact(null);
}
}
return $this;
}
public function getLegacyPrefix(): ?string
{
return $this->legacyPrefix;
}
public function setLegacyPrefix(?string $legacyPrefix): self
{
$this->legacyPrefix = $legacyPrefix;
return $this;
}
/**
* @return Collection|LegacyEmploye[]
*/
public function getLegacyEmployes(): Collection
{
return $this->legacyEmployes;
}
public function addLegacyEmploye(LegacyEmploye $legacyEmploye): self
{
if (!$this->legacyEmployes->contains($legacyEmploye)) {
$this->legacyEmployes[] = $legacyEmploye;
$legacyEmploye->setContact($this);
}
return $this;
}
public function removeLegacyEmploye(LegacyEmploye $legacyEmploye): self
{
if ($this->legacyEmployes->removeElement($legacyEmploye)) {
// set the owning side to null (unless already changed)
if ($legacyEmploye->getContact() === $this) {
$legacyEmploye->setContact(null);
}
}
return $this;
}
public function getLegacyProfessionelId(): ?int
{
return $this->legacyProfessionelId;
}
public function setLegacyProfessionelId(?int $legacyProfessionelId): self
{
$this->legacyProfessionelId = $legacyProfessionelId;
return $this;
}
/**
* @return Collection|EmployeeContract[]
*/
public function getEmployeeContracts(): Collection
{
return $this->employeeContracts;
}
public function addEmployeeContract(EmployeeContract $employeeContract): self
{
if (!$this->employeeContracts->contains($employeeContract)) {
$this->employeeContracts[] = $employeeContract;
$employeeContract->setContact($this);
}
return $this;
}
public function removeEmployeeContract(EmployeeContract $employeeContract): self
{
if ($this->employeeContracts->removeElement($employeeContract)) {
// set the owning side to null (unless already changed)
if ($employeeContract->getContact() === $this) {
$employeeContract->setContact(null);
}
}
return $this;
}
public function getAge(): int
{
$bdate = $this->birthDate;
return date_diff($bdate, date_create('now'))->y;
}
// public function getAgeComplete(): int
// {
// $bdate = date_create_from_format('Y-m-d', $this->birthDate->format('Y') . '-01-01');
// return date_diff($bdate, date_create('now'))->y;
// }
public function getAgeComplete($debutSejour = null): ?int
{
if ($debutSejour === null) {
$debutSejour = new DateTime();
}
$bdate = date_create_from_format('Y-m-d', $this->birthDate->format('Y') . '-01-01');
//$bdate = $this->birthDate;
return date_diff($bdate, $debutSejour)->y;
}
/**
* @return Collection|ReductionRequest[]
*/
public function getReductionRequests(): Collection
{
return $this->reductionRequests;
}
public function addReductionRequest(ReductionRequest $reductionRequest): self
{
if (!$this->reductionRequests->contains($reductionRequest)) {
$this->reductionRequests[] = $reductionRequest;
$reductionRequest->setContact($this);
}
return $this;
}
public function removeReductionRequest(ReductionRequest $reductionRequest): self
{
if ($this->reductionRequests->removeElement($reductionRequest)) {
// set the owning side to null (unless already changed)
if ($reductionRequest->getContact() === $this) {
$reductionRequest->setContact(null);
}
}
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection<int, TiersDeConfiance>
*/
public function getTiersDeConfiances(): Collection
{
return $this->tiersDeConfiances;
}
public function addTiersDeConfiance(TiersDeConfiance $tiersDeConfiance): self
{
if (!$this->tiersDeConfiances->contains($tiersDeConfiance)) {
$this->tiersDeConfiances[] = $tiersDeConfiance;
$tiersDeConfiance->setMain($this);
}
return $this;
}
public function removeTiersDeConfiance(TiersDeConfiance $tiersDeConfiance): self
{
if ($this->tiersDeConfiances->removeElement($tiersDeConfiance)) {
// set the owning side to null (unless already changed)
if ($tiersDeConfiance->getMain() === $this) {
$tiersDeConfiance->setMain(null);
}
}
return $this;
}
/**
* @return Collection<int, TiersDeConfiance>
*/
public function getTiersDeConfianceRelations(): Collection
{
return $this->tiersDeConfianceRelations;
}
public function addTiersDeConfianceRelation(TiersDeConfiance $tiersDeConfianceRelation): self
{
if (!$this->tiersDeConfianceRelations->contains($tiersDeConfianceRelation)) {
$this->tiersDeConfianceRelations[] = $tiersDeConfianceRelation;
$tiersDeConfianceRelation->setTiers($this);
}
return $this;
}
public function removeTiersDeConfianceRelation(TiersDeConfiance $tiersDeConfianceRelation): self
{
if ($this->tiersDeConfianceRelations->removeElement($tiersDeConfianceRelation)) {
// set the owning side to null (unless already changed)
if ($tiersDeConfianceRelation->getTiers() === $this) {
$tiersDeConfianceRelation->setTiers(null);
}
}
return $this;
}
public function getSexeEcrit()
{
return $this->sexe == "F" ? "Madame" : "Monsieur";
}
}