src/Entity/EntityLog.php line 310

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\EntityLog\Type;
  4. use App\Library\Utils\Dev\ReflectionUtils\ReflectionUtils;
  5. use App\Repository\EntityLogRepository;
  6. use App\Service\EntityLog\EntityLogService;
  7. use App\Service\EntityService;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10.  * @ORM\Entity(repositoryClass=EntityLogRepository::class)
  11.  */
  12. class EntityLog
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=255)
  22.      */
  23.     private $entityClass;
  24.     /**
  25.      * @ORM\Column(type="enum", options={"values"="entity_log_enum", "default"="update"})
  26.      */
  27.     private $type Type::TYPE_UPDATE;
  28.     /**
  29.      * @ORM\Column(type="datetime")
  30.      */
  31.     private $createdAt;
  32.     /**
  33.      * @ORM\Column(type="string", length=255, nullable=true)
  34.      */
  35.     private $fieldName;
  36.     /**
  37.      * @ORM\Column(type="text", nullable=true)
  38.      */
  39.     private $oldValue;
  40.     /**
  41.      * @ORM\Column(type="text", nullable=true)
  42.      */
  43.     private $newValue;
  44.     /**
  45.      * @ORM\Column(type="integer", nullable=true)
  46.      */
  47.     private $entityId;
  48.     /**
  49.      * @ORM\ManyToOne(targetEntity=User::class)
  50.      * @ORM\JoinColumn(nullable=true)
  51.      */
  52.     private $editedBy;
  53.     /**
  54.      * @ORM\ManyToOne(targetEntity=Student::class)
  55.      * @ORM\JoinColumn(nullable=true)
  56.      */
  57.     private $student;
  58.     /**
  59.      * @ORM\ManyToOne(targetEntity=Person::class)
  60.      * @ORM\JoinColumn(nullable=true)
  61.      */
  62.     private $person;
  63.     /**
  64.      * @ORM\ManyToOne(targetEntity=UserSettings::class)
  65.      * @ORM\JoinColumn(nullable=true)
  66.      */
  67.     private $userSettings;
  68.     /**
  69.      * @ORM\ManyToOne(targetEntity=Candidate::class)
  70.      * @ORM\JoinColumn(nullable=true)
  71.      */
  72.     private $candidate;
  73.     /**
  74.      * @ORM\ManyToOne(targetEntity=Payment::class)
  75.      * @ORM\JoinColumn(nullable=true)
  76.      */
  77.     private $payment;
  78.     /**
  79.      * @ORM\Column(type="text", nullable=true)
  80.      */
  81.     private $data;
  82.     /**
  83.      * @ORM\Column(type="text", nullable=true)
  84.      */
  85.     private $oldData;
  86.     public function __construct()
  87.     {
  88.         $this->createdAt = new \DateTime();
  89.     }
  90.     public function getId(): ?int
  91.     {
  92.         return $this->id;
  93.     }
  94.     public function getEntityClass(): ?string
  95.     {
  96.         return $this->entityClass;
  97.     }
  98.     public function setEntityClass(string $entityClass): self
  99.     {
  100.         $this->entityClass $entityClass;
  101.         return $this;
  102.     }
  103.     public function getType(): ?string
  104.     {
  105.         return $this->type;
  106.     }
  107.     public function setType(string $type): self
  108.     {
  109.         $this->type $type;
  110.         return $this;
  111.     }
  112.     public function getCreatedAt(): ?\DateTime
  113.     {
  114.         return $this->createdAt;
  115.     }
  116.     public function setCreatedAt(\DateTime $createdAt): self
  117.     {
  118.         $this->createdAt $createdAt;
  119.         return $this;
  120.     }
  121.     public function getFieldName(): ?string
  122.     {
  123.         return $this->fieldName;
  124.     }
  125.     public function setFieldName(?string $fieldName): self
  126.     {
  127.         $this->fieldName $fieldName;
  128.         return $this;
  129.     }
  130.     public function getOldValue(): ?string
  131.     {
  132.         return $this->oldValue;
  133.     }
  134.     public function setOldValue(?string $oldValue): self
  135.     {
  136.         $this->oldValue $oldValue;
  137.         return $this;
  138.     }
  139.     public function getNewValue(): ?string
  140.     {
  141.         return $this->newValue;
  142.     }
  143.     public function setNewValue(?string $newValue): self
  144.     {
  145.         $this->newValue $newValue;
  146.         return $this;
  147.     }
  148.     public function getEntityId(): ?int
  149.     {
  150.         return $this->entityId;
  151.     }
  152.     public function setEntityId(?int $entityId): self
  153.     {
  154.         $this->entityId $entityId;
  155.         return $this;
  156.     }
  157.     public function getEditedBy(): ?User
  158.     {
  159.         return $this->editedBy;
  160.     }
  161.     public function setEditedBy(?User $editedBy): self
  162.     {
  163.         $this->editedBy $editedBy;
  164.         return $this;
  165.     }
  166.     public function getStudent(): ?Student
  167.     {
  168.         return $this->student;
  169.     }
  170.     public function setStudent(?Student $student): self
  171.     {
  172.         $this->student $student;
  173.         return $this;
  174.     }
  175.     public function getPerson(): ?Person
  176.     {
  177.         return $this->person;
  178.     }
  179.     public function setPerson(?Person $person): self
  180.     {
  181.         $this->person $person;
  182.         return $this;
  183.     }
  184.     public function getUserSettings(): ?UserSettings
  185.     {
  186.         return $this->userSettings;
  187.     }
  188.     public function setUserSettings(?UserSettings $userSettings): self
  189.     {
  190.         $this->userSettings $userSettings;
  191.         return $this;
  192.     }
  193.     public function getCandidate(): ?Candidate
  194.     {
  195.         return $this->candidate;
  196.     }
  197.     public function setCandidate(?Candidate $candidate): self
  198.     {
  199.         $this->candidate $candidate;
  200.         return $this;
  201.     }
  202.     public function getPayment(): ?Payment
  203.     {
  204.         return $this->payment;
  205.     }
  206.     public function setPayment(?Payment $payment): self
  207.     {
  208.         $this->payment $payment;
  209.         return $this;
  210.     }
  211.     public function getTypeText(): string
  212.     {
  213.         return Type::getText($this->type);
  214.     }
  215.     public function getTypeCss(): string
  216.     {
  217.         return Type::getCssClass($this->type);
  218.     }
  219.     public function getEntityClassCss(): string
  220.     {
  221.         return EntityService::getEntityClassCssClass("App\\Entity\\{$this->entityClass}");
  222.     }
  223.     public function getEntityText(): string
  224.     {
  225.         return EntityService::getEntityClassText($this->entityClass);
  226.     }
  227.     public function getEntity()
  228.     {
  229.         return $this->getPerson() ?? $this->getStudent() ?? $this->getUserSettings() ?? $this->getCandidate() ?? $this->getPayment();
  230.     }
  231.     public function setEntity($entity): self
  232.     {
  233.         if ($entity instanceof Person) {
  234.             return $this->setPerson($entity);
  235.         } elseif ($entity instanceof Student) {
  236.             return $this->setStudent($entity);
  237.         } elseif ($entity instanceof UserSettings) {
  238.             return $this->setUserSettings($entity);
  239.         } elseif ($entity instanceof Candidate) {
  240.             return $this->setCandidate($entity);
  241.         } elseif ($entity instanceof Payment) {
  242.             return $this->setPayment($entity);
  243.         }
  244.         return $this;
  245.     }
  246.     public function getEntityFieldText(): ?string
  247.     {
  248.         $entityClass "App\\Entity\\{$this->entityClass}";
  249.         $text null;
  250.         $entity $this->getEntity();
  251.         if ($entity && method_exists($entityClass'getFieldText')) {
  252.             $text $entityClass::getFieldText($this->fieldName);
  253.         }
  254.         return $text ?: $this->fieldName;
  255.     }
  256.     public function getOldFieldValueText(): ?string
  257.     {
  258.         $oldValue $this->getOldValue();
  259.         return $this->getFieldValueText($oldValue);
  260.     }
  261.     public function getNewFieldValueText(): ?string
  262.     {
  263.         $newValue $this->getNewValue();
  264.         $result $this->getFieldValueText($newValue);
  265.         return $result;
  266.     }
  267.     private function getFieldValueText($val)
  268.     {
  269.         return EntityLogService::entityFieldValueText(
  270.             $this->getEntity(), $this->fieldName$val
  271.         );
  272.     }
  273.     public function getData(): ?array
  274.     {
  275.         return json_decode($this->datatrue);
  276.     }
  277.     public function setData(?array $data): self
  278.     {
  279.         $this->data json_encode($data,
  280.             JSON_UNESCAPED_UNICODE JSON_UNESCAPED_SLASHES);
  281.         return $this;
  282.     }
  283.     public function getOldData(): ?array
  284.     {
  285.         return json_decode($this->oldDatatrue);
  286.     }
  287.     public function setOldData(?array $oldData): self
  288.     {
  289.         $this->oldData json_encode($oldData,
  290.             JSON_UNESCAPED_UNICODE JSON_UNESCAPED_SLASHES);
  291.         return $this;
  292.     }
  293. }