src/Entity/BaseEntity.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use phpDocumentor\Reflection\Types\Boolean;
  5. /** @ORM\MappedSuperclass */
  6. class BaseEntity
  7. {
  8.     /**
  9.      * @ORM\Id()
  10.      * @ORM\GeneratedValue()
  11.      * @ORM\Column(type="integer")
  12.      */
  13.     protected $id;
  14.     /**
  15.      * @ORM\Column(type="datetime", options={"default" = "CURRENT_TIMESTAMP"})
  16.      */
  17.     protected $createdAt;
  18.     /**
  19.      * @ORM\Column(type="datetime", nullable=true)
  20.      */
  21.     protected $updatedAt;
  22.     /**
  23.      * @ORM\Column(type="boolean", nullable=false)
  24.      */
  25.     protected $isDeleted;
  26.     public function getId(): ?int
  27.     {
  28.         return $this->id;
  29.     }
  30.     public function __construct()
  31.     {
  32.     }
  33.     public function getCreatedAt(): ?\DateTimeInterface
  34.     {
  35.         return $this->createdAt;
  36.     }
  37.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  38.     {
  39.         $this->createdAt $createdAt;
  40.         return $this;
  41.     }
  42.     public function getUpdatedAt(): ?\DateTimeInterface
  43.     {
  44.         return $this->updatedAt;
  45.     }
  46.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  47.     {
  48.         $this->updatedAt $updatedAt;
  49.         return $this;
  50.     }
  51.     public function getIsDeleted(): ?bool
  52.     {
  53.         return $this->isDeleted;
  54.     }
  55.     public function setIsDeleted(bool $isDeleted): self
  56.     {
  57.         $this->isDeleted $isDeleted;
  58.         return $this;
  59.     }
  60.     /**
  61.      * @ORM\PrePersist
  62.      * @ORM\PreUpdate
  63.      */
  64.     public function updatedTimestamps(): void
  65.     {
  66.         $this->setUpdatedAt(new \DateTime('now'));
  67.         if ($this->getCreatedAt() === null) {
  68.             $this->setCreatedAt(new \DateTime('now'));
  69.             $this->isDeleted false;
  70.         }
  71.     }
  72. }