src/CmsBundle/Entity/Log.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\CmsBundle\Entity;
  3. use App\ProfileBundle\Entity\User;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * @ORM\Table(
  7.  *     name="log",
  8.  *     indexes={
  9.  *         @ORM\Index(name="created", columns={"created"})
  10.  *     }
  11.  * )
  12.  * @ORM\Entity(repositoryClass="App\CmsBundle\Repository\LogRepository")
  13.  * @ORM\HasLifecycleCallbacks()
  14.  */
  15. class Log
  16. {
  17.     use IdTrait;
  18.     /**
  19.      * @ORM\Column(
  20.      *     type="string",
  21.      *     length=255,
  22.      *     nullable=false
  23.      *     )
  24.      */
  25.     private $action;
  26.     /**
  27.      * @ORM\Column(
  28.      *     type="string",
  29.      *     length=255,
  30.      *     nullable=true
  31.      *     )
  32.      */
  33.     private $entity;
  34.     /**
  35.      * @ORM\ManyToOne(
  36.      *     targetEntity="App\ProfileBundle\Entity\User",
  37.      *     inversedBy="logs"
  38.      * )
  39.      * @ORM\JoinColumn(nullable=false)
  40.      */
  41.     private $user;
  42.     /**
  43.      * @var \DateTime
  44.      *
  45.      * @ORM\Column(name="created", type="datetime")
  46.      */
  47.     private $created;
  48.     /**
  49.      * @ORM\Column(
  50.      *     name="context",
  51.      *     type="text",
  52.      *     nullable=true
  53.      * )
  54.      */
  55.     private ?string $context null;
  56.     /**
  57.      * @param User $user
  58.      * @param string $action
  59.      * @param $context
  60.      */
  61.     public function __construct(User $userstring $actionstring $entity$context null)
  62.     {
  63.         $this->setUser($user)->setAction($action)->setEntity($entity)->setContext($context);
  64.     }
  65.     public function __toString(): string
  66.     {
  67.         return $this->id;
  68.     }
  69.     /**
  70.      * @return int|null
  71.      */
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     /**
  77.      * @return string|null
  78.      */
  79.     public function getAction(): ?string
  80.     {
  81.         return $this->action;
  82.     }
  83.     /**
  84.      * @param string $action
  85.      * @return $this
  86.      */
  87.     public function setAction(string $action): self
  88.     {
  89.         $this->action $action;
  90.         return $this;
  91.     }
  92.     /**
  93.      * @return string|null
  94.      */
  95.     public function getEntity(): ?string
  96.     {
  97.         return $this->entity;
  98.     }
  99.     /**
  100.      * @param string $entity
  101.      * @return $this
  102.      */
  103.     public function setEntity(string $entity): self
  104.     {
  105.         $this->entity $entity;
  106.         return $this;
  107.     }
  108.     /**
  109.      * @return User|null
  110.      */
  111.     public function getUser(): ?User
  112.     {
  113.         return $this->user;
  114.     }
  115.     /**
  116.      * @param User|null $user
  117.      * @return $this
  118.      */
  119.     public function setUser(?User $user): self
  120.     {
  121.         $this->user $user;
  122.         return $this;
  123.     }
  124.     /**
  125.      * @return string|null
  126.      */
  127.     public function getContext(): ?string
  128.     {
  129.         return ($this->context)
  130.             ? json_encode(json_decode($this->contexttrue), JSON_PRETTY_PRINT)
  131.             : '';
  132.     }
  133.     /**
  134.      * @param object|array|null $context
  135.      * @return $this
  136.      */
  137.     public function setContext(object|array|null $context): self
  138.     {
  139.         $this->context json_encode($context);
  140.         return $this;
  141.     }
  142.     /**
  143.      * Set initial value for created/updated values
  144.      *
  145.      * @ORM\PrePersist
  146.      */
  147.     public function setCreated()
  148.     {
  149.         $this->created = new \DateTime();
  150.     }
  151.     /**
  152.      * @return \DateTime
  153.      */
  154.     public function getCreated(): \DateTime
  155.     {
  156.         return $this->created;
  157.     }
  158. }