<?php
namespace App\Entity;
use App\Repository\FirmRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=FirmRepository::class)
*/
class Firm
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="integer")
*/
private $axonautId;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $addressStreet;
/**
* @ORM\Column(type="string", length=16, nullable=true)
*/
private $addressZipCode;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $addressCity;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $addressCountry;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $addressRegion;
/**
* @ORM\OneToMany(targetEntity=Contact::class, mappedBy="firm",cascade={"persist"})
*/
private $contacts;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $siret;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $filegetterId;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $comment;
public function __construct()
{
$this->contacts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getAxonautId(): ?int
{
return $this->axonautId;
}
public function setAxonautId(int $axonautId): self
{
$this->axonautId = $axonautId;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getAddressStreet(): ?string
{
return $this->addressStreet;
}
public function setAddressStreet(?string $addressStreet): self
{
$this->addressStreet = $addressStreet;
return $this;
}
public function getAddressZipCode(): ?string
{
return $this->addressZipCode;
}
public function setAddressZipCode(?string $addressZipCode): self
{
$this->addressZipCode = $addressZipCode;
return $this;
}
public function getAddressCity(): ?string
{
return $this->addressCity;
}
public function setAddressCity(?string $addressCity): self
{
$this->addressCity = $addressCity;
return $this;
}
public function getAddressCountry(): ?string
{
return $this->addressCountry;
}
public function setAddressCountry(?string $addressCountry): self
{
$this->addressCountry = $addressCountry;
return $this;
}
public function getAddressRegion(): ?string
{
return $this->addressRegion;
}
public function setAddressRegion(?string $addressRegion): self
{
$this->addressRegion = $addressRegion;
return $this;
}
/**
* @return Collection|Contact[]
*/
public function getContacts(): Collection
{
return $this->contacts;
}
/**
* @param int $axonautId
* @return Contact|null
*/
public function getContactByAxonautId(int $axonautId): ?Contact
{
foreach ($this->getContacts() as $contact) {
if ($contact->getAxonautId() == $axonautId) {
return $contact;
}
}
return null;
}
public function addContact(Contact $contact): self
{
if (!$this->contacts->contains($contact)) {
$this->contacts[] = $contact;
$contact->setFirm($this);
}
return $this;
}
public function removeContact(Contact $contact): self
{
if ($this->contacts->removeElement($contact)) {
// set the owning side to null (unless already changed)
if ($contact->getFirm() === $this) {
$contact->setFirm(null);
}
}
return $this;
}
public function getSiret(): ?string
{
return $this->siret;
}
public function setSiret(?string $siret): self
{
$this->siret = $siret;
return $this;
}
public function merge(Firm $firm): self
{
$this->setAxonautId($firm->getAxonautId())
->setSiret($firm->getSiret())
->setAddressCountry($firm->getAddressCountry())
->setAddressRegion($firm->getAddressRegion())
->setAddressCity($firm->getAddressCity())
->setAddressZipCode($firm->getAddressZipCode())
->setAddressStreet($firm->getAddressStreet())
->setName($firm->getName());
foreach ($firm->getContacts() as $contact) {
$this->mergeContact($contact);
}
return $this;
}
public function mergeContact(Contact $contact)
{
foreach ($this->getContacts() as $contactExist) {
if ($contactExist->getAxonautId() == $contact->getAxonautId()) {
$contactExist->setJob($contact->getJob())
->setCellphoneNumber($contact->getCellphoneNumber())
->setPhoneNumber($contact->getPhoneNumber())
->setEmail($contact->getEmail())
->setLastname($contact->getLastname())
->setFirstname($contact->getFirstname());
}
}
return false;
}
public function getFilegetterId(): ?int
{
return $this->filegetterId;
}
public function setFilegetterId(?int $filegetterId): self
{
$this->filegetterId = $filegetterId;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
}