]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/AnnotationBundle/Entity/Annotation.php
Add a real configuration for CS-Fixer
[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\UserBundle\Entity\User;
14
15 /**
16 * Annotation.
17 *
18 * @ORM\Table(name="annotation")
19 * @ORM\Entity(repositoryClass="Wallabag\AnnotationBundle\Repository\AnnotationRepository")
20 * @ORM\HasLifecycleCallbacks()
21 * @ExclusionPolicy("none")
22 */
23 class Annotation
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")
38 *
39 * @Groups({"entries_for_user", "export_all"})
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 *
60 * @Assert\Length(
61 * max = 10000,
62 * maxMessage = "validator.quote_length_too_high"
63 * )
64 * @ORM\Column(name="quote", type="text")
65 *
66 * @Groups({"entries_for_user", "export_all"})
67 */
68 private $quote;
69
70 /**
71 * @var array
72 *
73 * @ORM\Column(name="ranges", type="array")
74 *
75 * @Groups({"entries_for_user", "export_all"})
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 *
89 * @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Entry", inversedBy="annotations")
90 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
91 */
92 private $entry;
93
94 /*
95 * @param User $user
96 */
97 public function __construct(User $user)
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 *
117 * @return Annotation
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 (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 *
183 * @return Annotation
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 *
207 * @return Annotation
208 */
209 public function setRanges($ranges)
210 {
211 $this->ranges = $ranges;
212
213 return $this;
214 }
215
216 /**
217 * Set user.
218 *
219 * @param User $user
220 *
221 * @return Annotation
222 */
223 public function setUser($user)
224 {
225 $this->user = $user;
226
227 return $this;
228 }
229
230 /**
231 * Get user.
232 *
233 * @return User
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 *
254 * @return Annotation
255 */
256 public function setEntry($entry)
257 {
258 $this->entry = $entry;
259 $entry->setAnnotation($this);
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 }