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