<?php
namespace App\Entity;
use App\Entity\Traits\Address;
use App\Repository\CompanyRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
use Doctrine\ORM\Mapping\InheritanceType;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @InheritanceType("SINGLE_TABLE")
* @ORM\Entity(repositoryClass=CompanyRepository::class)
* @ORM\HasLifecycleCallbacks()
* @Vich\Uploadable
*/
class Company
{
use Address;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"room:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Groups({"room:read"})
*/
protected $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $image;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $updatedAt;
/**
* @ORM\OneToOne(targetEntity=User::class, inversedBy="company", cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=false)
* @Assert\Valid()
*/
protected $user;
/**
* @Vich\UploadableField(mapping="specialists_images", fileNameProperty="image")
* @Assert\File(
* mimeTypes={"image/jpeg", "image/gif", "image/png"},
* maxSize="700Ki",
* )
* @var File
*/
protected $imageFile;
/**
* @ORM\OneToMany(targetEntity=Room::class, mappedBy="company", orphanRemoval=true)
*/
protected $rooms;
/**
* @ORM\OneToMany(targetEntity=Workshop::class, mappedBy="company")
*/
protected $workshops;
/**
* @ORM\OneToMany(targetEntity=Client::class, mappedBy="company", orphanRemoval=true)
*/
protected $clients;
/**
* @ORM\OneToMany(targetEntity=Event::class, mappedBy="company")
*/
protected $events;
/**
* @ORM\OneToMany(targetEntity=CompanyTag::class, mappedBy="company", cascade={"all"})
*/
protected $companyTags;
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $presentation;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $presentationTitle;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $siret;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
*/
private $createdAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $companyCode;
/**
* @ORM\OneToMany(targetEntity=VisioEventPromotion::class, mappedBy="company")
*/
private $visioEventPromotions;
/**
* @ORM\Column(type="boolean")
*/
private $visioAllowed = true;
/**
* @ORM\Column(type="boolean")
*/
private $visioPaymentAllowed = true;
/**
* @ORM\OneToMany(targetEntity=Specialist::class, mappedBy="affiliatedCompany")
*/
private $affiliatedSpecialists;
/**
* @ORM\ManyToMany(targetEntity=Specialist::class, mappedBy="companies")
*/
private $specialists;
/**
* @ORM\OneToMany(targetEntity=AffiliatedEventApplication::class, mappedBy="company")
*/
private $affiliatedEventApplications;
/**
* @ORM\OneToMany(targetEntity=Segmentation::class, mappedBy="company")
*/
private $segmentations;
/**
* @ORM\Column(type="boolean")
*/
private $forceSegmentation;
/**
* @ORM\OneToMany(targetEntity=Configuration::class, mappedBy="company", cascade={"all"})
*/
private $configurations;
public function __construct()
{
$this->rooms = new ArrayCollection();
$this->workshops = new ArrayCollection();
$this->clients = new ArrayCollection();
$this->events = new ArrayCollection();
$this->companyTags = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->visioEventPromotions = new ArrayCollection();
$this->affiliatedSpecialists = new ArrayCollection();
$this->specialists = new ArrayCollection();
$this->affiliatedEventApplications = new ArrayCollection();
$this->segmentations = new ArrayCollection();
$this->configurations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
if ($this->user instanceof User){
$this->user->setName($name);
}
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getUpdatedAt(): ?\DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(User $user): self
{
$this->user = $user;
$this->setName($this->getName());
return $this;
}
/**
* @return File|null
*/
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|null $imageFile
* @return Company
*/
public function setImageFile(?File $imageFile = null): self
{
$this->imageFile = $imageFile;
if ($imageFile) {
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new \DateTime('now');
}
return $this;
}
/**
* @return Collection|Room[]
*/
public function getRooms(): Collection
{
return $this->rooms;
}
public function addRoom(Room $room): self
{
if (!$this->rooms->contains($room)) {
$this->rooms[] = $room;
$room->setCompany($this);
}
return $this;
}
public function removeRoom(Room $room): self
{
if ($this->rooms->removeElement($room)) {
// set the owning side to null (unless already changed)
if ($room->getCompany() === $this) {
$room->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|Workshop[]
*/
public function getWorkshops(): Collection
{
return $this->workshops;
}
public function addWorkshop(Workshop $workshop): self
{
if (!$this->workshops->contains($workshop)) {
$this->workshops[] = $workshop;
$workshop->setCompany($this);
}
return $this;
}
public function removeWorkshop(Workshop $workshop): self
{
if ($this->workshops->removeElement($workshop)) {
// set the owning side to null (unless already changed)
if ($workshop->getCompany() === $this) {
$workshop->setCompany(null);
}
}
return $this;
}
/**
* @ORM\PrePersist()
*/
public function prePersist()
{
$this->user->setCategory(User::GROUP_COMPANY);
$this->user->addRole(User::ROLE_COMPANY);
}
public function __toString()
{
return $this->name??'';
}
/**
* @return Collection|Client[]
*/
public function getClients(): Collection
{
return $this->clients;
}
public function addClient(Client $client): self
{
if (!$this->clients->contains($client)) {
$this->clients[] = $client;
$client->setCompany($this);
}
return $this;
}
public function removeClient(Client $client): self
{
if ($this->clients->removeElement($client)) {
// set the owning side to null (unless already changed)
if ($client->getCompany() === $this) {
$client->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|Event[]
*/
public function getEvents(): Collection
{
return $this->events;
}
public function addEvent(Event $event): self
{
if (!$this->events->contains($event)) {
$this->events[] = $event;
$event->setCompany($this);
}
return $this;
}
public function removeEvent(Event $event): self
{
if ($this->events->removeElement($event)) {
// set the owning side to null (unless already changed)
if ($event->getCompany() === $this) {
$event->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|CompanyTag[]
*/
public function getCompanyTags(): Collection
{
return $this->companyTags;
}
public function setCompanyTags(array $companyTags): self
{
$this->companyTags = new ArrayCollection();
if (is_array($companyTags)){
$this->companyTags = new ArrayCollection($companyTags);
}
return $this;
}
public function addCompanyTag(CompanyTag $companyTag): self
{
if (!$this->companyTags->contains($companyTag)) {
$this->companyTags[] = $companyTag;
$companyTag->setCompany($this);
}
return $this;
}
public function removeCompanyTag(CompanyTag $companyTag): self
{
if ($this->companyTags->removeElement($companyTag)) {
// set the owning side to null (unless already changed)
if ($companyTag->getCompany() === $this) {
$companyTag->setCompany(null);
}
}
return $this;
}
public function getPresentation(): ?string
{
return $this->presentation;
}
public function setPresentation(?string $presentation): self
{
$this->presentation = $presentation;
return $this;
}
public function getPresentationTitle(): ?string
{
return $this->presentationTitle;
}
public function setPresentationTitle(?string $presentationTitle): self
{
$this->presentationTitle = $presentationTitle;
return $this;
}
public function getSiret(): ?string
{
return $this->siret;
}
public function setSiret(?string $siret): self
{
$this->siret = $siret;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getCompanyCode(): ?string
{
return $this->companyCode;
}
public function setCompanyCode(?string $companyCode): self
{
$this->companyCode = $companyCode;
return $this;
}
/**
* @return Collection<int, VisioEventPromotion>
*/
public function getVisioEventPromotions(): Collection
{
return $this->visioEventPromotions;
}
public function addVisioEventPromotion(VisioEventPromotion $visioEventPromotion): self
{
if (!$this->visioEventPromotions->contains($visioEventPromotion)) {
$this->visioEventPromotions[] = $visioEventPromotion;
$visioEventPromotion->setCompany($this);
}
return $this;
}
public function removeVisioEventPromotion(VisioEventPromotion $visioEventPromotion): self
{
if ($this->visioEventPromotions->removeElement($visioEventPromotion)) {
// set the owning side to null (unless already changed)
if ($visioEventPromotion->getCompany() === $this) {
$visioEventPromotion->setCompany(null);
}
}
return $this;
}
public function getVisioAllowed(): ?bool
{
return $this->visioAllowed;
}
public function setVisioAllowed(bool $visioAllowed): self
{
$this->visioAllowed = $visioAllowed;
return $this;
}
public function getVisioPaymentAllowed(): ?bool
{
return $this->visioPaymentAllowed;
}
public function setVisioPaymentAllowed(bool $visioPaymentAllowed): self
{
$this->visioPaymentAllowed = $visioPaymentAllowed;
return $this;
}
/**
* @return Collection<int, Specialist>
*/
public function getAffiliatedSpecialists(): Collection
{
return $this->affiliatedSpecialists;
}
public function addAffiliatedSpecialist(Specialist $affiliatedSpecialist): self
{
if (!$this->affiliatedSpecialists->contains($affiliatedSpecialist)) {
$this->affiliatedSpecialists[] = $affiliatedSpecialist;
$affiliatedSpecialist->setAffiliatedCompany($this);
}
return $this;
}
public function removeAffiliatedSpecialist(Specialist $affiliatedSpecialist): self
{
if ($this->affiliatedSpecialists->removeElement($affiliatedSpecialist)) {
// set the owning side to null (unless already changed)
if ($affiliatedSpecialist->getAffiliatedCompany() === $this) {
$affiliatedSpecialist->setAffiliatedCompany(null);
}
}
return $this;
}
/**
* @return Collection<int, Specialist>
*/
public function getSpecialists(): Collection
{
return $this->specialists;
}
public function addSpecialist(Specialist $specialist): self
{
if (!$this->specialists->contains($specialist)) {
$this->specialists[] = $specialist;
$specialist->addCompany($this);
}
return $this;
}
public function removeSpecialist(Specialist $specialist): self
{
if ($this->specialists->removeElement($specialist)) {
$specialist->removeCompany($this);
}
return $this;
}
/**
* @return Collection<int, AffiliatedEventApplication>
*/
public function getAffiliatedEventApplications(): Collection
{
return $this->affiliatedEventApplications;
}
public function addAffiliatedEventApplication(AffiliatedEventApplication $affiliatedEventApplication): self
{
if (!$this->affiliatedEventApplications->contains($affiliatedEventApplication)) {
$this->affiliatedEventApplications[] = $affiliatedEventApplication;
$affiliatedEventApplication->setCompany($this);
}
return $this;
}
public function removeAffiliatedEventApplication(AffiliatedEventApplication $affiliatedEventApplication): self
{
if ($this->affiliatedEventApplications->removeElement($affiliatedEventApplication)) {
// set the owning side to null (unless already changed)
if ($affiliatedEventApplication->getCompany() === $this) {
$affiliatedEventApplication->setCompany(null);
}
}
return $this;
}
/**
* @return Collection<int, Segmentation>
*/
public function getSegmentations(): Collection
{
return $this->segmentations;
}
public function addSegmentation(Segmentation $segmentation): self
{
if (!$this->segmentations->contains($segmentation)) {
$this->segmentations[] = $segmentation;
$segmentation->setCompany($this);
}
return $this;
}
public function removeSegmentation(Segmentation $segmentation): self
{
if ($this->segmentations->removeElement($segmentation)) {
// set the owning side to null (unless already changed)
if ($segmentation->getCompany() === $this) {
$segmentation->setCompany(null);
}
}
return $this;
}
public function getForceSegmentation(): ?bool
{
return $this->forceSegmentation;
}
public function setForceSegmentation(bool $forceSegmentation): self
{
$this->forceSegmentation = $forceSegmentation;
return $this;
}
/**
* @return Collection<int, Configuration>
*/
public function getConfigurations(): Collection
{
return $this->configurations;
}
public function addConfiguration(Configuration $configuration): self
{
if (!$this->configurations->contains($configuration)) {
$this->configurations[] = $configuration;
$configuration->setCompany($this);
}
return $this;
}
public function removeConfiguration(Configuration $configuration): self
{
if ($this->configurations->removeElement($configuration)) {
// set the owning side to null (unless already changed)
if ($configuration->getCompany() === $this) {
$configuration->setCompany(null);
}
}
return $this;
}
}