src/Entity/Supplier.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SupplierRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. /**
  10.  * @ORM\Entity(repositoryClass=SupplierRepository::class)
  11.  */
  12. class Supplier
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=4)
  22.      */
  23.     private $ref;
  24.     /**
  25.      * @ORM\Column(type="string", length=255, nullable=true)
  26.      * @Assert\NotBlank
  27.      */
  28.     private $name;
  29.     /**
  30.      * @ORM\Column(type="string", length=255, nullable=true)
  31.      * @Assert\NotBlank
  32.      */
  33.     private $address;
  34.     /**
  35.      * @ORM\Column(type="integer", nullable=true)
  36.      */
  37.     private $phone;
  38.     /**
  39.      * @ORM\Column(type="string", length=100, nullable=true)
  40.      */
  41.     private $cif;
  42.     /**
  43.      * @ORM\Column(type="string", length=255, nullable=true)
  44.      */
  45.     private $work_center;
  46.     /**
  47.      * @ORM\Column(type="string", length=255, nullable=true)
  48.      */
  49.     private $contact;
  50.     /**
  51.      * @ORM\Column(type="string", length=255)
  52.      */
  53.     private $certifications;
  54.     /**
  55.      * @ORM\Column(type="string", length=255, nullable=true)
  56.      */
  57.     private $notes;
  58.     /**
  59.      * @ORM\Column(type="string", length=255, nullable=true)
  60.      */
  61.     private $others;
  62.     /**
  63.      * @ORM\Column(type="datetime", nullable=true)
  64.      */
  65.     private $created_at;
  66.     /**
  67.      * @ORM\Column(type="datetime", nullable=true)
  68.      */
  69.     private $updated_at;
  70.     /**
  71.      * @ORM\OneToOne(targetEntity=User::class, cascade={"persist", "remove"})
  72.      * @ORM\JoinColumn(onDelete="CASCADE")
  73.      */
  74.     private $user;
  75.     
  76.     /**
  77.      * @ORM\OneToMany(targetEntity=Part::class, mappedBy="supplier")
  78.      */
  79.     private $parts;
  80.     /**
  81.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="supplier")
  82.      */
  83.     private $users;
  84.     /**
  85.      * @ORM\OneToMany(targetEntity=CompanySupplier::class, mappedBy="supplier")
  86.      */
  87.     private $companySuppliers;
  88.     /**
  89.      * Permite colaboraciones externas
  90.      * 
  91.      * @ORM\Column(type="boolean")
  92.      */
  93.     private $collab;
  94.     /**
  95.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="suppliers")
  96.      * @ORM\JoinColumn(onDelete="CASCADE")
  97.      * @ORM\JoinColumn(nullable=false)
  98.      */
  99.     private $company;
  100.     /**
  101.      * @ORM\Column(type="string", length=100, nullable=true)
  102.      * 
  103.      * @Assert\Email(
  104.      *     message = "El email '{{ value }}' no es válido."
  105.      * )
  106.      */
  107.     private $email;
  108.     /**
  109.      * @ORM\Column(type="boolean", nullable=true)
  110.      */
  111.     private $marketplace;
  112.     public function __construct()
  113.     {    
  114.         $this->created_at = new \DateTime();
  115.         $this->markAsUpdated();
  116.         $this->parts = new ArrayCollection();
  117.         $this->users = new ArrayCollection();
  118.         $this->companySuppliers = new ArrayCollection();
  119.     }
  120.     // Registra el método mágico para imprimir el nombre del estado, por ejemplo, California
  121.     public function __toString() {
  122.         return $this->name;
  123.     }
  124.     public function getId(): ?int
  125.     {
  126.         return $this->id;
  127.     }
  128.     public function getRef(): ?string
  129.     {
  130.         return $this->ref;
  131.     }
  132.     public function setRef(string $ref): self
  133.     {
  134.         $ref++;
  135.         $this->ref $ref;
  136.         
  137.         return $this;
  138.     }
  139.     public function getName(): ?string
  140.     {
  141.         return $this->name;
  142.     }
  143.     public function setName(?string $name): self
  144.     {
  145.         $this->name $name;
  146.         return $this;
  147.     }
  148.     public function getAddress(): ?string
  149.     {
  150.         return $this->address;
  151.     }
  152.     public function setAddress(?string $address): self
  153.     {
  154.         $this->address $address;
  155.         return $this;
  156.     }
  157.     public function getPhone(): ?int
  158.     {
  159.         return $this->phone;
  160.     }
  161.     public function setPhone(?int $phone): self
  162.     {
  163.         $this->phone $phone;
  164.         return $this;
  165.     }
  166.     public function getCif(): ?string
  167.     {
  168.         return $this->cif;
  169.     }
  170.     public function setCif(?string $cif): self
  171.     {
  172.         $this->cif $cif;
  173.         return $this;
  174.     }
  175.     public function getWorkCenter(): ?string
  176.     {
  177.         return $this->work_center;
  178.     }
  179.     public function setWorkCenter(?string $work_center): self
  180.     {
  181.         $this->work_center $work_center;
  182.         return $this;
  183.     }
  184.     public function getContact(): ?string
  185.     {
  186.         return $this->contact;
  187.     }
  188.     public function setContact(?string $contact): self
  189.     {
  190.         $this->contact $contact;
  191.         return $this;
  192.     }
  193.     public function getCertifications(): ?string
  194.     {
  195.         return $this->certifications;
  196.     }
  197.     public function setCertifications(string $certifications): self
  198.     {
  199.         $this->certifications $certifications;
  200.         return $this;
  201.     }
  202.     public function getNotes(): ?string
  203.     {
  204.         return $this->notes;
  205.     }
  206.     public function setNotes(?string $notes): self
  207.     {
  208.         $this->notes $notes;
  209.         return $this;
  210.     }
  211.     public function getOthers(): ?string
  212.     {
  213.         return $this->others;
  214.     }
  215.     public function setOthers(?string $others): self
  216.     {
  217.         $this->others $others;
  218.         return $this;
  219.     }
  220.     public function getCreatedAt(): ?\DateTimeInterface
  221.     {
  222.         return $this->created_at;
  223.     }
  224.     public function getUpdatedAt(): ?\DateTimeInterface
  225.     {
  226.         return $this->updated_at;
  227.     }
  228.     /**
  229.      * Set the value of updatedAt
  230.      *
  231.      * @param \DateTime $updatedAt
  232.      */
  233.     public function markAsUpdated() : void
  234.     {
  235.         $this->updated_at = new \DateTime();
  236.     }
  237.     public function getUser(): ?User
  238.     {
  239.         return $this->user;
  240.     }
  241.     public function setUser(User $user): self
  242.     {
  243.         $this->user $user;
  244.         return $this;
  245.     }
  246.     /**
  247.      * @return Collection|Part[]
  248.      */
  249.     public function getParts(): Collection
  250.     {
  251.         return $this->parts;
  252.     }
  253.     public function addPart(Part $part): self
  254.     {
  255.         if (!$this->parts->contains($part)) {
  256.             $this->parts[] = $part;
  257.             $part->setSupplier($this);
  258.         }
  259.         return $this;
  260.     }
  261.     public function removePart(Part $part): self
  262.     {
  263.         if ($this->parts->removeElement($part)) {
  264.             // set the owning side to null (unless already changed)
  265.             if ($part->getSupplier() === $this) {
  266.                 $part->setSupplier(null);
  267.             }
  268.         }
  269.         return $this;
  270.     }
  271.     /**
  272.      * @return Collection<int, User>
  273.      */
  274.     public function getUsers(): Collection
  275.     {
  276.         return $this->users;
  277.     }
  278.     public function addUsers(User $users): self
  279.     {
  280.         if (!$this->users->contains($users)) {
  281.             $this->users[] = $users;
  282.             $users->setSupplier($this);
  283.         }
  284.         return $this;
  285.     }
  286.     public function removeUsers(User $users): self
  287.     {
  288.         if ($this->users->removeElement($users)) {
  289.             // set the owning side to null (unless already changed)
  290.             if ($users->getSupplier() === $this) {
  291.                 $users->setSupplier(null);
  292.             }
  293.         }
  294.         return $this;
  295.     }
  296.     /**
  297.      * @return Collection<int, CompanySupplier>
  298.      */
  299.     public function getCompanySuppliers(): Collection
  300.     {
  301.         return $this->companySuppliers;
  302.     }
  303.     public function addCompanySupplier(CompanySupplier $companySupplier): self
  304.     {
  305.         if (!$this->companySuppliers->contains($companySupplier)) {
  306.             $this->companySuppliers[] = $companySupplier;
  307.             $companySupplier->setSupplier($this);
  308.         }
  309.         return $this;
  310.     }
  311.     public function removeCompanySupplier(CompanySupplier $companySupplier): self
  312.     {
  313.         if ($this->companySuppliers->removeElement($companySupplier)) {
  314.             // set the owning side to null (unless already changed)
  315.             if ($companySupplier->getSupplier() === $this) {
  316.                 $companySupplier->setSupplier(null);
  317.             }
  318.         }
  319.         return $this;
  320.     }
  321.     public function getCollab(): ?bool
  322.     {
  323.         return $this->collab;
  324.     }
  325.     public function setCollab(bool $collab): self
  326.     {
  327.         $this->collab $collab;
  328.         return $this;
  329.     }
  330.     public function getCompany(): ?Company
  331.     {
  332.         return $this->company;
  333.     }
  334.     public function setCompany(?Company $company): self
  335.     {
  336.         $this->company $company;
  337.         return $this;
  338.     }
  339.     public function getEmail(): ?string
  340.     {
  341.         return $this->email;
  342.     }
  343.     public function setEmail(?string $email): self
  344.     {
  345.         $this->email $email;
  346.         return $this;
  347.     }
  348.     public function getMarketplace(): ?bool
  349.     {
  350.         return $this->marketplace;
  351.     }
  352.     public function setMarketplace(?bool $marketplace): self
  353.     {
  354.         $this->marketplace $marketplace;
  355.         return $this;
  356.     }
  357. }