]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Entity/Entry.php
first draft of hypermedia implementation
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Entry.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Entity;
4
5 use Doctrine\ORM\Mapping as ORM;
6 use Symfony\Component\Validator\Constraints as Assert;
7 use Hateoas\Configuration\Annotation as Hateoas;
8 use JMS\Serializer\Annotation\XmlRoot;
9
10 /**
11 * Entry
12 *
13 * @XmlRoot("entry")
14 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
15 * @ORM\Table(name="entry")
16 * @ORM\HasLifecycleCallbacks()
17 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
18 */
19 class Entry
20 {
21 /** @Serializer\XmlAttribute */
22 /**
23 * @var integer
24 *
25 * @ORM\Column(name="id", type="integer")
26 * @ORM\Id
27 * @ORM\GeneratedValue(strategy="AUTO")
28 */
29 private $id;
30
31 /**
32 * @var string
33 *
34 * @ORM\Column(name="title", type="text", nullable=true)
35 */
36 private $title;
37
38 /**
39 * @var string
40 *
41 * @Assert\NotBlank()
42 * @ORM\Column(name="url", type="text", nullable=true)
43 */
44 private $url;
45
46 /**
47 * @var boolean
48 *
49 * @ORM\Column(name="is_archived", type="boolean")
50 */
51 private $isArchived = false;
52
53 /**
54 * @var boolean
55 *
56 * @ORM\Column(name="is_starred", type="boolean")
57 */
58 private $isStarred = false;
59
60 /**
61 * @var boolean
62 *
63 * @ORM\Column(name="is_deleted", type="boolean")
64 */
65 private $isDeleted = false;
66
67 /**
68 * @var string
69 *
70 * @ORM\Column(name="content", type="text", nullable=true)
71 */
72 private $content;
73
74 /**
75 * @var date
76 *
77 * @ORM\Column(name="created_at", type="datetime")
78 */
79 private $createdAt;
80
81 /**
82 * @var date
83 *
84 * @ORM\Column(name="updated_at", type="datetime")
85 */
86 private $updatedAt;
87
88 /**
89 * @var string
90 *
91 * @ORM\Column(name="comments", type="text", nullable=true)
92 */
93 private $comments;
94
95 /**
96 * @var string
97 *
98 * @ORM\Column(name="mimetype", type="text", nullable=true)
99 */
100 private $mimetype;
101
102 /**
103 * @var integer
104 *
105 * @ORM\Column(name="reading_type", type="integer", nullable=true)
106 */
107 private $readingTime;
108
109 /**
110 * @var string
111 *
112 * @ORM\Column(name="domain_name", type="text", nullable=true)
113 */
114 private $domainName;
115
116 /**
117 * @var boolean
118 *
119 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
120 */
121 private $isPublic;
122
123 /**
124 * @ORM\ManyToOne(targetEntity="User", inversedBy="entries")
125 */
126 private $user;
127
128 /*
129 * @param User $user
130 */
131 public function __construct(User $user)
132 {
133 $this->user = $user;
134 }
135
136 /**
137 * Get id
138 *
139 * @return integer
140 */
141 public function getId()
142 {
143 return $this->id;
144 }
145
146 /**
147 * Set title
148 *
149 * @param string $title
150 * @return Entry
151 */
152 public function setTitle($title)
153 {
154 $this->title = $title;
155
156 return $this;
157 }
158
159 /**
160 * Get title
161 *
162 * @return string
163 */
164 public function getTitle()
165 {
166 return $this->title;
167 }
168
169 /**
170 * Set url
171 *
172 * @param string $url
173 * @return Entry
174 */
175 public function setUrl($url)
176 {
177 $this->url = $url;
178
179 return $this;
180 }
181
182 /**
183 * Get url
184 *
185 * @return string
186 */
187 public function getUrl()
188 {
189 return $this->url;
190 }
191
192 /**
193 * Set isArchived
194 *
195 * @param string $isArchived
196 * @return Entry
197 */
198 public function setArchived($isArchived)
199 {
200 $this->isArchived = $isArchived;
201
202 return $this;
203 }
204
205 /**
206 * Get isArchived
207 *
208 * @return string
209 */
210 public function isArchived()
211 {
212 return $this->isArchived;
213 }
214
215 public function toggleArchive()
216 {
217 $this->isArchived = $this->isArchived() ^ 1;
218
219 return $this;
220 }
221
222 /**
223 * Set isStarred
224 *
225 * @param string $isStarred
226 * @return Entry
227 */
228 public function setStarred($isStarred)
229 {
230 $this->isStarred = $isStarred;
231
232 return $this;
233 }
234
235 /**
236 * Get isStarred
237 *
238 * @return string
239 */
240 public function isStarred()
241 {
242 return $this->isStarred;
243 }
244
245 public function toggleStar()
246 {
247 $this->isStarred = $this->isStarred() ^ 1;
248
249 return $this;
250 }
251
252 /**
253 * Set content
254 *
255 * @param string $content
256 * @return Entry
257 */
258 public function setContent($content)
259 {
260 $this->content = $content;
261
262 return $this;
263 }
264
265 /**
266 * Get content
267 *
268 * @return string
269 */
270 public function getContent()
271 {
272 return $this->content;
273 }
274
275 /**
276 * @return User
277 */
278 public function getUser()
279 {
280 return $this->user;
281 }
282
283 /**
284 * @return string
285 */
286 public function isDeleted()
287 {
288 return $this->isDeleted;
289 }
290
291 /**
292 * @param string $isDeleted
293 */
294 public function setDeleted($isDeleted)
295 {
296 $this->isDeleted = $isDeleted;
297 }
298
299 /**
300 * @return string
301 */
302 public function getCreatedAt()
303 {
304 return $this->createdAt;
305 }
306
307 /**
308 * @return string
309 */
310 public function getUpdatedAt()
311 {
312 return $this->updatedAt;
313 }
314
315 /**
316 * @ORM\PrePersist
317 * @ORM\PreUpdate
318 */
319 public function timestamps()
320 {
321 if (is_null($this->createdAt)) {
322 $this->createdAt = new \DateTime();
323 }
324
325 $this->updatedAt = new \DateTime();
326 }
327
328 /**
329 * @return string
330 */
331 public function getComments()
332 {
333 return $this->comments;
334 }
335
336 /**
337 * @param string $comments
338 */
339 public function setComments($comments)
340 {
341 $this->comments = $comments;
342 }
343
344 /**
345 * @return string
346 */
347 public function getMimetype()
348 {
349 return $this->mimetype;
350 }
351
352 /**
353 * @param string $mimetype
354 */
355 public function setMimetype($mimetype)
356 {
357 $this->mimetype = $mimetype;
358 }
359
360 /**
361 * @return int
362 */
363 public function getReadingTime()
364 {
365 return $this->readingTime;
366 }
367
368 /**
369 * @param int $readingTime
370 */
371 public function setReadingTime($readingTime)
372 {
373 $this->readingTime = $readingTime;
374 }
375
376 /**
377 * @return string
378 */
379 public function getDomainName()
380 {
381 return $this->domainName;
382 }
383
384 /**
385 * @param string $domainName
386 */
387 public function setDomainName($domainName)
388 {
389 $this->domainName = $domainName;
390 }
391
392 /**
393 * @return boolean
394 */
395 public function isPublic()
396 {
397 return $this->isPublic;
398 }
399
400 /**
401 * @param boolean $isPublic
402 */
403 public function setPublic($isPublic)
404 {
405 $this->isPublic = $isPublic;
406 }
407 }