src/Entity/Firm.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\FirmRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=FirmRepository::class)
  9.  */
  10. class Firm
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $axonautId;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $name;
  26.     /**
  27.      * @ORM\Column(type="text", nullable=true)
  28.      */
  29.     private $addressStreet;
  30.     /**
  31.      * @ORM\Column(type="string", length=16, nullable=true)
  32.      */
  33.     private $addressZipCode;
  34.     /**
  35.      * @ORM\Column(type="string", length=128, nullable=true)
  36.      */
  37.     private $addressCity;
  38.     /**
  39.      * @ORM\Column(type="string", length=128, nullable=true)
  40.      */
  41.     private $addressCountry;
  42.     /**
  43.      * @ORM\Column(type="string", length=128, nullable=true)
  44.      */
  45.     private $addressRegion;
  46.     /**
  47.      * @ORM\OneToMany(targetEntity=Contact::class, mappedBy="firm",cascade={"persist"})
  48.      */
  49.     private $contacts;
  50.     /**
  51.      * @ORM\Column(type="string", length=64, nullable=true)
  52.      */
  53.     private $siret;
  54.     /**
  55.      * @ORM\Column(type="integer", nullable=true)
  56.      */
  57.     private $filegetterId;
  58.     /**
  59.      * @ORM\Column(type="text", nullable=true)
  60.      */
  61.     private $comment;
  62.     public function __construct()
  63.     {
  64.         $this->contacts = new ArrayCollection();
  65.     }
  66.     public function getId(): ?int
  67.     {
  68.         return $this->id;
  69.     }
  70.     public function getAxonautId(): ?int
  71.     {
  72.         return $this->axonautId;
  73.     }
  74.     public function setAxonautId(int $axonautId): self
  75.     {
  76.         $this->axonautId $axonautId;
  77.         return $this;
  78.     }
  79.     public function getName(): ?string
  80.     {
  81.         return $this->name;
  82.     }
  83.     public function setName(string $name): self
  84.     {
  85.         $this->name $name;
  86.         return $this;
  87.     }
  88.     public function getAddressStreet(): ?string
  89.     {
  90.         return $this->addressStreet;
  91.     }
  92.     public function setAddressStreet(?string $addressStreet): self
  93.     {
  94.         $this->addressStreet $addressStreet;
  95.         return $this;
  96.     }
  97.     public function getAddressZipCode(): ?string
  98.     {
  99.         return $this->addressZipCode;
  100.     }
  101.     public function setAddressZipCode(?string $addressZipCode): self
  102.     {
  103.         $this->addressZipCode $addressZipCode;
  104.         return $this;
  105.     }
  106.     public function getAddressCity(): ?string
  107.     {
  108.         return $this->addressCity;
  109.     }
  110.     public function setAddressCity(?string $addressCity): self
  111.     {
  112.         $this->addressCity $addressCity;
  113.         return $this;
  114.     }
  115.     public function getAddressCountry(): ?string
  116.     {
  117.         return $this->addressCountry;
  118.     }
  119.     public function setAddressCountry(?string $addressCountry): self
  120.     {
  121.         $this->addressCountry $addressCountry;
  122.         return $this;
  123.     }
  124.     public function getAddressRegion(): ?string
  125.     {
  126.         return $this->addressRegion;
  127.     }
  128.     public function setAddressRegion(?string $addressRegion): self
  129.     {
  130.         $this->addressRegion $addressRegion;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return Collection|Contact[]
  135.      */
  136.     public function getContacts(): Collection
  137.     {
  138.         return $this->contacts;
  139.     }
  140.     /**
  141.      * @param int $axonautId
  142.      * @return Contact|null
  143.      */
  144.     public function getContactByAxonautId(int $axonautId): ?Contact
  145.     {
  146.         foreach ($this->getContacts() as $contact) {
  147.             if ($contact->getAxonautId() == $axonautId) {
  148.                 return $contact;
  149.             }
  150.         }
  151.         return null;
  152.     }
  153.     public function addContact(Contact $contact): self
  154.     {
  155.         if (!$this->contacts->contains($contact)) {
  156.             $this->contacts[] = $contact;
  157.             $contact->setFirm($this);
  158.         }
  159.         return $this;
  160.     }
  161.     public function removeContact(Contact $contact): self
  162.     {
  163.         if ($this->contacts->removeElement($contact)) {
  164.             // set the owning side to null (unless already changed)
  165.             if ($contact->getFirm() === $this) {
  166.                 $contact->setFirm(null);
  167.             }
  168.         }
  169.         return $this;
  170.     }
  171.     public function getSiret(): ?string
  172.     {
  173.         return $this->siret;
  174.     }
  175.     public function setSiret(?string $siret): self
  176.     {
  177.         $this->siret $siret;
  178.         return $this;
  179.     }
  180.     public function merge(Firm $firm): self
  181.     {
  182.         $this->setAxonautId($firm->getAxonautId())
  183.              ->setSiret($firm->getSiret())
  184.              ->setAddressCountry($firm->getAddressCountry())
  185.              ->setAddressRegion($firm->getAddressRegion())
  186.              ->setAddressCity($firm->getAddressCity())
  187.              ->setAddressZipCode($firm->getAddressZipCode())
  188.              ->setAddressStreet($firm->getAddressStreet())
  189.              ->setName($firm->getName());
  190.         foreach ($firm->getContacts() as $contact) {
  191.             $this->mergeContact($contact);
  192.         }
  193.         return $this;
  194.     }
  195.     public function mergeContact(Contact $contact)
  196.     {
  197.         foreach ($this->getContacts() as $contactExist) {
  198.             if ($contactExist->getAxonautId() == $contact->getAxonautId()) {
  199.                 $contactExist->setJob($contact->getJob())
  200.                              ->setCellphoneNumber($contact->getCellphoneNumber())
  201.                              ->setPhoneNumber($contact->getPhoneNumber())
  202.                              ->setEmail($contact->getEmail())
  203.                              ->setLastname($contact->getLastname())
  204.                              ->setFirstname($contact->getFirstname());
  205.             }
  206.         }
  207.         return false;
  208.     }
  209.     public function getFilegetterId(): ?int
  210.     {
  211.         return $this->filegetterId;
  212.     }
  213.     public function setFilegetterId(?int $filegetterId): self
  214.     {
  215.         $this->filegetterId $filegetterId;
  216.         return $this;
  217.     }
  218.     public function getComment(): ?string
  219.     {
  220.         return $this->comment;
  221.     }
  222.     public function setComment(?string $comment): self
  223.     {
  224.         $this->comment $comment;
  225.         return $this;
  226.     }
  227. }