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