forked from Probesys/bileto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntityEvent.php
162 lines (130 loc) · 3.79 KB
/
EntityEvent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
// This file is part of Bileto.
// Copyright 2022-2025 Probesys
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace App\Entity;
use App\ActivityMonitor\RecordableEntityInterface;
use App\ActivityMonitor\TrackableEntityInterface;
use App\ActivityMonitor\TrackableEntityTrait;
use App\Repository\EntityEventRepository;
use App\Uid\UidEntityInterface;
use App\Uid\UidEntityTrait;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EntityEventRepository::class)]
#[ORM\Index(columns: ['entity_type', 'entity_id'])]
class EntityEvent implements TrackableEntityInterface, UidEntityInterface
{
use TrackableEntityTrait;
use UidEntityTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 20)]
private ?string $uid = null;
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\ManyToOne]
private ?User $createdBy = null;
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)]
private ?\DateTimeImmutable $updatedAt = null;
#[ORM\ManyToOne]
private ?User $updatedBy = null;
#[ORM\Column(length: 10)]
private ?string $type = null;
#[ORM\Column(length: 255)]
private ?string $entityType = null;
#[ORM\Column]
private ?int $entityId = null;
/** @var array<string, mixed[]> */
#[ORM\Column]
private array $changes = [];
public function getId(): ?int
{
return $this->id;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getEntityType(): ?string
{
return $this->entityType;
}
public function setEntityType(string $entityType): self
{
$this->entityType = $entityType;
return $this;
}
public function getEntityId(): ?int
{
return $this->entityId;
}
public function setEntityId(int $entityId): self
{
$this->entityId = $entityId;
return $this;
}
/**
* @return array<string, mixed[]>
*/
public function getChanges(): array
{
return $this->changes;
}
/**
* @param array<string, mixed[]> $changes
*/
public function setChanges(array $changes): self
{
$this->changes = $changes;
return $this;
}
/**
* Return true if the EntityEvent references the specified field.
*/
public function refersTo(string $field): bool
{
return isset($this->changes[$field]);
}
public static function initInsert(RecordableEntityInterface $entity): self
{
$entityEvent = new self();
$entityEvent->type = 'insert';
$entityEvent->entityType = $entity->getEntityType();
$entityEvent->entityId = $entity->getId();
$entityEvent->changes = [];
return $entityEvent;
}
/**
* @param array<string, mixed[]> $changes
*/
public static function initUpdate(RecordableEntityInterface $entity, array $changes): self
{
$entityEvent = new self();
$entityEvent->type = 'update';
$entityEvent->entityType = $entity->getEntityType();
$entityEvent->entityId = $entity->getId();
$entityEvent->changes = $changes;
return $entityEvent;
}
public static function initDelete(RecordableEntityInterface $entity): self
{
$entityEvent = new self();
$entityEvent->type = 'delete';
$entityEvent->entityType = $entity->getEntityType();
$entityEvent->entityId = $entity->getId();
$entityEvent->changes = [];
return $entityEvent;
}
public function getTimelineType(): string
{
return 'event';
}
}