src/Entity/FormLead.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\ActivableTrait;
  4. use App\Entity\Traits\EntityIdTrait;
  5. use App\Entity\Traits\TimestampableTrait;
  6. use App\Repository\FormLeadRepository;
  7. use DateTime;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Exception;
  12. use Symfony\Component\Uid\Uuid;
  13. /**
  14.  * @ORM\Entity(repositoryClass=FormLeadRepository::class)
  15.  * @ORM\HasLifecycleCallbacks()
  16.  */
  17. class FormLead
  18. {
  19.     use EntityIdTrait;
  20.     use TimestampableTrait;
  21.     use ActivableTrait;
  22.     /**
  23.      * @var DateTime
  24.      * @ORM\Column(type="datetime")
  25.      */
  26.     private $periodStartsAt;
  27.     /**
  28.      * @var DateTime
  29.      * @ORM\Column(type="datetime")
  30.      */
  31.     private $periodUpdatedAt;
  32.     /**
  33.      * @var bool
  34.      * @ORM\Column(type="boolean")
  35.      */
  36.     private $eventForced false;
  37.     /**
  38.      * @ORM\ManyToOne(targetEntity=Campaign::class, inversedBy="formLeads")
  39.      * @ORM\JoinColumn(nullable=false)
  40.      */
  41.     private $campaign;
  42.     /**
  43.      * @ORM\OneToMany(targetEntity=FormLeadData::class, mappedBy="formLead")
  44.      */
  45.     private $formLeadData;
  46.     public function __construct()
  47.     {
  48.         $this->formLeadData = new ArrayCollection();
  49.         $this->uuid Uuid::v6();
  50.     }
  51.     /**
  52.      * @return DateTime|null
  53.      */
  54.     public function getPeriodStartsAt(): ?DateTime
  55.     {
  56.         return $this->periodStartsAt;
  57.     }
  58.     /**
  59.      * @param DateTime $periodStartsAt
  60.      * @return $this
  61.      */
  62.     public function setPeriodStartsAt(DateTime $periodStartsAt): self
  63.     {
  64.         $this->periodStartsAt $periodStartsAt;
  65.         return $this;
  66.     }
  67.     /**
  68.      * @return DateTime|null
  69.      */
  70.     public function getPeriodUpdatedAt(): ?DateTime
  71.     {
  72.         return $this->periodUpdatedAt;
  73.     }
  74.     /**
  75.      * @param DateTime $periodUpdatedAt
  76.      * @return $this
  77.      */
  78.     public function setPeriodUpdatedAt(DateTime $periodUpdatedAt): self
  79.     {
  80.         $this->periodUpdatedAt $periodUpdatedAt;
  81.         return $this;
  82.     }
  83.     /**
  84.      * @return bool
  85.      */
  86.     public function isEventForced(): bool
  87.     {
  88.         return $this->eventForced;
  89.     }
  90.     /**
  91.      * @param bool $eventForced
  92.      * @return $this
  93.      */
  94.     public function setEventForced(bool $eventForced): self
  95.     {
  96.         $this->eventForced $eventForced;
  97.         return $this;
  98.     }
  99.     /**
  100.      * @return Campaign|null
  101.      */
  102.     public function getCampaign(): ?Campaign
  103.     {
  104.         return $this->campaign;
  105.     }
  106.     /**
  107.      * @param Campaign|null $campaign
  108.      * @return $this
  109.      */
  110.     public function setCampaign(?Campaign $campaign): self
  111.     {
  112.         $this->campaign $campaign;
  113.         return $this;
  114.     }
  115.     /**
  116.      * @return Collection<int, FormLeadData>
  117.      */
  118.     public function getFormLeadData(): Collection
  119.     {
  120.         return $this->formLeadData;
  121.     }
  122.     /**
  123.      * @param FormLeadData $formLeadData
  124.      * @return $this
  125.      */
  126.     public function addFormLeadData(FormLeadData $formLeadData): self
  127.     {
  128.         if (!$this->formLeadData->contains($formLeadData)) {
  129.             $this->formLeadData[] = $formLeadData;
  130.             $formLeadData->setFormLead($this);
  131.         }
  132.         return $this;
  133.     }
  134.     /**
  135.      * @param FormLeadData $formLeadData
  136.      * @return $this
  137.      */
  138.     public function removeFormLeadData(FormLeadData $formLeadData): self
  139.     {
  140.         if ($this->formLeadData->removeElement($formLeadData)) {
  141.             // set the owning side to null (unless already changed)
  142.             if ($formLeadData->getFormLead() === $this) {
  143.                 $formLeadData->setFormLead(null);
  144.             }
  145.         }
  146.         return $this;
  147.     }
  148.     /**
  149.      * @return ArrayCollection
  150.      * @throws Exception
  151.      */
  152.     public function getOrderedByCreateFormLeadData(): ArrayCollection
  153.     {
  154.         $collection = new ArrayCollection();
  155.         foreach ($this->formLeadData as $item) {
  156.             $collection->add($item);
  157.         }
  158.         $iterator $collection->getIterator();
  159.         $iterator->uasort(function (FormLeadData $aFormLeadData $b) {
  160.             return ($a->getCreatedAt() > $b->getCreatedAt()) ? -1;
  161.         });
  162.         return new ArrayCollection(iterator_to_array($iterator));
  163.     }
  164. }