src/Entity/Company.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\Address;
  4. use App\Repository\CompanyRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Doctrine\ORM\Mapping\DiscriminatorColumn;
  9. use Doctrine\ORM\Mapping\InheritanceType;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  16. /**
  17.  * @InheritanceType("SINGLE_TABLE")
  18.  * @ORM\Entity(repositoryClass=CompanyRepository::class)
  19.  * @ORM\HasLifecycleCallbacks()
  20.  * @Vich\Uploadable
  21.  */
  22. class Company
  23. {
  24.     use Address;
  25.     /**
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue
  28.      * @ORM\Column(type="integer")
  29.      * @Groups({"room:read"})
  30.      */
  31.     private $id;
  32.     /**
  33.      * @ORM\Column(type="string", length=255)
  34.      * @Assert\NotBlank
  35.      * @Groups({"room:read"})
  36.      */
  37.     protected $name;
  38.     /**
  39.      * @ORM\Column(type="string", length=255, nullable=true)
  40.      */
  41.     protected $image;
  42.     /**
  43.      * @ORM\Column(type="datetime", nullable=true)
  44.      */
  45.     protected $updatedAt;
  46.     /**
  47.      * @ORM\OneToOne(targetEntity=User::class, inversedBy="company", cascade={"persist", "remove"})
  48.      * @ORM\JoinColumn(nullable=false)
  49.      * @Assert\Valid()
  50.      */
  51.     protected $user;
  52.     /**
  53.      * @Vich\UploadableField(mapping="specialists_images", fileNameProperty="image")
  54.      * @Assert\File(
  55.      *     mimeTypes={"image/jpeg", "image/gif", "image/png"},
  56.      *     maxSize="700Ki",
  57.      * )
  58.      * @var File
  59.      */
  60.     protected $imageFile;
  61.     /**
  62.      * @ORM\OneToMany(targetEntity=Room::class, mappedBy="company", orphanRemoval=true)
  63.      */
  64.     protected $rooms;
  65.     /**
  66.      * @ORM\OneToMany(targetEntity=Workshop::class, mappedBy="company")
  67.      */
  68.     protected $workshops;
  69.     /**
  70.      * @ORM\OneToMany(targetEntity=Client::class, mappedBy="company", orphanRemoval=true)
  71.      */
  72.     protected $clients;
  73.     /**
  74.      * @ORM\OneToMany(targetEntity=Event::class, mappedBy="company")
  75.      */
  76.     protected $events;
  77.     /**
  78.      * @ORM\OneToMany(targetEntity=CompanyTag::class, mappedBy="company", cascade={"all"})
  79.      */
  80.     protected $companyTags;
  81.     /**
  82.      * @ORM\Column(type="text", nullable=true)
  83.      */
  84.     protected $presentation;
  85.     /**
  86.      * @ORM\Column(type="string", length=255, nullable=true)
  87.      */
  88.     protected $presentationTitle;
  89.     /**
  90.      * @ORM\Column(type="string", length=255, nullable=true)
  91.      */
  92.     private $siret;
  93.     /**
  94.      * @ORM\Column(type="string", length=255, nullable=true)
  95.      */
  96.     private $phone;
  97.     /**
  98.      * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  99.      */
  100.     private $createdAt;
  101.     /**
  102.      * @ORM\Column(type="string", length=255, nullable=true)
  103.      */
  104.     private $companyCode;
  105.     /**
  106.      * @ORM\OneToMany(targetEntity=VisioEventPromotion::class, mappedBy="company")
  107.      */
  108.     private $visioEventPromotions;
  109.     /**
  110.      * @ORM\Column(type="boolean")
  111.      */
  112.     private $visioAllowed true;
  113.     /**
  114.      * @ORM\Column(type="boolean")
  115.      */
  116.     private $visioPaymentAllowed true;
  117.     /**
  118.      * @ORM\OneToMany(targetEntity=Specialist::class, mappedBy="affiliatedCompany")
  119.      */
  120.     private $affiliatedSpecialists;
  121.     /**
  122.      * @ORM\ManyToMany(targetEntity=Specialist::class, mappedBy="companies")
  123.      */
  124.     private $specialists;
  125.     /**
  126.      * @ORM\OneToMany(targetEntity=AffiliatedEventApplication::class, mappedBy="company")
  127.      */
  128.     private $affiliatedEventApplications;
  129.     /**
  130.      * @ORM\OneToMany(targetEntity=Segmentation::class, mappedBy="company")
  131.      */
  132.     private $segmentations;
  133.     /**
  134.      * @ORM\Column(type="boolean")
  135.      */
  136.     private $forceSegmentation;
  137.     /**
  138.      * @ORM\OneToMany(targetEntity=Configuration::class, mappedBy="company", cascade={"all"})
  139.      */
  140.     private $configurations;
  141.    
  142.     public function __construct()
  143.     {
  144.         $this->rooms = new ArrayCollection();
  145.         $this->workshops = new ArrayCollection();
  146.         $this->clients = new ArrayCollection();
  147.         $this->events = new ArrayCollection();
  148.         $this->companyTags = new ArrayCollection();
  149.         $this->createdAt = new \DateTime();
  150.         $this->visioEventPromotions = new ArrayCollection();
  151.         $this->affiliatedSpecialists = new ArrayCollection();
  152.         $this->specialists = new ArrayCollection();
  153.         $this->affiliatedEventApplications = new ArrayCollection();
  154.         $this->segmentations = new ArrayCollection();
  155.         $this->configurations = new ArrayCollection();
  156.     }
  157.     public function getId(): ?int
  158.     {
  159.         return $this->id;
  160.     }
  161.     public function getName(): ?string
  162.     {
  163.         return $this->name;
  164.     }
  165.     public function setName(?string $name): self
  166.     {
  167.         $this->name $name;
  168.         if ($this->user instanceof User){
  169.             $this->user->setName($name);
  170.         }
  171.         return $this;
  172.     }
  173.     public function getImage(): ?string
  174.     {
  175.         return $this->image;
  176.     }
  177.     public function setImage(?string $image): self
  178.     {
  179.         $this->image $image;
  180.         return $this;
  181.     }
  182.     public function getUpdatedAt(): ?\DateTime
  183.     {
  184.         return $this->updatedAt;
  185.     }
  186.     public function setUpdatedAt(?\DateTime $updatedAt): self
  187.     {
  188.         $this->updatedAt $updatedAt;
  189.         return $this;
  190.     }
  191.     public function getUser(): ?User
  192.     {
  193.         return $this->user;
  194.     }
  195.     public function setUser(User $user): self
  196.     {
  197.         $this->user $user;
  198.         $this->setName($this->getName());
  199.         return $this;
  200.     }
  201.     /**
  202.      * @return File|null
  203.      */
  204.     public function getImageFile(): ?File
  205.     {
  206.         return $this->imageFile;
  207.     }
  208.     /**
  209.      * @param File|null $imageFile
  210.      * @return Company
  211.      */
  212.     public function setImageFile(?File $imageFile null): self
  213.     {
  214.         $this->imageFile $imageFile;
  215.         if ($imageFile) {
  216.             // if 'updatedAt' is not defined in your entity, use another property
  217.             $this->updatedAt = new \DateTime('now');
  218.         }
  219.         return $this;
  220.     }
  221.     /**
  222.      * @return Collection|Room[]
  223.      */
  224.     public function getRooms(): Collection
  225.     {
  226.         return $this->rooms;
  227.     }
  228.     public function addRoom(Room $room): self
  229.     {
  230.         if (!$this->rooms->contains($room)) {
  231.             $this->rooms[] = $room;
  232.             $room->setCompany($this);
  233.         }
  234.         return $this;
  235.     }
  236.     public function removeRoom(Room $room): self
  237.     {
  238.         if ($this->rooms->removeElement($room)) {
  239.             // set the owning side to null (unless already changed)
  240.             if ($room->getCompany() === $this) {
  241.                 $room->setCompany(null);
  242.             }
  243.         }
  244.         return $this;
  245.     }
  246.     /**
  247.      * @return Collection|Workshop[]
  248.      */
  249.     public function getWorkshops(): Collection
  250.     {
  251.         return $this->workshops;
  252.     }
  253.     public function addWorkshop(Workshop $workshop): self
  254.     {
  255.         if (!$this->workshops->contains($workshop)) {
  256.             $this->workshops[] = $workshop;
  257.             $workshop->setCompany($this);
  258.         }
  259.         return $this;
  260.     }
  261.     public function removeWorkshop(Workshop $workshop): self
  262.     {
  263.         if ($this->workshops->removeElement($workshop)) {
  264.             // set the owning side to null (unless already changed)
  265.             if ($workshop->getCompany() === $this) {
  266.                 $workshop->setCompany(null);
  267.             }
  268.         }
  269.         return $this;
  270.     }
  271.     /**
  272.      * @ORM\PrePersist()
  273.      */
  274.     public function prePersist()
  275.     {
  276.         $this->user->setCategory(User::GROUP_COMPANY);
  277.         $this->user->addRole(User::ROLE_COMPANY);
  278.     }
  279.     public function __toString()
  280.     {
  281.         return $this->name??'';
  282.     }
  283.     /**
  284.      * @return Collection|Client[]
  285.      */
  286.     public function getClients(): Collection
  287.     {
  288.         return $this->clients;
  289.     }
  290.     public function addClient(Client $client): self
  291.     {
  292.         if (!$this->clients->contains($client)) {
  293.             $this->clients[] = $client;
  294.             $client->setCompany($this);
  295.         }
  296.         return $this;
  297.     }
  298.     public function removeClient(Client $client): self
  299.     {
  300.         if ($this->clients->removeElement($client)) {
  301.             // set the owning side to null (unless already changed)
  302.             if ($client->getCompany() === $this) {
  303.                 $client->setCompany(null);
  304.             }
  305.         }
  306.         return $this;
  307.     }
  308.     /**
  309.      * @return Collection|Event[]
  310.      */
  311.     public function getEvents(): Collection
  312.     {
  313.         return $this->events;
  314.     }
  315.     public function addEvent(Event $event): self
  316.     {
  317.         if (!$this->events->contains($event)) {
  318.             $this->events[] = $event;
  319.             $event->setCompany($this);
  320.         }
  321.         return $this;
  322.     }
  323.     public function removeEvent(Event $event): self
  324.     {
  325.         if ($this->events->removeElement($event)) {
  326.             // set the owning side to null (unless already changed)
  327.             if ($event->getCompany() === $this) {
  328.                 $event->setCompany(null);
  329.             }
  330.         }
  331.         return $this;
  332.     }
  333.     /**
  334.      * @return Collection|CompanyTag[]
  335.      */
  336.     public function getCompanyTags(): Collection
  337.     {
  338.         return $this->companyTags;
  339.     }
  340.     public function setCompanyTags(array $companyTags): self
  341.     {
  342.         $this->companyTags = new ArrayCollection();
  343.         if (is_array($companyTags)){
  344.             $this->companyTags = new ArrayCollection($companyTags);
  345.         }
  346.         return $this;
  347.     }
  348.     public function addCompanyTag(CompanyTag $companyTag): self
  349.     {
  350.         if (!$this->companyTags->contains($companyTag)) {
  351.             $this->companyTags[] = $companyTag;
  352.             $companyTag->setCompany($this);
  353.         }
  354.         return $this;
  355.     }
  356.     public function removeCompanyTag(CompanyTag $companyTag): self
  357.     {
  358.         if ($this->companyTags->removeElement($companyTag)) {
  359.             // set the owning side to null (unless already changed)
  360.             if ($companyTag->getCompany() === $this) {
  361.                 $companyTag->setCompany(null);
  362.             }
  363.         }
  364.         return $this;
  365.     }
  366.     public function getPresentation(): ?string
  367.     {
  368.         return $this->presentation;
  369.     }
  370.     public function setPresentation(?string $presentation): self
  371.     {
  372.         $this->presentation $presentation;
  373.         return $this;
  374.     }
  375.     public function getPresentationTitle(): ?string
  376.     {
  377.         return $this->presentationTitle;
  378.     }
  379.     public function setPresentationTitle(?string $presentationTitle): self
  380.     {
  381.         $this->presentationTitle $presentationTitle;
  382.         return $this;
  383.     }
  384.     public function getSiret(): ?string
  385.     {
  386.         return $this->siret;
  387.     }
  388.     public function setSiret(?string $siret): self
  389.     {
  390.         $this->siret $siret;
  391.         return $this;
  392.     }
  393.     public function getPhone(): ?string
  394.     {
  395.         return $this->phone;
  396.     }
  397.     public function setPhone(?string $phone): self
  398.     {
  399.         $this->phone $phone;
  400.         return $this;
  401.     }
  402.     public function getCreatedAt(): ?\DateTime
  403.     {
  404.         return $this->createdAt;
  405.     }
  406.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  407.     {
  408.         $this->createdAt $createdAt;
  409.         return $this;
  410.     }
  411.     public function getCompanyCode(): ?string
  412.     {
  413.         return $this->companyCode;
  414.     }
  415.     public function setCompanyCode(?string $companyCode): self
  416.     {
  417.         $this->companyCode $companyCode;
  418.         return $this;
  419.     }
  420.     /**
  421.      * @return Collection<int, VisioEventPromotion>
  422.      */
  423.     public function getVisioEventPromotions(): Collection
  424.     {
  425.         return $this->visioEventPromotions;
  426.     }
  427.     public function addVisioEventPromotion(VisioEventPromotion $visioEventPromotion): self
  428.     {
  429.         if (!$this->visioEventPromotions->contains($visioEventPromotion)) {
  430.             $this->visioEventPromotions[] = $visioEventPromotion;
  431.             $visioEventPromotion->setCompany($this);
  432.         }
  433.         return $this;
  434.     }
  435.     public function removeVisioEventPromotion(VisioEventPromotion $visioEventPromotion): self
  436.     {
  437.         if ($this->visioEventPromotions->removeElement($visioEventPromotion)) {
  438.             // set the owning side to null (unless already changed)
  439.             if ($visioEventPromotion->getCompany() === $this) {
  440.                 $visioEventPromotion->setCompany(null);
  441.             }
  442.         }
  443.         return $this;
  444.     }
  445.     public function getVisioAllowed(): ?bool
  446.     {
  447.         return $this->visioAllowed;
  448.     }
  449.     public function setVisioAllowed(bool $visioAllowed): self
  450.     {
  451.         $this->visioAllowed $visioAllowed;
  452.         return $this;
  453.     }
  454.     public function getVisioPaymentAllowed(): ?bool
  455.     {
  456.         return $this->visioPaymentAllowed;
  457.     }
  458.     public function setVisioPaymentAllowed(bool $visioPaymentAllowed): self
  459.     {
  460.         $this->visioPaymentAllowed $visioPaymentAllowed;
  461.         return $this;
  462.     }
  463.     /**
  464.      * @return Collection<int, Specialist>
  465.      */
  466.     public function getAffiliatedSpecialists(): Collection
  467.     {
  468.         return $this->affiliatedSpecialists;
  469.     }
  470.     public function addAffiliatedSpecialist(Specialist $affiliatedSpecialist): self
  471.     {
  472.         if (!$this->affiliatedSpecialists->contains($affiliatedSpecialist)) {
  473.             $this->affiliatedSpecialists[] = $affiliatedSpecialist;
  474.             $affiliatedSpecialist->setAffiliatedCompany($this);
  475.         }
  476.         return $this;
  477.     }
  478.     public function removeAffiliatedSpecialist(Specialist $affiliatedSpecialist): self
  479.     {
  480.         if ($this->affiliatedSpecialists->removeElement($affiliatedSpecialist)) {
  481.             // set the owning side to null (unless already changed)
  482.             if ($affiliatedSpecialist->getAffiliatedCompany() === $this) {
  483.                 $affiliatedSpecialist->setAffiliatedCompany(null);
  484.             }
  485.         }
  486.         return $this;
  487.     }
  488.     /**
  489.      * @return Collection<int, Specialist>
  490.      */
  491.     public function getSpecialists(): Collection
  492.     {
  493.         return $this->specialists;
  494.     }
  495.     public function addSpecialist(Specialist $specialist): self
  496.     {
  497.         if (!$this->specialists->contains($specialist)) {
  498.             $this->specialists[] = $specialist;
  499.             $specialist->addCompany($this);
  500.         }
  501.         return $this;
  502.     }
  503.     public function removeSpecialist(Specialist $specialist): self
  504.     {
  505.         if ($this->specialists->removeElement($specialist)) {
  506.             $specialist->removeCompany($this);
  507.         }
  508.         return $this;
  509.     }
  510.     /**
  511.      * @return Collection<int, AffiliatedEventApplication>
  512.      */
  513.     public function getAffiliatedEventApplications(): Collection
  514.     {
  515.         return $this->affiliatedEventApplications;
  516.     }
  517.     public function addAffiliatedEventApplication(AffiliatedEventApplication $affiliatedEventApplication): self
  518.     {
  519.         if (!$this->affiliatedEventApplications->contains($affiliatedEventApplication)) {
  520.             $this->affiliatedEventApplications[] = $affiliatedEventApplication;
  521.             $affiliatedEventApplication->setCompany($this);
  522.         }
  523.         return $this;
  524.     }
  525.     public function removeAffiliatedEventApplication(AffiliatedEventApplication $affiliatedEventApplication): self
  526.     {
  527.         if ($this->affiliatedEventApplications->removeElement($affiliatedEventApplication)) {
  528.             // set the owning side to null (unless already changed)
  529.             if ($affiliatedEventApplication->getCompany() === $this) {
  530.                 $affiliatedEventApplication->setCompany(null);
  531.             }
  532.         }
  533.         return $this;
  534.     }
  535.     /**
  536.      * @return Collection<int, Segmentation>
  537.      */
  538.     public function getSegmentations(): Collection
  539.     {
  540.         return $this->segmentations;
  541.     }
  542.     public function addSegmentation(Segmentation $segmentation): self
  543.     {
  544.         if (!$this->segmentations->contains($segmentation)) {
  545.             $this->segmentations[] = $segmentation;
  546.             $segmentation->setCompany($this);
  547.         }
  548.         return $this;
  549.     }
  550.     public function removeSegmentation(Segmentation $segmentation): self
  551.     {
  552.         if ($this->segmentations->removeElement($segmentation)) {
  553.             // set the owning side to null (unless already changed)
  554.             if ($segmentation->getCompany() === $this) {
  555.                 $segmentation->setCompany(null);
  556.             }
  557.         }
  558.         return $this;
  559.     }
  560.     public function getForceSegmentation(): ?bool
  561.     {
  562.         return $this->forceSegmentation;
  563.     }
  564.     public function setForceSegmentation(bool $forceSegmentation): self
  565.     {
  566.         $this->forceSegmentation $forceSegmentation;
  567.         return $this;
  568.     }
  569.     /**
  570.      * @return Collection<int, Configuration>
  571.      */
  572.     public function getConfigurations(): Collection
  573.     {
  574.         return $this->configurations;
  575.     }
  576.     public function addConfiguration(Configuration $configuration): self
  577.     {
  578.         if (!$this->configurations->contains($configuration)) {
  579.             $this->configurations[] = $configuration;
  580.             $configuration->setCompany($this);
  581.         }
  582.         return $this;
  583.     }
  584.     public function removeConfiguration(Configuration $configuration): self
  585.     {
  586.         if ($this->configurations->removeElement($configuration)) {
  587.             // set the owning side to null (unless already changed)
  588.             if ($configuration->getCompany() === $this) {
  589.                 $configuration->setCompany(null);
  590.             }
  591.         }
  592.         return $this;
  593.     }
  594.    
  595. }