src/Entity/Company.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Library;
  4. use App\Entity\Part;
  5. use App\Repository\CompanyRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. /**
  14.  * @ORM\Entity(repositoryClass=CompanyRepository::class)
  15.  * @Vich\Uploadable
  16.  * 
  17.  * @ORM\Table(name="company",indexes={
  18.  *     @ORM\Index(name="company_certifications", columns={"certifications"}),
  19.  *     @ORM\Index(name="company_name", columns={"name"})
  20.  * })
  21.  */
  22. class Company
  23. {
  24.     /**
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue
  27.      * @ORM\Column(type="integer")
  28.      * @Groups({"company"})
  29.      */
  30.     private $id
  31.     /**
  32.      * @ORM\Column(type="string", length=100)
  33.      * @Assert\NotBlank
  34.      * @Groups({"company"})
  35.      */
  36.     private $name;
  37.     /**
  38.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="company")
  39.      * @Groups({"company"})
  40.      */
  41.     private $user;
  42.     /**
  43.      * @ORM\Column(type="datetime")
  44.      * @Groups({"company"})
  45.      */
  46.     private $created_at;
  47.     /**
  48.      * @ORM\OneToMany(targetEntity=Library::class, mappedBy="company", orphanRemoval=false)
  49.      */
  50.     private $libraries;
  51.     /**
  52.      * @ORM\OneToMany(targetEntity=Part::class, mappedBy="Company")
  53.      */
  54.     private $parts;
  55.     /**
  56.      * @ORM\Column(type="string", length=20)
  57.      * @Assert\NotBlank
  58.      * @Groups({"company"})
  59.      */
  60.     private $nif;
  61.     /**
  62.      * @ORM\Column(type="string", length=50)
  63.      * @Assert\NotBlank
  64.      * @Groups({"company"})
  65.      */
  66.     private $phone;
  67.     /**
  68.      * @ORM\Column(type="string", length=100)
  69.      * @Assert\NotBlank
  70.      * @Assert\Email()
  71.      * @Groups({"company"})
  72.      */
  73.     private $email;
  74.     /**
  75.      * @ORM\Column(type="string", length=255)
  76.      * @Assert\NotBlank
  77.      * @Groups({"company"})
  78.      */
  79.     private $address;
  80.     /**
  81.      * @ORM\Column(type="datetime", nullable=true)
  82.      * @Groups({"company"})
  83.      */
  84.     private $updated_at;
  85.     /**
  86.      * @ORM\Column(type="string", length=4, unique=true)
  87.      * @Groups({"company"})
  88.      */
  89.     private $ref;
  90.     /**
  91.      * @ORM\OneToMany(targetEntity=CompanySupplier::class, mappedBy="company")
  92.      */
  93.     private $companySuppliers;
  94.     /**
  95.      * @ORM\OneToMany(targetEntity=LicenseCompany::class, mappedBy="company")
  96.      */
  97.     private $licenseCompanies;
  98.     /**
  99.      * 1: Client, 2:Supplier
  100.      * 
  101.      * @ORM\OneToMany(targetEntity=Supplier::class, mappedBy="company")
  102.      */
  103.     private $suppliers;
  104.     /**
  105.      * 1:OEM (Cliente), 2:Service bureau (Proveedor)
  106.      * 
  107.      * @ORM\Column(type="integer")
  108.      * @Groups({"company"})
  109.      */
  110.     private $type;
  111.     /**
  112.      * @ORM\ManyToOne(targetEntity=LicenseCompany::class)
  113.      * @ORM\JoinColumn(onDelete="SET NULL")
  114.      */
  115.     private $licenseCompany;
  116.     /**
  117.      * @ORM\Column(type="string", length=510, nullable=true)
  118.      * @Assert\Length(
  119.      *      max = 510
  120.      * )
  121.      * @Groups({"company"})
  122.      */
  123.     private $certifications;
  124.     /**
  125.      * @ORM\Column(type="string", length=255, nullable=true)
  126.      * @Groups({"company"})
  127.      * @Assert\Length(
  128.      *      max = 255
  129.      * )
  130.      */
  131.     private $services;
  132.     /**
  133.      * @ORM\Column(type="string", length=255, nullable=true)
  134.      * @Groups({"company"})
  135.      * @Assert\Length(
  136.      *      max = 255
  137.      * )
  138.      */
  139.     private $web_page;
  140.     /**
  141.      * @ORM\Column(type="string", length=255, nullable=true)
  142.      * @Groups({"company"})
  143.      */
  144.     private $logo;
  145.     /**
  146.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  147.      * 
  148.      * @Vich\UploadableField(mapping="company_file", fileNameProperty="logo")
  149.      * @Assert\File(
  150.      *     maxSize = "2M",
  151.      *     mimeTypes = {"image/jpeg","image/gif","image/png"},
  152.      *     maxSizeMessage = "El tamaño máximo permitido del archivo es {{ limit }} MB.",
  153.      *     mimeTypesMessage = "El tipo de archivo no es válido ({{ type }}). Tipos de archivo permitidos {{ types }}"
  154.      * )
  155.      * 
  156.      * @var File|null
  157.      */
  158.     private $logoFile;
  159.     /**
  160.      * @ORM\Column(type="string", length=510, nullable=true)
  161.      * @Groups({"company"})
  162.      * @Assert\Length(
  163.      *      max = 510
  164.      * )
  165.      */
  166.     private $description;
  167.     /**
  168.      * @ORM\OneToMany(targetEntity=Equipment::class, mappedBy="company")
  169.      */
  170.     private $equipment;
  171.     /**
  172.      * @ORM\OneToMany(targetEntity=Material::class, mappedBy="company")
  173.      */
  174.     private $materials;
  175.     /**
  176.      * @ORM\OneToMany(targetEntity=CompanyAddress::class, mappedBy="company")
  177.      */
  178.     private $companyAddresses;
  179.     /**
  180.      * @ORM\Column(type="smallint", nullable=true)
  181.      */
  182.     private $currency;
  183.     /**
  184.      * @ORM\Column(type="smallint", nullable=true)
  185.      */
  186.     private $thema;
  187.     /**
  188.      * @ORM\Column(type="string", length=10, nullable=true)
  189.      */
  190.     private $color;
  191.     /**
  192.      * @ORM\OneToMany(targetEntity=CompanyClient::class, mappedBy="company")
  193.      */
  194.     private $companyClients;
  195.     /**
  196.      * @ORM\Column(type="string", length=10, nullable=true)
  197.      */
  198.     private $corporate_color;
  199.     /**
  200.      * 1:oscuro, 2:claro
  201.      * 
  202.      * @ORM\Column(type="smallint", nullable=true)
  203.      */
  204.     private $corporate_theme;
  205.     public function __construct()
  206.     {
  207.         $this->user = new ArrayCollection();
  208.         $this->created_at = new \DateTime();
  209.         $this->markAsUpdated();
  210.         $this->libraries = new ArrayCollection();
  211.         $this->parts = new ArrayCollection();
  212.         $this->companySuppliers = new ArrayCollection();
  213.         $this->licenseCompanies = new ArrayCollection();
  214.         $this->suppliers = new ArrayCollection();
  215.         $this->equipment = new ArrayCollection();
  216.         $this->materials = new ArrayCollection();
  217.         $this->companyAddresses = new ArrayCollection();
  218.         $this->companyClients = new ArrayCollection();
  219.     }
  220.     // Registra el método mágico para imprimir el nombre del estado, por ejemplo, California
  221.     public function __toString() {
  222.         return $this->name;
  223.     }
  224.     public function getId(): ?int
  225.     {
  226.         return $this->id;
  227.     }
  228.     public function getName(): ?string
  229.     {
  230.         return $this->name;
  231.     }
  232.     public function setName(string $name): self
  233.     {
  234.         $this->name $name;
  235.         return $this;
  236.     }
  237.     /**
  238.      * @return Collection|User[]
  239.      */
  240.     public function getUser(): Collection
  241.     {
  242.         return $this->user;
  243.     }
  244.     public function addUser(User $user): self
  245.     {
  246.         if (!$this->user->contains($user)) {
  247.             $this->user[] = $user;
  248.             $user->setCompany($this);
  249.         }
  250.         return $this;
  251.     }
  252.     public function removeUser(User $user): self
  253.     {
  254.         if ($this->user->removeElement($user)) {
  255.             // set the owning side to null (unless already changed)
  256.             if ($user->getCompany() === $this) {
  257.                 $user->setCompany(null);
  258.             }
  259.         }
  260.         return $this;
  261.     }
  262.     public function getCreatedAt(): ?\DateTimeInterface
  263.     {
  264.         return $this->created_at;
  265.     }
  266.     /**
  267.      * @return Collection|Library[]
  268.      */
  269.     public function getLibraries(): Collection
  270.     {
  271.         return $this->libraries;
  272.     }
  273.     public function addLibrary(Library $library): self
  274.     {
  275.         if (!$this->libraries->contains($library)) {
  276.             $this->libraries[] = $library;
  277.             $library->setCompany($this);
  278.         }
  279.         return $this;
  280.     }
  281.     public function removeLibrary(Library $library): self
  282.     {
  283.         if ($this->libraries->removeElement($library)) {
  284.             // set the owning side to null (unless already changed)
  285.             if ($library->getCompany() === $this) {
  286.                 $library->setCompany(null);
  287.             }
  288.         }
  289.         return $this;
  290.     }
  291.     /**
  292.      * @return Collection|Part[]
  293.      */
  294.     public function getParts(): Collection
  295.     {
  296.         return $this->parts;
  297.     }
  298.     public function addPart(Part $part): self
  299.     {
  300.         if (!$this->parts->contains($part)) {
  301.             $this->parts[] = $part;
  302.             $part->setCompany($this);
  303.         }
  304.         return $this;
  305.     }
  306.     public function removePart(Part $part): self
  307.     {
  308.         if ($this->parts->removeElement($part)) {
  309.             // set the owning side to null (unless already changed)
  310.             if ($part->getCompany() === $this) {
  311.                 $part->setCompany(null);
  312.             }
  313.         }
  314.         return $this;
  315.     }
  316.     public function getNif(): ?string
  317.     {
  318.         return $this->nif;
  319.     }
  320.     public function setNif(?string $nif): self
  321.     {
  322.         $this->nif $nif;
  323.         return $this;
  324.     }
  325.     public function getPhone(): ?string
  326.     {
  327.         return $this->phone;
  328.     }
  329.     public function setPhone(?string $phone): self
  330.     {
  331.         $this->phone $phone;
  332.         return $this;
  333.     }
  334.     public function getEmail(): ?string
  335.     {
  336.         return $this->email;
  337.     }
  338.     public function setEmail(?string $email): self
  339.     {
  340.         $this->email $email;
  341.         return $this;
  342.     }
  343.     public function getAddress(): ?string
  344.     {
  345.         return $this->address;
  346.     }
  347.     
  348.     public function setAddress(?string $address): self
  349.     {
  350.         $this->address $address;
  351.         return $this;
  352.     }
  353.     public function getUpdatedAt(): ?\DateTimeInterface
  354.     {
  355.         return $this->updated_at;
  356.     }
  357.     /**
  358.      * Set the value of updatedAt
  359.      *
  360.      * @param \DateTime $updatedAt
  361.      */
  362.     public function markAsUpdated() : void
  363.     {
  364.         $this->updated_at = new \DateTime();
  365.     }
  366.     public function getRef(): ?string
  367.     {
  368.         return $this->ref;
  369.     }
  370.     public function setRef(string $ref): self
  371.     {
  372.         $ref++;
  373.         $this->ref $ref;
  374.         return $this;
  375.     }
  376.     /**
  377.      * @return Collection|CompanySupplier[]
  378.      */
  379.     public function getCompanySuppliers(): Collection
  380.     {
  381.         return $this->companySuppliers;
  382.     }
  383.     public function addCompanySupplier(CompanySupplier $companySupplier): self
  384.     {
  385.         if (!$this->companySuppliers->contains($companySupplier)) {
  386.             $this->companySuppliers[] = $companySupplier;
  387.             $companySupplier->setCompany($this);
  388.         }
  389.         return $this;
  390.     }
  391.     public function removeCompanySupplier(CompanySupplier $companySupplier): self
  392.     {
  393.         if ($this->companySuppliers->removeElement($companySupplier)) {
  394.             // set the owning side to null (unless already changed)
  395.             if ($companySupplier->getCompany() === $this) {
  396.                 $companySupplier->setCompany(null);
  397.             }
  398.         }
  399.         return $this;
  400.     }
  401.     /**
  402.      * @return Collection<int, LicenseCompany>
  403.      */
  404.     public function getLicenseCompanies(): Collection
  405.     {
  406.         return $this->licenseCompanies;
  407.     }
  408.     public function addLicenseCompany(LicenseCompany $licenseCompany): self
  409.     {
  410.         if (!$this->licenseCompanies->contains($licenseCompany)) {
  411.             $this->licenseCompanies[] = $licenseCompany;
  412.             $licenseCompany->setCompany($this);
  413.         }
  414.         return $this;
  415.     }
  416.     public function removeLicenseCompany(LicenseCompany $licenseCompany): self
  417.     {
  418.         if ($this->licenseCompanies->removeElement($licenseCompany)) {
  419.             // set the owning side to null (unless already changed)
  420.             if ($licenseCompany->getCompany() === $this) {
  421.                 $licenseCompany->setCompany(null);
  422.             }
  423.         }
  424.         return $this;
  425.     }
  426.     /**
  427.      * @return Collection<int, Supplier>
  428.      */
  429.     public function getSuppliers(): Collection
  430.     {
  431.         return $this->suppliers;
  432.     }
  433.     public function addSupplier(Supplier $supplier): self
  434.     {
  435.         if (!$this->suppliers->contains($supplier)) {
  436.             $this->suppliers[] = $supplier;
  437.             $supplier->setCompany($this);
  438.         }
  439.         return $this;
  440.     }
  441.     public function removeSupplier(Supplier $supplier): self
  442.     {
  443.         if ($this->suppliers->removeElement($supplier)) {
  444.             // set the owning side to null (unless already changed)
  445.             if ($supplier->getCompany() === $this) {
  446.                 $supplier->setCompany(null);
  447.             }
  448.         }
  449.         return $this;
  450.     }
  451.     public function getType(): ?int
  452.     {
  453.         return $this->type;
  454.     }
  455.     public function setType(int $type): self
  456.     {
  457.         $this->type $type;
  458.         return $this;
  459.     }
  460.     public function getLicenseCompany(): ?LicenseCompany
  461.     {
  462.         return $this->licenseCompany;
  463.     }
  464.     public function setLicenseCompany(?LicenseCompany $licenseCompany): self
  465.     {
  466.         $this->licenseCompany $licenseCompany;
  467.         return $this;
  468.     }
  469.     public function getCertifications(): ?string
  470.     {
  471.         return $this->certifications;
  472.     }
  473.     public function setCertifications(string $certifications): self
  474.     {
  475.         $this->certifications $certifications;
  476.         return $this;
  477.     }
  478.     public function getServices(): ?string
  479.     {
  480.         return $this->services;
  481.     }
  482.     public function setServices(?string $services): self
  483.     {
  484.         $this->services $services;
  485.         return $this;
  486.     }
  487.     public function getWebPage(): ?string
  488.     {
  489.         return $this->web_page;
  490.     }
  491.     public function setWebPage(?string $web_page): self
  492.     {
  493.         $this->web_page $web_page;
  494.         return $this;
  495.     }
  496.     public function getLogo(): ?string
  497.     {
  498.         return $this->logo;
  499.     }
  500.     public function setLogo(?string $logo): self
  501.     {
  502.         $this->logo $logo;
  503.         return $this;
  504.     }
  505.     /**
  506.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  507.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  508.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  509.      * must be able to accept an instance of 'File' as the bundle will inject one here
  510.      * during Doctrine hydration.
  511.      *
  512.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  513.      */
  514.     public function setLogoFile(?File $logoFile null): void
  515.     {
  516.         $this->logoFile $logoFile;
  517.         if (null !== $logoFile) {
  518.             // It is required that at least one field changes if you are using doctrine
  519.             // otherwise the event listeners won't be called and the file is lost
  520.             $this->markAsUpdated();
  521.         }
  522.     }
  523.     public function getLogoFile(): ?File
  524.     {
  525.         return $this->logoFile;
  526.     }
  527.     public function getDescription(): ?string
  528.     {
  529.         return $this->description;
  530.     }
  531.     public function setDescription(?string $description): self
  532.     {
  533.         $this->description $description;
  534.         return $this;
  535.     }
  536.     /**
  537.      * @return Collection<int, Equipment>
  538.      */
  539.     public function getEquipment(): Collection
  540.     {
  541.         return $this->equipment;
  542.     }
  543.     public function addEquipment(Equipment $equipment): self
  544.     {
  545.         if (!$this->equipment->contains($equipment)) {
  546.             $this->equipment[] = $equipment;
  547.             $equipment->setCompany($this);
  548.         }
  549.         return $this;
  550.     }
  551.     public function removeEquipment(Equipment $equipment): self
  552.     {
  553.         if ($this->equipment->removeElement($equipment)) {
  554.             // set the owning side to null (unless already changed)
  555.             if ($equipment->getCompany() === $this) {
  556.                 $equipment->setCompany(null);
  557.             }
  558.         }
  559.         return $this;
  560.     }
  561.     /**
  562.      * @return Collection<int, Material>
  563.      */
  564.     public function getMaterials(): Collection
  565.     {
  566.         return $this->materials;
  567.     }
  568.     public function addMaterial(Material $material): self
  569.     {
  570.         if (!$this->materials->contains($material)) {
  571.             $this->materials[] = $material;
  572.             $material->setCompany($this);
  573.         }
  574.         return $this;
  575.     }
  576.     public function removeMaterial(Material $material): self
  577.     {
  578.         if ($this->materials->removeElement($material)) {
  579.             // set the owning side to null (unless already changed)
  580.             if ($material->getCompany() === $this) {
  581.                 $material->setCompany(null);
  582.             }
  583.         }
  584.         return $this;
  585.     }
  586.     /**
  587.      * @return Collection<int, CompanyAddress>
  588.      */
  589.     public function getCompanyAddresses(): Collection
  590.     {
  591.         return $this->companyAddresses;
  592.     }
  593.     public function addCompanyAddress(CompanyAddress $companyAddress): self
  594.     {
  595.         if (!$this->companyAddresses->contains($companyAddress)) {
  596.             $this->companyAddresses[] = $companyAddress;
  597.             $companyAddress->setCompany($this);
  598.         }
  599.         return $this;
  600.     }
  601.     public function removeCompanyAddress(CompanyAddress $companyAddress): self
  602.     {
  603.         if ($this->companyAddresses->removeElement($companyAddress)) {
  604.             // set the owning side to null (unless already changed)
  605.             if ($companyAddress->getCompany() === $this) {
  606.                 $companyAddress->setCompany(null);
  607.             }
  608.         }
  609.         return $this;
  610.     }
  611.     public function getCurrency(): ?int
  612.     {
  613.         return $this->currency;
  614.     }
  615.     public function setCurrency(int $currency): self
  616.     {
  617.         $this->currency $currency;
  618.         return $this;
  619.     }
  620.     public function getThema(): ?int
  621.     {
  622.         return $this->thema;
  623.     }
  624.     public function setThema(int $thema): self
  625.     {
  626.         $this->thema $thema;
  627.         return $this;
  628.     }
  629.     public function getColor(): ?string
  630.     {
  631.         return $this->color;
  632.     }
  633.     public function setColor(?string $color): self
  634.     {
  635.         $this->color $color;
  636.         return $this;
  637.     }
  638.     /**
  639.      * @return Collection<int, CompanyClient>
  640.      */
  641.     public function getCompanyClients(): Collection
  642.     {
  643.         return $this->companyClients;
  644.     }
  645.     public function addCompanyClient(CompanyClient $companyClient): self
  646.     {
  647.         if (!$this->companyClients->contains($companyClient)) {
  648.             $this->companyClients[] = $companyClient;
  649.             $companyClient->setCompany($this);
  650.         }
  651.         return $this;
  652.     }
  653.     public function removeCompanyClient(CompanyClient $companyClient): self
  654.     {
  655.         if ($this->companyClients->removeElement($companyClient)) {
  656.             // set the owning side to null (unless already changed)
  657.             if ($companyClient->getCompany() === $this) {
  658.                 $companyClient->setCompany(null);
  659.             }
  660.         }
  661.         return $this;
  662.     }
  663.     public function getCorporateColor(): ?string
  664.     {
  665.         return $this->corporate_color;
  666.     }
  667.     public function setCorporateColor(?string $corporate_color): self
  668.     {
  669.         $this->corporate_color $corporate_color;
  670.         return $this;
  671.     }
  672.     public function getCorporateTheme(): ?int
  673.     {
  674.         return $this->corporate_theme;
  675.     }
  676.     public function setCorporateTheme(?int $corporate_theme): self
  677.     {
  678.         $this->corporate_theme $corporate_theme;
  679.         return $this;
  680.     }
  681.     
  682. }