<?phpnamespace App\Entity;use App\Repository\StoreIndexationRepository;use DateTimeImmutable;use DateTimeInterface;use Doctrine\ORM\Mapping as ORM;use Gedmo\Mapping\Annotation as Gedmo; // gedmo annotationsuse Symfony\Component\Validator\Constraints as Assert;/** * @ORM\Entity(repositoryClass=StoreIndexationRepository::class) * @ORM\HasLifecycleCallbacks() */class StoreIndexation{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private int $id; /** * @ORM\ManyToOne(targetEntity=Store::class, inversedBy="storeIndexations") * @ORM\JoinColumn(nullable=false) */ private Store $store; /** * @ORM\Column(type="datetime_immutable") * @Gedmo\Timestampable(on="create") */ private DateTimeImmutable $createdAt; /** * @ORM\Column(type="integer") * @Assert\Range( * min = 1, * max = 12, * notInRangeMessage = "Le nombre de mois doit ĂȘtre entre {{ min }} et {{ max }}", * ) */ private int $nbMonths=12; /** * @ORM\Column(type="datetime_immutable") */ private DateTimeImmutable $startAt; /** * @ORM\Column(type="datetime_immutable") */ private DateTimeImmutable $endAt; /** * @ORM\Column(type="boolean") */ private bool $automaticRenewal=true; /** * @ORM\Column(type="boolean") */ private bool $renewed=false; /** * @ORM\ManyToOne(targetEntity=Order::class, inversedBy="storeIndexations") */ private ?Order $order; public function __construct() { $this->setStartAt(new DateTimeImmutable()); } //get label public function getLabel(): string { return 'Indexation de '.$this->store->getLabel().' du '.$this->startAt->format('d/m/Y').' au '.$this->endAt->format('d/m/Y'); } /** * @ORM\PrePersist */ public function computeEndAt(): void { $this->setEndAt($this->startAt->modify('+'.$this->nbMonths.' months')); } public function getId(): ?int { return $this->id; } public function getStore(): ?Store { return $this->store; } public function setStore(?Store $store): self { $this->store = $store; return $this; } public function getStartAt(): ?DateTimeInterface { return $this->startAt; } public function setStartAt(DateTimeInterface $startAt): self { if($startAt instanceof \DateTime) { $startAt = DateTimeImmutable::createFromMutable($startAt); } $this->startAt = $startAt; return $this; } public function getEndAt(): ?DateTimeInterface { return $this->endAt; } public function setEndAt(DateTimeInterface $endAt): self { if($endAt instanceof \DateTime) { $endAt = DateTimeImmutable::createFromMutable($endAt); } $this->endAt = $endAt; return $this; } public function getCreatedAt(): DateTimeImmutable { return $this->createdAt; } public function setCreatedAt(DateTimeImmutable $createdAt): void { $this->createdAt = $createdAt; } public function getNbMonths(): int { return $this->nbMonths; } public function setNbMonths(int $nbMonths): void { $this->nbMonths = $nbMonths; } public function isAutomaticRenewal(): bool { return $this->automaticRenewal; } public function setAutomaticRenewal(bool $automaticRenewal): void { $this->automaticRenewal = $automaticRenewal; } public function isRenewed(): bool { return $this->renewed; } public function setRenewed(bool $renewed): void { $this->renewed = $renewed; } public function getOrder(): ?Order { return $this->order; } public function setOrder(?Order $order): void { $this->order = $order; }}