1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\User; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @ORM\Table(name="posts", schema="posts", indexes={ |
11
|
|
|
* @ORM\Index(name="idx_post_created_at", columns={"created_at"}), |
12
|
|
|
* @ORM\Index(name="idx_post_private", columns={"private"}), |
13
|
|
|
* }) |
14
|
|
|
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository") |
15
|
|
|
* @ORM\HasLifecycleCallbacks |
16
|
|
|
*/ |
17
|
|
|
class Post |
18
|
|
|
{ |
19
|
|
|
public const TYPE_POST = 'post'; |
20
|
|
|
public const TYPE_FEED = 'feed'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
* |
25
|
|
|
* @ORM\Column(name="id", type="text") |
26
|
|
|
* @ORM\Id |
27
|
|
|
*/ |
28
|
|
|
private $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
* |
33
|
|
|
* @ORM\Column(name="text", type="text") |
34
|
|
|
*/ |
35
|
|
|
private $text; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var \DateTime |
39
|
|
|
* |
40
|
|
|
* @ORM\Column(name="created_at", type="datetime") |
41
|
|
|
*/ |
42
|
|
|
private $createdAt; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var \DateTime |
46
|
|
|
* |
47
|
|
|
* @ORM\Column(name="updated_at", type="datetime", nullable=true) |
48
|
|
|
*/ |
49
|
|
|
private $updatedAt; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string |
53
|
|
|
* |
54
|
|
|
* @ORM\Column(name="type", type="string", length=6) |
55
|
|
|
*/ |
56
|
|
|
private $type = self::TYPE_POST; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var bool |
60
|
|
|
* |
61
|
|
|
* @ORM\Column(name="private", type="boolean", nullable=true) |
62
|
|
|
*/ |
63
|
|
|
private $private; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var bool |
67
|
|
|
* |
68
|
|
|
* @ORM\Column(name="is_deleted", type="boolean") |
69
|
|
|
*/ |
70
|
|
|
private $deleted = false; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var User |
74
|
|
|
* |
75
|
|
|
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User") |
76
|
|
|
* @ORM\JoinColumn(name="author") |
77
|
|
|
*/ |
78
|
|
|
private $author; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var File[]|ArrayCollection |
82
|
|
|
* |
83
|
|
|
* @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File", fetch="EXTRA_LAZY", cascade={"persist"}) |
84
|
|
|
* @ORM\JoinTable(name="posts_files", schema="posts", |
85
|
|
|
* joinColumns={@ORM\JoinColumn(name="post_id")}, |
86
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="file_id")} |
87
|
|
|
* ) |
88
|
|
|
*/ |
89
|
|
|
private $files; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var Tag[]|ArrayCollection |
93
|
|
|
* |
94
|
|
|
* @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\PostTag", mappedBy="post", fetch="EXTRA_LAZY", cascade={"persist"}, orphanRemoval=true) |
95
|
|
|
*/ |
96
|
|
|
private $postTags; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @var Comment[]|ArrayCollection |
100
|
|
|
* |
101
|
|
|
* @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", mappedBy="post", cascade={"persist"}) |
102
|
|
|
*/ |
103
|
|
|
private $comments; |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Post constructor. |
108
|
|
|
* @param string $id |
109
|
|
|
*/ |
110
|
|
|
public function __construct($id) |
111
|
|
|
{ |
112
|
|
|
$this->id = $id; |
113
|
|
|
|
114
|
|
|
$this->files = new ArrayCollection(); |
115
|
|
|
$this->postTags = new ArrayCollection(); |
116
|
|
|
$this->comments = new ArrayCollection(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @ORM\PreUpdate |
121
|
|
|
*/ |
122
|
|
|
public function preUpdate(): void |
123
|
|
|
{ |
124
|
|
|
$this->updatedAt = new \DateTime(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function getId(): string |
128
|
|
|
{ |
129
|
|
|
return $this->id; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function setText(string $text): self |
133
|
|
|
{ |
134
|
1 |
|
$this->text = $text; |
135
|
|
|
|
136
|
1 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function getText(): string |
140
|
|
|
{ |
141
|
|
|
return $this->text; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function setCreatedAt(\DateTime $createdAt): self |
145
|
|
|
{ |
146
|
|
|
$this->createdAt = $createdAt; |
147
|
|
|
|
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function getCreatedAt(): \DateTime |
152
|
|
|
{ |
153
|
|
|
return $this->createdAt; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function getUpdatedAt(): ?\DateTime |
157
|
1 |
|
{ |
158
|
|
|
return $this->updatedAt; |
159
|
1 |
|
} |
160
|
|
|
|
161
|
|
|
public function setType(string $type): self |
162
|
|
|
{ |
163
|
|
|
$this->type = $type; |
164
|
|
|
|
165
|
|
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function getType(): string |
169
|
|
|
{ |
170
|
|
|
return $this->type; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function getAuthor(): User |
174
|
|
|
{ |
175
|
|
|
return $this->author; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function setAuthor(User $author): self |
179
|
|
|
{ |
180
|
1 |
|
$this->author = $author; |
181
|
|
|
|
182
|
1 |
|
return $this; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function addFile(File $files): self |
186
|
|
|
{ |
187
|
|
|
$this->files[] = $files; |
188
|
|
|
|
189
|
|
|
return $this; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function removeFile(File $files): void |
193
|
|
|
{ |
194
|
|
|
$this->files->removeElement($files); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Get files |
199
|
|
|
* |
200
|
|
|
* @return File[]|ArrayCollection |
201
|
|
|
*/ |
202
|
|
|
public function getFiles() |
203
|
|
|
{ |
204
|
|
|
return $this->files; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function addPostTag(PostTag $tag): self |
208
|
|
|
{ |
209
|
|
|
$tag->setPost($this); |
210
|
|
|
$this->postTags[] = $tag; |
211
|
|
|
|
212
|
|
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public function removePostTag(PostTag $tag): void |
216
|
|
|
{ |
217
|
|
|
$this->postTags->removeElement($tag); |
218
|
|
|
} |
219
|
1 |
|
|
220
|
|
|
/** |
221
|
1 |
|
* Get tags |
222
|
|
|
* |
223
|
|
|
* @return PostTag[]|ArrayCollection |
224
|
|
|
*/ |
225
|
|
|
public function getPostTags() |
226
|
|
|
{ |
227
|
|
|
return $this->postTags; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
public function setDeleted(bool $deleted): self |
231
|
|
|
{ |
232
|
|
|
$this->deleted = $deleted; |
233
|
|
|
|
234
|
|
|
return $this; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
public function getDeleted(): bool |
238
|
|
|
{ |
239
|
|
|
return $this->deleted; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
public function isDeleted(): bool |
243
|
|
|
{ |
244
|
|
|
return $this->deleted; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
public function setPrivate(bool $private): self |
248
|
|
|
{ |
249
|
|
|
$this->private = $private; |
250
|
|
|
|
251
|
|
|
return $this; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
public function isPrivate(): bool |
255
|
|
|
{ |
256
|
|
|
return $this->private; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
public function getPrivate(): bool |
260
|
|
|
{ |
261
|
|
|
return $this->private; |
262
|
1 |
|
} |
263
|
|
|
|
264
|
1 |
|
public function addComment(Comment $comment): self |
265
|
|
|
{ |
266
|
|
|
$this->comments[] = $comment; |
267
|
|
|
$comment->setPost($this); |
268
|
|
|
|
269
|
|
|
return $this; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
public function removeComment(Comment $comment): void |
273
|
|
|
{ |
274
|
|
|
$this->comments->removeElement($comment); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Get comments |
279
|
|
|
* |
280
|
|
|
* @return Comment[]|ArrayCollection |
281
|
|
|
*/ |
282
|
|
|
public function getComments() |
283
|
|
|
{ |
284
|
|
|
return $this->comments; |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
|