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