<?phpnamespace App\Entity;use App\Entity\Traits\ActivableTrait;use App\Entity\Traits\EntityIdTrait;use App\Entity\Traits\TimestampableTrait;use App\Repository\FormLeadRepository;use DateTime;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Exception;use Symfony\Component\Uid\Uuid;/** * @ORM\Entity(repositoryClass=FormLeadRepository::class) * @ORM\HasLifecycleCallbacks() */class FormLead{    use EntityIdTrait;    use TimestampableTrait;    use ActivableTrait;    /**     * @var DateTime     * @ORM\Column(type="datetime")     */    private $periodStartsAt;    /**     * @var DateTime     * @ORM\Column(type="datetime")     */    private $periodUpdatedAt;    /**     * @var bool     * @ORM\Column(type="boolean")     */    private $eventForced = false;    /**     * @ORM\ManyToOne(targetEntity=Campaign::class, inversedBy="formLeads")     * @ORM\JoinColumn(nullable=false)     */    private $campaign;    /**     * @ORM\OneToMany(targetEntity=FormLeadData::class, mappedBy="formLead")     */    private $formLeadData;    public function __construct()    {        $this->formLeadData = new ArrayCollection();        $this->uuid = Uuid::v6();    }    /**     * @return DateTime|null     */    public function getPeriodStartsAt(): ?DateTime    {        return $this->periodStartsAt;    }    /**     * @param DateTime $periodStartsAt     * @return $this     */    public function setPeriodStartsAt(DateTime $periodStartsAt): self    {        $this->periodStartsAt = $periodStartsAt;        return $this;    }    /**     * @return DateTime|null     */    public function getPeriodUpdatedAt(): ?DateTime    {        return $this->periodUpdatedAt;    }    /**     * @param DateTime $periodUpdatedAt     * @return $this     */    public function setPeriodUpdatedAt(DateTime $periodUpdatedAt): self    {        $this->periodUpdatedAt = $periodUpdatedAt;        return $this;    }    /**     * @return bool     */    public function isEventForced(): bool    {        return $this->eventForced;    }    /**     * @param bool $eventForced     * @return $this     */    public function setEventForced(bool $eventForced): self    {        $this->eventForced = $eventForced;        return $this;    }    /**     * @return Campaign|null     */    public function getCampaign(): ?Campaign    {        return $this->campaign;    }    /**     * @param Campaign|null $campaign     * @return $this     */    public function setCampaign(?Campaign $campaign): self    {        $this->campaign = $campaign;        return $this;    }    /**     * @return Collection<int, FormLeadData>     */    public function getFormLeadData(): Collection    {        return $this->formLeadData;    }    /**     * @param FormLeadData $formLeadData     * @return $this     */    public function addFormLeadData(FormLeadData $formLeadData): self    {        if (!$this->formLeadData->contains($formLeadData)) {            $this->formLeadData[] = $formLeadData;            $formLeadData->setFormLead($this);        }        return $this;    }    /**     * @param FormLeadData $formLeadData     * @return $this     */    public function removeFormLeadData(FormLeadData $formLeadData): self    {        if ($this->formLeadData->removeElement($formLeadData)) {            // set the owning side to null (unless already changed)            if ($formLeadData->getFormLead() === $this) {                $formLeadData->setFormLead(null);            }        }        return $this;    }    /**     * @return ArrayCollection     * @throws Exception     */    public function getOrderedByCreateFormLeadData(): ArrayCollection    {        $collection = new ArrayCollection();        foreach ($this->formLeadData as $item) {            $collection->add($item);        }        $iterator = $collection->getIterator();        $iterator->uasort(function (FormLeadData $a, FormLeadData $b) {            return ($a->getCreatedAt() > $b->getCreatedAt()) ? -1 : 1;        });        return new ArrayCollection(iterator_to_array($iterator));    }}