src/Entity/AuditLog.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use App\AuditLog\AuditLogMessage;
  5. use App\Helpers\Utils;
  6. use App\Repository\AuditLogRepository;
  7. use DateTimeImmutable;
  8. use DateTimeInterface;
  9. use Doctrine\ORM\Mapping as ORM;
  10. /**
  11.  * @ORM\Entity(repositoryClass=AuditLogRepository::class)
  12.  * @ORM\Table(name="audit_log", indexes={
  13.  *      @ORM\Index(name="idx_opdate", columns={"opdate"}),
  14.  *      @ORM\Index(name="idx_resource", columns={"resource"}),
  15.  *      @ORM\Index(name="idx_action", columns={"action"}),
  16.  * })
  17.  */
  18. class AuditLog
  19. {
  20.     /**
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue
  23.      * @ORM\Column(type="integer")
  24.      */
  25.     private ?int $id null;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=User::class)
  28.      * @ORM\JoinColumn(nullable=false)
  29.      */
  30.     private User $user;
  31.     /**
  32.      * @ORM\Column(type="string", length=255)
  33.      */
  34.     private string $resource;
  35.     /**
  36.      * @ORM\Column(type="string", length=255)
  37.      */
  38.     private string $action;
  39.     /**
  40.      * @ORM\Column(type="text", nullable=true)
  41.      */
  42.     private ?string $message;
  43.     /**
  44.      * @ORM\Column(type="datetime")
  45.      */
  46.     private DateTimeInterface $opdate;
  47.     /**
  48.      * @ORM\Column(type="string", length=255)
  49.      */
  50.     private string $ip;
  51.     public function __construct(User $userAuditLogMessage $messagestring $ip '')
  52.     {
  53.         $this->user $user;
  54.         $this->resource $message->getResourceName();
  55.         $this->action $message->getActionName();
  56.         $this->message $message->convertToDatabaseValue($message);
  57.         $this->opdate = new DateTimeImmutable();
  58.         $this->ip $ip;
  59.     }
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getUser(): User
  65.     {
  66.         return $this->user;
  67.     }
  68.     public function setUser(User $user): self
  69.     {
  70.         $this->user $user;
  71.         return $this;
  72.     }
  73.     public function getResource(): ?string
  74.     {
  75.         return $this->resource;
  76.     }
  77.     public function setResource(string $resource): self
  78.     {
  79.         $this->resource $resource;
  80.         return $this;
  81.     }
  82.     public function getAction(): ?string
  83.     {
  84.         return $this->action;
  85.     }
  86.     public function setAction(string $action): self
  87.     {
  88.         $this->action $action;
  89.         return $this;
  90.     }
  91.     public function getMessage(): ?string
  92.     {
  93.         return $this->message;
  94.     }
  95.     public function setMessage(?string $message): self
  96.     {
  97.         $this->message $message;
  98.         return $this;
  99.     }
  100.     public function getOpdate(): ?DateTimeInterface
  101.     {
  102.         return $this->opdate;
  103.     }
  104.     public function setOpdate(DateTimeInterface $opdate): self
  105.     {
  106.         $this->opdate $opdate;
  107.         return $this;
  108.     }
  109.     public function getIp(): ?string
  110.     {
  111.         return $this->ip;
  112.     }
  113.     public function setIp(string $ip): self
  114.     {
  115.         $this->ip $ip;
  116.         return $this;
  117.     }
  118. }