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