src/Entity/StoreIndexation.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\StoreIndexationRepository;
  4. use DateTimeImmutable;
  5. use DateTimeInterface;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo// gedmo annotations
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Entity(repositoryClass=StoreIndexationRepository::class)
  11.  * @ORM\HasLifecycleCallbacks()
  12.  */
  13. class StoreIndexation
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private int $id;
  21.     /**
  22.      * @ORM\ManyToOne(targetEntity=Store::class, inversedBy="storeIndexations")
  23.      * @ORM\JoinColumn(nullable=false)
  24.      */
  25.     private Store $store;
  26.     /**
  27.      * @ORM\Column(type="datetime_immutable")
  28.      * @Gedmo\Timestampable(on="create")
  29.      */
  30.     private DateTimeImmutable $createdAt;
  31.     /**
  32.      * @ORM\Column(type="integer")
  33.      * @Assert\Range(
  34.      *      min = 1,
  35.      *      max = 12,
  36.      *      notInRangeMessage = "Le nombre de mois doit ĂȘtre entre {{ min }} et {{ max }}",
  37.      * )
  38.      */
  39.     private int $nbMonths=12;
  40.     /**
  41.      * @ORM\Column(type="datetime_immutable")
  42.      */
  43.     private DateTimeImmutable $startAt;
  44.     /**
  45.      * @ORM\Column(type="datetime_immutable")
  46.      */
  47.     private DateTimeImmutable $endAt;
  48.     /**
  49.      * @ORM\Column(type="boolean")
  50.      */
  51.     private bool $automaticRenewal=true;
  52.     /**
  53.      * @ORM\Column(type="boolean")
  54.      */
  55.     private bool $renewed=false;
  56.     /**
  57.      * @ORM\ManyToOne(targetEntity=Order::class, inversedBy="storeIndexations")
  58.      */
  59.     private ?Order $order;
  60.     public function __construct()
  61.     {
  62.         $this->setStartAt(new DateTimeImmutable());
  63.     }
  64.     //get label
  65.     public function getLabel(): string
  66.     {
  67.         return 'Indexation de '.$this->store->getLabel().' du '.$this->startAt->format('d/m/Y').' au '.$this->endAt->format('d/m/Y');
  68.     }
  69.     /**
  70.      * @ORM\PrePersist
  71.      */
  72.     public function computeEndAt(): void
  73.     {
  74.         $this->setEndAt($this->startAt->modify('+'.$this->nbMonths.' months'));
  75.     }
  76.     public function getId(): ?int
  77.     {
  78.         return $this->id;
  79.     }
  80.     public function getStore(): ?Store
  81.     {
  82.         return $this->store;
  83.     }
  84.     public function setStore(?Store $store): self
  85.     {
  86.         $this->store $store;
  87.         return $this;
  88.     }
  89.     public function getStartAt(): ?DateTimeInterface
  90.     {
  91.         return $this->startAt;
  92.     }
  93.     public function setStartAt(DateTimeInterface $startAt): self
  94.     {
  95.         if($startAt instanceof \DateTime) {
  96.             $startAt DateTimeImmutable::createFromMutable($startAt);
  97.         }
  98.         $this->startAt $startAt;
  99.         return $this;
  100.     }
  101.     public function getEndAt(): ?DateTimeInterface
  102.     {
  103.         return $this->endAt;
  104.     }
  105.     public function setEndAt(DateTimeInterface $endAt): self
  106.     {
  107.         if($endAt instanceof \DateTime) {
  108.             $endAt DateTimeImmutable::createFromMutable($endAt);
  109.         }
  110.         $this->endAt $endAt;
  111.         return $this;
  112.     }
  113.     public function getCreatedAt(): DateTimeImmutable
  114.     {
  115.         return $this->createdAt;
  116.     }
  117.     public function setCreatedAt(DateTimeImmutable $createdAt): void
  118.     {
  119.         $this->createdAt $createdAt;
  120.     }
  121.     public function getNbMonths(): int
  122.     {
  123.         return $this->nbMonths;
  124.     }
  125.     public function setNbMonths(int $nbMonths): void
  126.     {
  127.         $this->nbMonths $nbMonths;
  128.     }
  129.     public function isAutomaticRenewal(): bool
  130.     {
  131.         return $this->automaticRenewal;
  132.     }
  133.     public function setAutomaticRenewal(bool $automaticRenewal): void
  134.     {
  135.         $this->automaticRenewal $automaticRenewal;
  136.     }
  137.     public function isRenewed(): bool
  138.     {
  139.         return $this->renewed;
  140.     }
  141.     public function setRenewed(bool $renewed): void
  142.     {
  143.         $this->renewed $renewed;
  144.     }
  145.     public function getOrder(): ?Order
  146.     {
  147.         return $this->order;
  148.     }
  149.     public function setOrder(?Order $order): void
  150.     {
  151.         $this->order $order;
  152.     }
  153. }