src/Entity/Producer.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\ProducerRepository")
  10.  * @ORM\Table(indexes={              
  11.  *   @ORM\Index(name="cuig",columns={"cuig"}),
  12.  *   @ORM\Index(name="cuit",columns={"cuit"}),
  13.  *   @ORM\Index(name="name",columns={"name"}),
  14.  *   @ORM\Index(name="renspa",columns={"renspa"}),
  15.  *   @ORM\Index(name="createdAt",columns={"created_at"}),
  16.  *   @ORM\Index(name="updatedAt",columns={"updated_at"}),
  17.  *   @ORM\Index(name="deletedAt",columns={"deleted_at"}),
  18.  *   @ORM\Index(name="created",columns={"created"}),
  19.  *   @ORM\Index(name="updated",columns={"updated"}),
  20.  *  })
  21.  *      })
  22.  * @ORM\HasLifecycleCallbacks
  23.  */
  24. class Producer {
  25.     /**
  26.      * @ORM\Id()
  27.      * @ORM\GeneratedValue()
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     private $id;
  31.      /**
  32.      * @ORM\Column(type="string", length=36, nullable=true)
  33.      */
  34.     private $uuid;
  35.     /**
  36.      * @ORM\Column(type="string", length=255, nullable=true)
  37.      */
  38.     private $firebaseId;
  39.     /**
  40.      * @ORM\Column(type="string", length=255)
  41.      */
  42.     private $name;
  43.     /**
  44.      * @ORM\Column(type="string", length=255, nullable=true)
  45.      */
  46.     private $cuit;
  47.     /**
  48.      * @ORM\Column(type="text", nullable=true)
  49.      */
  50.     private $picture;
  51.     /**
  52.      * @ORM\Column(type="string", length=255, nullable=true)
  53.      */
  54.     private $email;
  55.     /**
  56.      * @ORM\Column(type="string", nullable=true)
  57.      */
  58.     private $phone;
  59.     /**
  60.      * @ORM\Column(type="string", length=255, nullable=true)
  61.      */
  62.     private $businessName;
  63.     /**
  64.      * @ORM\Column(type="boolean")
  65.      */
  66.     private $toUpdate;
  67.     /**
  68.      * @ORM\Column(type="datetime")
  69.      */
  70.     private $created;
  71.     /**
  72.      * @ORM\Column(type="datetime")
  73.      */
  74.     private $updated;
  75.     /**
  76.      * @ORM\ManyToOne(targetEntity="User", cascade={"persist"})
  77.      * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  78.      */
  79.     private $user;
  80.     /**
  81.      * @ORM\ManyToOne(targetEntity="Address", cascade={"persist"})
  82.      * @ORM\JoinColumn(name="address_id", referencedColumnName="id")
  83.      */
  84.     private $address;
  85.     /**
  86.      * @ORM\OneToMany(targetEntity="Farm", mappedBy="producer")
  87.      */
  88.     private $farms;
  89.     /**
  90.      * @var bool
  91.      * @ORM\Column(name="deleted", type="boolean", nullable=true)
  92.      */
  93.     private $deleted false;
  94.     /**
  95.      * @var bool
  96.      * @ORM\Column(name="demo", type="boolean", nullable=true)
  97.      */
  98.     private $demo false;
  99.     /**
  100.     * One Producer has many Animals.
  101.     * @ORM\OneToMany(targetEntity="Animal", mappedBy="producer")
  102.     */
  103.     private $animals;
  104.     /**
  105.      * @ORM\Column(type="string", length=255, nullable=true)
  106.      */
  107.     private $renspa;
  108.     /**
  109.      * @ORM\Column(type="string", length=255, nullable=true)
  110.      */
  111.     private $cuig;
  112.     /**
  113.      * Many Producers have One Organization
  114.      * @ORM\ManyToOne(targetEntity="Organization")
  115.      * @ORM\JoinColumn(name="organization_id", referencedColumnName="id")
  116.      */
  117.     private $organization;
  118.     /**
  119.      * @ORM\Column(type="datetime")
  120.      */
  121.     private $createdAt;
  122.     /**
  123.      * @ORM\Column(type="datetime")
  124.      */
  125.     private $updatedAt;
  126.     /**
  127.      * @ORM\Column(type="datetime", nullable=true)
  128.      */
  129.     private $deletedAt;
  130.     /**
  131.      * @ORM\OneToMany(targetEntity=FarmProducer::class, mappedBy="producer", orphanRemoval=true)
  132.      */
  133.     private $farmProducers;
  134.     /**
  135.      * @ORM\Column(type="string", length=255)
  136.      */
  137.     private $surname;
  138.     /** @ORM\PreUpdate */
  139.     public function PreUpdate()
  140.     {
  141.         $this->setUpdatedAt( new \DateTime() );
  142.     }
  143.     /** @ORM\PrePersist */
  144.     public function PrePersist()
  145.     {
  146.         $this->setCreatedAt( new \DateTime() );
  147.         $this->setUpdatedAt( new \DateTime() );
  148.     }
  149.     public function __construct() {
  150.         $this->farms = new ArrayCollection();
  151.         $this->created = new \Datetime;
  152.         $this->updated = new \Datetime;
  153.         $this->animals = new ArrayCollection();
  154.         $this->establishments = new ArrayCollection();
  155.         $this->toUpdate false;
  156.         $this->farmProducers = new ArrayCollection();
  157.     }
  158.     public function getId(): ?int {
  159.         return $this->id;
  160.     }
  161.     public function setId($id) {
  162.         $this->id $id;
  163.     }
  164.     public function getUuid()
  165.     {
  166.         return $this->uuid;
  167.     }
  168.     public function setUuid($uuid): self
  169.     {
  170.         $this->uuid $uuid;
  171.         return $this;
  172.     }
  173.     /**
  174.      * @return mixed
  175.      */
  176.     public function getFirebaseId() {
  177.         return $this->firebaseId;
  178.     }
  179.     /**
  180.      * @param mixed $firebaseId
  181.      */
  182.     public function setFirebaseId($firebaseId) {
  183.         $this->firebaseId $firebaseId;
  184.     }
  185.     /**
  186.      * @return mixed
  187.      */
  188.     public function getName() {
  189.         return $this->name;
  190.     }
  191.     /**
  192.      * @param mixed $name
  193.      */
  194.     public function setName($name) {
  195.         $this->name $name;
  196.     }
  197.     /**
  198.      * @return mixed
  199.      */
  200.     public function getCuit() {
  201.         return $this->cuit;
  202.     }
  203.     /**
  204.      * @param mixed $cuit
  205.      */
  206.     public function setCuit($cuit) {
  207.         $this->cuit strtoupper($cuit);
  208.     }
  209.     /**
  210.      * @return mixed
  211.      */
  212.     public function getPicture() {
  213.         return $this->picture;
  214.     }
  215.     /**
  216.      * @param mixed $picture
  217.      */
  218.     public function setPicture($picture) {
  219.         $this->picture $picture;
  220.     }
  221.     /**
  222.      * @return mixed
  223.      */
  224.     public function getEmail() {
  225.         return $this->email;
  226.     }
  227.     /**
  228.      * @param mixed $email
  229.      */
  230.     public function setEmail($email) {
  231.         $this->email $email;
  232.     }
  233.     /**
  234.      * @return mixed
  235.      */
  236.     public function getPhone() {
  237.         return $this->phone;
  238.     }
  239.     /**
  240.      * @param mixed $phone
  241.      */
  242.     public function setPhone($phone) {
  243.         $this->phone $phone;
  244.     }
  245.     /**
  246.      * @return mixed
  247.      */
  248.     public function getBusinessName() {
  249.         return $this->businessName;
  250.     }
  251.     /**
  252.      * @param mixed $businessName
  253.      */
  254.     public function setBusinessName($businessName): void {
  255.         $this->businessName $businessName;
  256.     }
  257.     /**
  258.      * @return mixed
  259.      */
  260.     public function getToUpdate() {
  261.         return $this->toUpdate;
  262.     }
  263.     /**
  264.      * @param mixed $toUpdate
  265.      */
  266.     public function setToUpdate($toUpdate) {
  267.         $this->toUpdate $toUpdate;
  268.     }
  269.     /**
  270.      * @return mixed
  271.      */
  272.     public function getCreated() {
  273.         return $this->created;
  274.     }
  275.     /**
  276.      * @param mixed $created
  277.      */
  278.     public function setCreated($created) {
  279.         $this->created $created;
  280.     }
  281.     /**
  282.      * @return mixed
  283.      */
  284.     public function getUpdated() {
  285.         return $this->updated;
  286.     }
  287.     /**
  288.      * @param mixed $updated
  289.      */
  290.     public function setUpdated($updated): void {
  291.         $this->updated $updated;
  292.     }
  293.     /**
  294.      * @return mixed
  295.      */
  296.     public function getUser() {
  297.         return $this->user;
  298.     }
  299.     /**
  300.      * @param mixed $user
  301.      */
  302.     public function setUser($user): void {
  303.         $this->user $user;
  304.     }
  305.     /**
  306.      * @return mixed
  307.      */
  308.     public function getAddress() {
  309.         return $this->address;
  310.     }
  311.     /**
  312.      * @param mixed $address
  313.      */
  314.     public function setAddress($address): void {
  315.         $this->address $address;
  316.     }
  317.     /**
  318.      * @return mixed
  319.      */
  320.     public function getFarms() {
  321.         return $this->establishments//Replace farms by establishments - #9055
  322.     }
  323.     /**
  324.      * Add Farm
  325.      *
  326.      * @param $farm
  327.      * @return Producer
  328.      */
  329.     public function addFarm($farm null) {
  330.         $this->farms->add($farm);
  331.         return $this;
  332.     }
  333.     /**
  334.      * Remove Farm
  335.      *
  336.      * @param $farm
  337.      */
  338.     public function removeFarm($farm null) {
  339.         $this->farms->removeElement($farm);
  340.     }
  341.     public function __toString() {
  342.         return $this->name ?? $this->businessName;
  343.     }
  344.     /**
  345.      * @return bool
  346.      */
  347.     public function isDeleted(): bool {
  348.         return $this->deleted;
  349.     }
  350.     public function setDeleted(bool $deleted): self
  351.     {
  352.         $this->deleted $deleted;
  353.         $this->deletedAt = ( $deleted ) ? new \DateTime() : null;
  354.         return $this;
  355.     }
  356.     public function getDeleted(): ?bool {
  357.         return $this->deleted;
  358.     }
  359.     public function getDemo(): ?bool
  360.     {
  361.         return $this->demo;
  362.     }
  363.     public function setDemo(?bool $demo): self
  364.     {
  365.         $this->demo $demo;
  366.         return $this;
  367.     }
  368.     /**
  369.      * @return Collection|Animal[]
  370.      */
  371.     public function getAnimals(): Collection
  372.     {
  373.         return $this->animals;
  374.     }
  375.     public function addAnimal(Animal $animal): self
  376.     {
  377.         if (!$this->animals->contains($animal)) {
  378.             $this->animals[] = $animal;
  379.             $animal->setProducer($this);
  380.         }
  381.         return $this;
  382.     }
  383.     public function removeAnimal(Animal $animal): self
  384.     {
  385.         if ($this->animals->removeElement($animal)) {
  386.             // set the owning side to null (unless already changed)
  387.             if ($animal->getProducer() === $this) {
  388.                 $animal->setProducer(null);
  389.             }
  390.         }
  391.         return $this;
  392.     }
  393.     public function getRenspa(): ?string
  394.     {
  395.         return $this->renspa;
  396.     }
  397.     public function setRenspa(?string $renspa): self
  398.     {
  399.         $this->renspa $renspa;
  400.         return $this;
  401.     }
  402.     public function getCuig(): ?string
  403.     {
  404.         return $this->cuig;
  405.     }
  406.     public function setCuig(?string $cuig): self
  407.     {
  408.         $this->cuig $cuig;
  409.         return $this;
  410.     }
  411.     public function getOrganization(): ?Organization
  412.     {
  413.         return $this->organization;
  414.     }
  415.     public function setOrganization(?Organization $organization): self
  416.     {
  417.         $this->organization $organization;
  418.         return $this;
  419.     }
  420.     public function isToUpdate(): ?bool
  421.     {
  422.         return $this->toUpdate;
  423.     }
  424.     public function isDemo(): ?bool
  425.     {
  426.         return $this->demo;
  427.     }
  428.     public function getCreatedAt(): ?\DateTime
  429.     {
  430.         return $this->createdAt;
  431.     }
  432.     public function setCreatedAt(\DateTime $createdAt): self
  433.     {
  434.         $this->createdAt $createdAt;
  435.         return $this;
  436.     }
  437.     public function getUpdatedAt(): ?\DateTime
  438.     {
  439.         return $this->updatedAt;
  440.     }
  441.     public function setUpdatedAt(\DateTime $updatedAt): self
  442.     {
  443.         $this->updatedAt $updatedAt;
  444.         return $this;
  445.     }
  446.     public function getDeletedAt(): ?\DateTime
  447.     {
  448.         return $this->deletedAt;
  449.     }
  450.     public function setDeletedAt(?\DateTime $deletedAt): self
  451.     {
  452.         $this->deletedAt $deletedAt;
  453.         $this->deleted = (boolean) $deletedAt;
  454.         return $this;
  455.     }
  456.     /**
  457.      * @return Collection<int, FarmProducer>
  458.      */
  459.     public function getFarmProducers(): Collection
  460.     {
  461.         return $this->farmProducers;
  462.     }
  463.     public function addFarmProducer(FarmProducer $farmProducer): self
  464.     {
  465.         if (!$this->farmProducers->contains($farmProducer)) {
  466.             $this->farmProducers[] = $farmProducer;
  467.             $farmProducer->setProducer($this);
  468.         }
  469.         return $this;
  470.     }
  471.     public function removeFarmProducer(FarmProducer $farmProducer): self
  472.     {
  473.         if ($this->farmProducers->removeElement($farmProducer)) {
  474.             // set the owning side to null (unless already changed)
  475.             if ($farmProducer->getProducer() === $this) {
  476.                 $farmProducer->setProducer(null);
  477.             }
  478.         }
  479.         return $this;
  480.     }
  481.     public function getSurname(): ?string
  482.     {
  483.         return $this->surname;
  484.     }
  485.     public function setSurname(string $surname): self
  486.     {
  487.         $this->surname $surname;
  488.         return $this;
  489.     }
  490. }