src/Entity/Farm.php line 25

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\Serializer\Annotation\Groups;
  8. use Symfony\Component\Uid\Uuid;
  9. /**
  10.  * @ORM\Entity
  11.  * @ORM\Entity(repositoryClass="App\Repository\FarmRepository")
  12.  * @ORM\Table(indexes={
  13.  *   @ORM\Index(name="name",columns={"name"}),
  14.  *   @ORM\Index(name="deleted",columns={"deleted"}),
  15.  *   @ORM\Index(name="created",columns={"created"}),
  16.  *   @ORM\Index(name="createdAt",columns={"created_at"}),
  17.  *   @ORM\Index(name="updatedAt",columns={"updated_at"}),
  18.  *   @ORM\Index(name="deletedAt",columns={"deleted_at"}),
  19.  * })
  20.  * @ORM\HasLifecycleCallbacks
  21.  */
  22. class Farm
  23. {
  24.     /**
  25.      * @ORM\Id()
  26.      * @ORM\GeneratedValue()
  27.      * @ORM\Column(type="integer")
  28.      * @Groups({"read", "write", "api_get"})
  29.      */
  30.     private $id;
  31.     /**
  32.      * @ORM\Column(type="string", length=36, nullable=false)
  33.      */
  34.     private $uuid;
  35.     /**
  36.      * @ORM\Column(type="boolean", nullable=true)
  37.      * @Groups({"read", "write"})
  38.      */
  39.     private $cottage;
  40.     /**
  41.      * @ORM\Column(type="boolean", nullable=true)
  42.      * @Groups({"read", "write"})
  43.      */
  44.     private $raise;
  45.     /**
  46.      * @ORM\Column(type="string", length=255, nullable=true)
  47.      */
  48.     private $cuartel;
  49.     /**
  50.      * @ORM\Column(type="boolean", nullable=true)
  51.      */
  52.     private $feedlot;
  53.     /**
  54.      * @ORM\Column(type="boolean", nullable=true)
  55.      */
  56.     private $wintering;
  57.     /**
  58.      * @ORM\Column(type="boolean", nullable=true)
  59.      */
  60.     private $mix;
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      * @Groups({"api_get"})
  64.      */
  65.     private $name;
  66.     /**
  67.      * @ORM\Column(type="boolean", nullable=true)
  68.      */
  69.     private $other;
  70.     /**
  71.      * @ORM\Column(type="text", nullable=true)
  72.      */
  73.     private $picture;
  74.     /**
  75.      * @var \DateTime
  76.      * @ORM\Column(type="datetime", nullable=true)
  77.      */
  78.     private $created;
  79.     /**
  80.      * @ORM\Column(type="boolean", nullable=true)
  81.      */
  82.     private $tambo;
  83.     /**
  84.      * @ORM\Column(type="string", length=255, nullable=true)
  85.      */
  86.     private $tenure;
  87.     /**
  88.      * @ORM\Column(type="string", length=255, nullable=true)
  89.      * @Groups({"api_get"})
  90.      */
  91.     private $renspa;
  92.     /**
  93.      * @ORM\Column(type="string", length=255, nullable=true)
  94.      */
  95.     private $cuig;
  96.     /**
  97.      * @ORM\ManyToOne(targetEntity="Address",  cascade={"persist"})
  98.      * @ORM\JoinColumn(name="address_id", referencedColumnName="id")
  99.      */
  100.     private $address;
  101.     /**
  102.      * @ORM\Column(type="string", length=255, nullable=true)
  103.      */
  104.     private $hectares;
  105.     /**
  106.      * Many Farms have one producer.
  107.      * @ORM\ManyToOne(targetEntity="Producer", inversedBy="farms", cascade={"persist"})
  108.      * @ORM\JoinColumn(name="producer_id", referencedColumnName="id")
  109.      */
  110.     private $producer;
  111.     /**
  112.      * @ORM\Column(type="string", nullable=true)
  113.      */
  114.     private $timeStamp;
  115.     /**
  116.      * @var bool
  117.      * @ORM\Column(name="deleted", type="boolean", nullable=true)
  118.      * @Groups({"api_get"})
  119.      */
  120.     private $deleted false;
  121.     /**
  122.      * @ORM\OneToMany(targetEntity="Lot", mappedBy="farm")
  123.      */
  124.     private $lots;
  125.     /**
  126.      * @var bool
  127.      * @ORM\Column(name="demo", type="boolean", nullable=true)
  128.      * @Groups({"api_get"})
  129.      */
  130.     private $demo false;
  131.     /**
  132.      * Many Farms have One Organization
  133.      * @ORM\ManyToOne(targetEntity="Organization")
  134.      * @ORM\JoinColumn(name="organization_id", referencedColumnName="id")
  135.      */
  136.     private $organization;
  137.     /**
  138.      * One Farm has many locations.
  139.      * @ORM\OneToMany(targetEntity="Location", mappedBy="farm")
  140.      */
  141.     private $locations;
  142.     /**
  143.      * @ORM\Column(type="string", length=255, nullable=true)
  144.      */
  145.     private $activity;
  146.     /**
  147.      * @ORM\Column(type="datetime")
  148.      */
  149.     private $createdAt;
  150.     /**
  151.      * @ORM\Column(type="datetime")
  152.      */
  153.     private $updatedAt;
  154.     /**
  155.      * @ORM\Column(type="datetime", nullable=true)
  156.      */
  157.     private $deletedAt;
  158.     /**
  159.      * @ORM\OneToMany(targetEntity=FarmProducer::class, mappedBy="farm", orphanRemoval=false)
  160.      */
  161.     private $farmProducers;
  162.     /* desnormalizado de farmProducers */
  163.     private $producers;
  164.     /** @ORM\PreUpdate */
  165.     public function PreUpdate()
  166.     {
  167.         $this->setUpdatedAt( new \DateTime() );
  168.     }
  169.     /** @ORM\PrePersist */
  170.     public function PrePersist()
  171.     {
  172.         $this->setCreatedAt( new \DateTime() );
  173.         $this->setUpdatedAt( new \DateTime() );
  174.     }
  175.     public function __construct()
  176.     {
  177.         $this->created = new \DateTime();
  178.         $this->lots = new ArrayCollection();
  179.         $this->locations = new ArrayCollection();
  180.         $this->farmProducers = new ArrayCollection();
  181.         $this->uuid Uuid::v6();
  182.     }
  183.     public function getUuid()
  184.     {
  185.         return $this->uuid;
  186.     }
  187.     public function setUuid($uuid): self
  188.     {
  189.         $this->uuid $uuid;
  190.         return $this;
  191.     }
  192.     public function getId(): ?int
  193.     {
  194.         return $this->id;
  195.     }
  196.     public function setId($id)
  197.     {
  198.         $this->id $id;
  199.     }
  200.     public function getCottage(): ?bool
  201.     {
  202.         return $this->cottage;
  203.     }
  204.     public function setCottage(bool $cottage): self
  205.     {
  206.         $this->cottage $cottage;
  207.         return $this;
  208.     }
  209.     public function getRaise(): ?bool
  210.     {
  211.         return $this->raise;
  212.     }
  213.     public function setRaise(bool $raise): self
  214.     {
  215.         $this->raise $raise;
  216.         return $this;
  217.     }
  218.     public function getCuartel(): ?string
  219.     {
  220.         return $this->cuartel;
  221.     }
  222.     public function setCuartel(?string $cuartel): self
  223.     {
  224.         $this->cuartel $cuartel;
  225.         return $this;
  226.     }
  227.     public function getFeedlot(): ?bool
  228.     {
  229.         return $this->feedlot;
  230.     }
  231.     public function setFeedlot(bool $feedlot): self
  232.     {
  233.         $this->feedlot $feedlot;
  234.         return $this;
  235.     }
  236.     public function getWintering(): ?bool
  237.     {
  238.         return $this->wintering;
  239.     }
  240.     public function setWintering(?bool $wintering): self
  241.     {
  242.         $this->wintering $wintering;
  243.         return $this;
  244.     }
  245.     public function getMix(): ?bool
  246.     {
  247.         return $this->mix;
  248.     }
  249.     public function setMix(?bool $mix): self
  250.     {
  251.         $this->mix $mix;
  252.         return $this;
  253.     }
  254.     public function getName(): ?string
  255.     {
  256.         return $this->name;
  257.     }
  258.     public function setName(?string $name): self
  259.     {
  260.         $this->name $name;
  261.         return $this;
  262.     }
  263.     public function getOther(): ?bool
  264.     {
  265.         return $this->other;
  266.     }
  267.     public function setOther(?bool $other): self
  268.     {
  269.         $this->other $other;
  270.         return $this;
  271.     }
  272.     public function getPicture(): ?string
  273.     {
  274.         return $this->picture;
  275.     }
  276.     public function setPicture(?string $picture): self
  277.     {
  278.         $this->picture $picture;
  279.         return $this;
  280.     }
  281.     public function getTambo(): ?bool
  282.     {
  283.         return $this->tambo;
  284.     }
  285.     public function setTambo(?bool $tambo): self
  286.     {
  287.         $this->tambo $tambo;
  288.         return $this;
  289.     }
  290.     public function getTenure(): ?string
  291.     {
  292.         return $this->tenure;
  293.     }
  294.     public function setTenure(?string $tenure): self
  295.     {
  296.         $this->tenure $tenure;
  297.         return $this;
  298.     }
  299.     /**
  300.      * @return mixed
  301.      */
  302.     public function getAddress()
  303.     {
  304.         return $this->address;
  305.     }
  306.     /**
  307.      * @param mixed $address
  308.      */
  309.     public function setAddress($address): void
  310.     {
  311.         $this->address $address;
  312.     }
  313.     public function getHectares(): ?string
  314.     {
  315.         return $this->hectares;
  316.     }
  317.     public function setHectares(?string $hectares): self
  318.     {
  319.         $this->hectares $hectares;
  320.         return $this;
  321.     }
  322.     /**
  323.      * @return mixed
  324.      */
  325.     public function getCreated()
  326.     {
  327.         return $this->created;
  328.     }
  329.     /**
  330.      * @param mixed $created
  331.      */
  332.     public function setCreated($created)
  333.     {
  334.         $this->created $created;
  335.     }
  336.     /**
  337.      * @return mixed
  338.      */
  339.     public function getProducer()
  340.     {
  341.         return $this->producer;
  342.     }
  343.     /**
  344.      * @param mixed $producer
  345.      */
  346.     public function setProducer($producer): void
  347.     {
  348.         $this->producer $producer;
  349.     }
  350.     /**
  351.      * @return mixed
  352.      */
  353.     public function getTimeStamp()
  354.     {
  355.         return $this->timeStamp;
  356.     }
  357.     /**
  358.      * @param mixed $timeStamp
  359.      */
  360.     public function setTimeStamp($timeStamp): void
  361.     {
  362.         $this->timeStamp $timeStamp;
  363.     }
  364.     /**
  365.      * @return mixed
  366.      */
  367.     public function getRenspa()
  368.     {
  369.         return $this->renspa;
  370.     }
  371.     /**
  372.      * @param mixed $renspa
  373.      */
  374.     public function setRenspa($renspa): void
  375.     {
  376.         $this->renspa $renspa;
  377.     }
  378.     /**
  379.      * @return mixed
  380.      */
  381.     public function getCuig()
  382.     {
  383.         return $this->cuig;
  384.     }
  385.     /**
  386.      * @param mixed $cuig
  387.      */
  388.     public function setCuig($cuig): void
  389.     {
  390.         $this->cuig strtoupper($cuig);
  391.     }
  392.     /**
  393.      * @return bool
  394.      */
  395.     public function isDeleted(): bool
  396.     {
  397.         return $this->deleted;
  398.     }
  399.     public function setDeleted(bool $deleted): self
  400.     {
  401.         $this->deleted $deleted;
  402.         $this->deletedAt = ( $deleted ) ? new \DateTime() : null;
  403.         return $this;
  404.     }
  405.     public function __toString()
  406.     {
  407.         return $this->name ?? ' - ';
  408.     }
  409.     public function getDeleted(): ?bool
  410.     {
  411.         return $this->deleted;
  412.     }
  413.     public function getDemo(): ?bool
  414.     {
  415.         return $this->demo;
  416.     }
  417.     public function setDemo(?bool $demo): self
  418.     {
  419.         $this->demo $demo;
  420.         return $this;
  421.     }
  422.     /**
  423.      * @return Collection|Lot[]
  424.      */
  425.     public function getLots(): Collection
  426.     {
  427.         return $this->lots;
  428.     }
  429.     public function addLot(Lot $lot): self
  430.     {
  431.         if (!$this->lots->contains($lot)) {
  432.             $this->lots[] = $lot;
  433.             $lot->setFarm($this);
  434.         }
  435.         return $this;
  436.     }
  437.     public function removeLot(Lot $lot): self
  438.     {
  439.         if ($this->lots->removeElement($lot)) {
  440.             // set the owning side to null (unless already changed)
  441.             if ($lot->getFarm() === $this) {
  442.                 $lot->setFarm(null);
  443.             }
  444.         }
  445.         return $this;
  446.     }
  447.     public function getOrganization(): ?Organization
  448.     {
  449.         return $this->organization;
  450.     }
  451.     public function setOrganization(?Organization $organization): self
  452.     {
  453.         $this->organization $organization;
  454.         return $this;
  455.     }
  456.     /**
  457.      * @return Collection|Location[]
  458.      */
  459.     public function getLocations(): Collection
  460.     {
  461.         return $this->locations;
  462.     }
  463.     public function addLocation(Location $location): self
  464.     {
  465.         if (!$this->locations->contains($location)) {
  466.             $this->locations[] = $location;
  467.             $location->setFarm($this);
  468.         }
  469.         return $this;
  470.     }
  471.     public function removeLocation(Location $location): self
  472.     {
  473.         if ($this->locations->removeElement($location)) {
  474.             // set the owning side to null (unless already changed)
  475.             if ($location->getFarm() === $this) {
  476.                 $location->setFarm(null);
  477.             }
  478.         }
  479.         return $this;
  480.     }
  481.     public function isCottage(): ?bool
  482.     {
  483.         return $this->cottage;
  484.     }
  485.     public function isRaise(): ?bool
  486.     {
  487.         return $this->raise;
  488.     }
  489.     public function isFeedlot(): ?bool
  490.     {
  491.         return $this->feedlot;
  492.     }
  493.     public function isWintering(): ?bool
  494.     {
  495.         return $this->wintering;
  496.     }
  497.     public function isMix(): ?bool
  498.     {
  499.         return $this->mix;
  500.     }
  501.     public function isOther(): ?bool
  502.     {
  503.         return $this->other;
  504.     }
  505.     public function isTambo(): ?bool
  506.     {
  507.         return $this->tambo;
  508.     }
  509.     public function isDemo(): ?bool
  510.     {
  511.         return $this->demo;
  512.     }
  513.     public function getActivity(): ?string
  514.     {
  515.         return $this->activity;
  516.     }
  517.     public function setActivity(?string $activity): self
  518.     {
  519.         $this->activity $activity;
  520.         return $this;
  521.     }
  522.     public function getCreatedAt(): ?\DateTime
  523.     {
  524.         return $this->createdAt;
  525.     }
  526.     public function setCreatedAt(\DateTime $createdAt): self
  527.     {
  528.         $this->createdAt $createdAt;
  529.         return $this;
  530.     }
  531.     public function getUpdatedAt(): ?\DateTime
  532.     {
  533.         return $this->updatedAt;
  534.     }
  535.     public function setUpdatedAt(\DateTime $updatedAt): self
  536.     {
  537.         $this->updatedAt $updatedAt;
  538.         return $this;
  539.     }
  540.     public function getDeletedAt(): ?\DateTime
  541.     {
  542.         return $this->deletedAt;
  543.     }
  544.     public function setDeletedAt(?\DateTime $deletedAt): self
  545.     {
  546.         $this->deletedAt $deletedAt;
  547.         $this->deleted = (boolean) $deletedAt;
  548.         return $this;
  549.     }
  550.     /**
  551.      * @return Collection<int, FarmProducer>
  552.      */
  553.     public function getFarmProducers(): Collection
  554.     {
  555.         return $this->farmProducers;
  556.     }
  557.     public function addFarmProducer(FarmProducer $farmProducer): self
  558.     {
  559.         if (!$this->farmProducers->contains($farmProducer)) {
  560.             $this->farmProducers[] = $farmProducer;
  561.             $farmProducer->setFarm($this);
  562.         }
  563.         return $this;
  564.     }
  565.     public function removeFarmProducer(FarmProducer $farmProducer): self
  566.     {
  567.         if ($this->farmProducers->removeElement($farmProducer)) {
  568.             // set the owning side to null (unless already changed)
  569.             if ($farmProducer->getFarm() === $this) {
  570.                 $farmProducer->setDeletedAt( new \DateTime() );
  571.             }
  572.         }
  573.         return $this;
  574.     }
  575.     public function clearFarmProducers(): self
  576.     {
  577.         $this->farmProducers->clear();
  578.         return $this;
  579.     }
  580. }