]>
Commit | Line | Data |
---|---|---|
f38e03dc TC |
1 | <?php |
2 | ||
4dc87223 | 3 | namespace Wallabag\AnnotationBundle\Entity; |
f38e03dc TC |
4 | |
5 | use Doctrine\ORM\Mapping as ORM; | |
6 | use JMS\Serializer\Annotation\ExclusionPolicy; | |
7 | use JMS\Serializer\Annotation\Exclude; | |
8 | use JMS\Serializer\Annotation\VirtualProperty; | |
9 | use JMS\Serializer\Annotation\SerializedName; | |
b0458874 | 10 | use JMS\Serializer\Annotation\Groups; |
2c3e148b | 11 | use Symfony\Component\Validator\Constraints as Assert; |
f38e03dc TC |
12 | use Wallabag\UserBundle\Entity\User; |
13 | use Wallabag\CoreBundle\Entity\Entry; | |
14 | ||
15 | /** | |
4dc87223 | 16 | * Annotation. |
f38e03dc | 17 | * |
4dc87223 NL |
18 | * @ORM\Table(name="annotation") |
19 | * @ORM\Entity(repositoryClass="Wallabag\AnnotationBundle\Repository\AnnotationRepository") | |
f38e03dc TC |
20 | * @ORM\HasLifecycleCallbacks() |
21 | * @ExclusionPolicy("none") | |
22 | */ | |
4dc87223 | 23 | class Annotation |
f38e03dc TC |
24 | { |
25 | /** | |
26 | * @var int | |
27 | * | |
28 | * @ORM\Column(name="id", type="integer") | |
29 | * @ORM\Id | |
30 | * @ORM\GeneratedValue(strategy="AUTO") | |
31 | */ | |
32 | private $id; | |
33 | ||
34 | /** | |
35 | * @var string | |
36 | * | |
37 | * @ORM\Column(name="text", type="text") | |
b0458874 JB |
38 | * |
39 | * @Groups({"entries_for_user", "export_all"}) | |
f38e03dc TC |
40 | */ |
41 | private $text; | |
42 | ||
43 | /** | |
44 | * @var \DateTime | |
45 | * | |
46 | * @ORM\Column(name="created_at", type="datetime") | |
47 | */ | |
48 | private $createdAt; | |
49 | ||
50 | /** | |
51 | * @var \DateTime | |
52 | * | |
53 | * @ORM\Column(name="updated_at", type="datetime") | |
54 | */ | |
55 | private $updatedAt; | |
56 | ||
57 | /** | |
58 | * @var string | |
59 | * | |
2c3e148b | 60 | * @Assert\Length( |
61 | * max = 10000, | |
62 | * maxMessage = "validator.quote_length_too_high" | |
63 | * ) | |
64 | * @ORM\Column(name="quote", type="text") | |
b0458874 JB |
65 | * |
66 | * @Groups({"entries_for_user", "export_all"}) | |
f38e03dc TC |
67 | */ |
68 | private $quote; | |
69 | ||
70 | /** | |
71 | * @var array | |
72 | * | |
73 | * @ORM\Column(name="ranges", type="array") | |
b0458874 JB |
74 | * |
75 | * @Groups({"entries_for_user", "export_all"}) | |
f38e03dc TC |
76 | */ |
77 | private $ranges; | |
78 | ||
79 | /** | |
80 | * @Exclude | |
81 | * | |
82 | * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User") | |
83 | */ | |
84 | private $user; | |
85 | ||
86 | /** | |
87 | * @Exclude | |
88 | * | |
4dc87223 | 89 | * @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Entry", inversedBy="annotations") |
206bade5 | 90 | * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade") |
f38e03dc TC |
91 | */ |
92 | private $entry; | |
93 | ||
94 | /* | |
95 | * @param User $user | |
96 | */ | |
5d6f6f56 | 97 | public function __construct(User $user) |
f38e03dc TC |
98 | { |
99 | $this->user = $user; | |
100 | } | |
101 | ||
102 | /** | |
103 | * Get id. | |
104 | * | |
105 | * @return int | |
106 | */ | |
107 | public function getId() | |
108 | { | |
109 | return $this->id; | |
110 | } | |
111 | ||
112 | /** | |
113 | * Set text. | |
114 | * | |
115 | * @param string $text | |
116 | * | |
4dc87223 | 117 | * @return Annotation |
f38e03dc TC |
118 | */ |
119 | public function setText($text) | |
120 | { | |
121 | $this->text = $text; | |
122 | ||
123 | return $this; | |
124 | } | |
125 | ||
126 | /** | |
127 | * Get text. | |
128 | * | |
129 | * @return string | |
130 | */ | |
131 | public function getText() | |
132 | { | |
133 | return $this->text; | |
134 | } | |
135 | ||
136 | /** | |
137 | * @ORM\PrePersist | |
138 | * @ORM\PreUpdate | |
139 | */ | |
140 | public function timestamps() | |
141 | { | |
142 | if (is_null($this->createdAt)) { | |
143 | $this->createdAt = new \DateTime(); | |
144 | } | |
145 | $this->updatedAt = new \DateTime(); | |
146 | } | |
147 | ||
148 | /** | |
149 | * Get created. | |
150 | * | |
151 | * @return \DateTime | |
152 | */ | |
153 | public function getCreatedAt() | |
154 | { | |
155 | return $this->createdAt; | |
156 | } | |
157 | ||
158 | /** | |
159 | * Get updated. | |
160 | * | |
161 | * @return \DateTime | |
162 | */ | |
163 | public function getUpdatedAt() | |
164 | { | |
165 | return $this->updatedAt; | |
166 | } | |
167 | ||
168 | /** | |
169 | * Get quote. | |
170 | * | |
171 | * @return string | |
172 | */ | |
173 | public function getQuote() | |
174 | { | |
175 | return $this->quote; | |
176 | } | |
177 | ||
178 | /** | |
179 | * Set quote. | |
180 | * | |
181 | * @param string $quote | |
182 | * | |
4dc87223 | 183 | * @return Annotation |
f38e03dc TC |
184 | */ |
185 | public function setQuote($quote) | |
186 | { | |
187 | $this->quote = $quote; | |
188 | ||
189 | return $this; | |
190 | } | |
191 | ||
192 | /** | |
193 | * Get ranges. | |
194 | * | |
195 | * @return array | |
196 | */ | |
197 | public function getRanges() | |
198 | { | |
199 | return $this->ranges; | |
200 | } | |
201 | ||
202 | /** | |
203 | * Set ranges. | |
204 | * | |
205 | * @param array $ranges | |
206 | * | |
4dc87223 | 207 | * @return Annotation |
f38e03dc TC |
208 | */ |
209 | public function setRanges($ranges) | |
210 | { | |
211 | $this->ranges = $ranges; | |
212 | ||
213 | return $this; | |
214 | } | |
215 | ||
216 | /** | |
217 | * Set user. | |
218 | * | |
5d6f6f56 | 219 | * @param User $user |
f38e03dc | 220 | * |
4dc87223 | 221 | * @return Annotation |
f38e03dc TC |
222 | */ |
223 | public function setUser($user) | |
224 | { | |
225 | $this->user = $user; | |
226 | ||
227 | return $this; | |
228 | } | |
229 | ||
230 | /** | |
231 | * Get user. | |
232 | * | |
5d6f6f56 | 233 | * @return User |
f38e03dc TC |
234 | */ |
235 | public function getUser() | |
236 | { | |
237 | return $this->user; | |
238 | } | |
239 | ||
240 | /** | |
241 | * @VirtualProperty | |
242 | * @SerializedName("user") | |
243 | */ | |
244 | public function getUserName() | |
245 | { | |
246 | return $this->user->getName(); | |
247 | } | |
248 | ||
249 | /** | |
250 | * Set entry. | |
251 | * | |
252 | * @param Entry $entry | |
253 | * | |
4dc87223 | 254 | * @return Annotation |
f38e03dc TC |
255 | */ |
256 | public function setEntry($entry) | |
257 | { | |
258 | $this->entry = $entry; | |
4dc87223 | 259 | $entry->setAnnotation($this); |
f38e03dc TC |
260 | |
261 | return $this; | |
262 | } | |
263 | ||
264 | /** | |
265 | * Get entry. | |
266 | * | |
267 | * @return Entry | |
268 | */ | |
269 | public function getEntry() | |
270 | { | |
271 | return $this->entry; | |
272 | } | |
273 | ||
274 | /** | |
275 | * @VirtualProperty | |
276 | * @SerializedName("annotator_schema_version") | |
277 | */ | |
278 | public function getVersion() | |
279 | { | |
280 | return 'v1.0'; | |
281 | } | |
282 | } |