1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PiedWeb\ConversationBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use PiedWeb\CMSBundle\Entity\IdTrait; |
7
|
|
|
use PiedWeb\CMSBundle\Entity\TimestampableTrait; |
8
|
|
|
use PiedWeb\ConversationBundle\Repository\MessageRepository; |
9
|
|
|
use Symfony\Component\HttpFoundation\IpUtils; |
10
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @ORM\Entity(repositoryClass=MessageRepository::class) |
14
|
|
|
*/ |
15
|
|
|
class Message |
16
|
|
|
{ |
17
|
|
|
use IdTrait; |
18
|
|
|
use TimestampableTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
* @ORM\Column(type="string", length=180, nullable=true) |
23
|
|
|
*/ |
24
|
|
|
protected $authorName = ''; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
* @ORM\Column(type="string", length=180, nullable=true) |
29
|
|
|
*/ |
30
|
|
|
protected $authorEmail = ''; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var int |
34
|
|
|
* @ORM\Column(type="integer", nullable=true) |
35
|
|
|
*/ |
36
|
|
|
protected $authorIp; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
* @ORM\Column(type="string", nullable=true) |
41
|
|
|
* @Assert\NotBlank() |
42
|
|
|
* @Assert\Length( |
43
|
|
|
* min = 2, |
44
|
|
|
* max = 200000, |
45
|
|
|
* minMessage = "conversation.content.short", |
46
|
|
|
* maxMessage = "conversation.content.long" |
47
|
|
|
* ) |
48
|
|
|
*/ |
49
|
|
|
protected $content; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Identifier referring (most of time, URI). |
53
|
|
|
* |
54
|
|
|
* @ORM\Column(type="string", length=180) |
55
|
|
|
* |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
protected $referring; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
62
|
|
|
*/ |
63
|
|
|
protected $publishedAt; |
64
|
|
|
|
65
|
|
|
public function __construct() |
66
|
|
|
{ |
67
|
|
|
$this->updatedAt = null !== $this->updatedAt ? $this->updatedAt : new \DateTime(); |
68
|
|
|
$this->createdAt = null !== $this->createdAt ? $this->createdAt : new \DateTime(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getPublishedAt(): ?\DateTimeInterface |
72
|
|
|
{ |
73
|
|
|
return $this->publishedAt; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function setPublishedAt(?\DateTimeInterface $publishedAt): self |
77
|
|
|
{ |
78
|
|
|
$this->publishedAt = $publishedAt; |
79
|
|
|
|
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Set message content. |
85
|
|
|
* |
86
|
|
|
* @param string|null |
87
|
|
|
* |
88
|
|
|
* @return self |
89
|
|
|
*/ |
90
|
|
|
public function setContent($content) |
91
|
|
|
{ |
92
|
|
|
$this->content = $content; |
93
|
|
|
|
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Get message content. |
99
|
|
|
* |
100
|
|
|
* @return string|null |
101
|
|
|
*/ |
102
|
|
|
public function getContent() |
103
|
|
|
{ |
104
|
|
|
return $this->content; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get the value of authorName. |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function getAuthorName() |
113
|
|
|
{ |
114
|
|
|
return $this->authorName; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Set the value of authorName. |
119
|
|
|
* |
120
|
|
|
* @return self |
121
|
|
|
*/ |
122
|
|
|
public function setAuthorName(?string $authorName) |
123
|
|
|
{ |
124
|
|
|
$this->authorName = $authorName; |
125
|
|
|
|
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Get the value of authorEmail. |
131
|
|
|
* |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
public function getAuthorEmail() |
135
|
|
|
{ |
136
|
|
|
return $this->authorEmail; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Set the value of authorEmail. |
141
|
|
|
* |
142
|
|
|
* @return self |
143
|
|
|
*/ |
144
|
|
|
public function setAuthorEmail(?string $authorEmail) |
145
|
|
|
{ |
146
|
|
|
$this->authorEmail = $authorEmail; |
147
|
|
|
|
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Get identifier referring. |
153
|
|
|
* |
154
|
|
|
* @return string |
155
|
|
|
*/ |
156
|
|
|
public function getReferring() |
157
|
|
|
{ |
158
|
|
|
return $this->referring; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Set identifier referring. |
163
|
|
|
* |
164
|
|
|
* @param string $from Identifier referring |
165
|
|
|
* |
166
|
|
|
* @return self |
167
|
|
|
*/ |
168
|
|
|
public function setReferring(string $referring) |
169
|
|
|
{ |
170
|
|
|
$this->referring = $referring; |
171
|
|
|
|
172
|
|
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Get the value of authorIp. |
177
|
|
|
* |
178
|
|
|
* @return int |
179
|
|
|
*/ |
180
|
|
|
public function getAuthorIp() |
181
|
|
|
{ |
182
|
|
|
return $this->authorIp; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Set the value of authorIp. |
187
|
|
|
* |
188
|
|
|
* @return self |
189
|
|
|
*/ |
190
|
|
|
public function setAuthorIp(?int $authorIp) |
191
|
|
|
{ |
192
|
|
|
if (null !== $authorIp) { |
193
|
|
|
$this->authorIp = $authorIp; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function setAuthorIpRaw(string $authorIp) |
200
|
|
|
{ |
201
|
|
|
return $this->setAuthorIp(ip2long(IPUtils::anonymize($authorIp))); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function getAuthorIpRaw() |
205
|
|
|
{ |
206
|
|
|
return long2ip($this->getAuthorIp()); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function __toString() |
210
|
|
|
{ |
211
|
|
|
return $this->id.' '; |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|