1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Blog\Entity; |
6
|
|
|
|
7
|
|
|
use App\User\User; |
8
|
|
|
use Cycle\Annotated\Annotation\Column; |
9
|
|
|
use Cycle\Annotated\Annotation\Entity; |
10
|
|
|
use Cycle\Annotated\Annotation\Relation\BelongsTo; |
11
|
|
|
use Cycle\Annotated\Annotation\Table; |
12
|
|
|
use Cycle\Annotated\Annotation\Table\Index; |
13
|
|
|
use DateTimeImmutable; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @Entity( |
17
|
|
|
* repository="App\Blog\Comment\CommentRepository", |
18
|
|
|
* mapper="App\Blog\Comment\CommentMapper", |
19
|
|
|
* constrain="App\Blog\Comment\Scope\PublicScope" |
20
|
|
|
* ) |
21
|
|
|
* @Table( |
22
|
|
|
* indexes={ |
23
|
|
|
* @Index(columns={"public","published_at"}) |
24
|
|
|
* } |
25
|
|
|
* ) |
26
|
|
|
*/ |
27
|
|
|
class Comment |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @Column(type="primary") |
31
|
|
|
*/ |
32
|
|
|
private ?int $id = null; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @Column(type="bool", default="false") |
36
|
|
|
*/ |
37
|
|
|
private bool $public = false; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @Column(type="text") |
41
|
|
|
*/ |
42
|
|
|
private string $content; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @Column(type="datetime") |
46
|
|
|
*/ |
47
|
|
|
private DateTimeImmutable $created_at; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @Column(type="datetime") |
51
|
|
|
*/ |
52
|
|
|
private DateTimeImmutable $updated_at; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @Column(type="datetime", nullable=true) |
56
|
|
|
*/ |
57
|
|
|
private ?DateTimeImmutable $published_at = null; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @Column(type="datetime", nullable=true) |
61
|
|
|
*/ |
62
|
|
|
private ?DateTimeImmutable $deleted_at = null; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @BelongsTo(target="App\User\User", nullable=false, load="eager") |
66
|
|
|
* |
67
|
|
|
* @var \Cycle\ORM\Promise\Reference|User |
68
|
|
|
*/ |
69
|
|
|
private $user = null; |
70
|
|
|
private ?int $user_id = null; |
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @BelongsTo(target="App\Blog\Entity\Post", nullable=false) |
74
|
|
|
* |
75
|
|
|
* @var \Cycle\ORM\Promise\Reference|Post |
76
|
|
|
*/ |
77
|
|
|
private $post = null; |
78
|
|
|
private ?int $post_id = null; |
|
|
|
|
79
|
|
|
|
80
|
|
|
public function __construct(string $content) |
81
|
|
|
{ |
82
|
|
|
$this->content = $content; |
83
|
|
|
$this->created_at = new DateTimeImmutable(); |
84
|
|
|
$this->updated_at = new DateTimeImmutable(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getId(): ?int |
88
|
|
|
{ |
89
|
|
|
return $this->id; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getContent(): string |
93
|
|
|
{ |
94
|
|
|
return $this->content; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function setContent(string $content): void |
98
|
|
|
{ |
99
|
|
|
$this->content = $content; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function isPublic(): bool |
103
|
|
|
{ |
104
|
|
|
return $this->public; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function setPublic(bool $public): void |
108
|
|
|
{ |
109
|
|
|
$this->public = $public; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getCreatedAt(): DateTimeImmutable |
113
|
|
|
{ |
114
|
|
|
return $this->created_at; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function getUpdatedAt(): DateTimeImmutable |
118
|
|
|
{ |
119
|
|
|
return $this->updated_at; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getDeletedAt(): ?DateTimeImmutable |
123
|
|
|
{ |
124
|
|
|
return $this->deleted_at; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function setUser(User $user): void |
128
|
|
|
{ |
129
|
|
|
$this->user = $user; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function getUser(): ?User |
133
|
|
|
{ |
134
|
|
|
return $this->user; |
|
|
|
|
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function setPost(Post $post): void |
138
|
|
|
{ |
139
|
|
|
$this->post = $post; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function getPost(): ?Post |
143
|
|
|
{ |
144
|
|
|
return $this->post; |
|
|
|
|
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function getPublishedAt(): ?DateTimeImmutable |
148
|
|
|
{ |
149
|
|
|
return $this->published_at; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function setPublishedAt(?DateTimeImmutable $published_at): void |
153
|
|
|
{ |
154
|
|
|
$this->published_at = $published_at; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|