]>
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 | * | |
8197f082 | 63 | * @Assert\NotNull() |
2c3e148b | 64 | * @Assert\Length( |
65 | * max = 10000, | |
66 | * maxMessage = "validator.quote_length_too_high" | |
67 | * ) | |
68 | * @ORM\Column(name="quote", type="text") | |
b0458874 JB |
69 | * |
70 | * @Groups({"entries_for_user", "export_all"}) | |
f38e03dc TC |
71 | */ |
72 | private $quote; | |
73 | ||
74 | /** | |
75 | * @var array | |
76 | * | |
77 | * @ORM\Column(name="ranges", type="array") | |
b0458874 JB |
78 | * |
79 | * @Groups({"entries_for_user", "export_all"}) | |
f38e03dc TC |
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 | * | |
4dc87223 | 93 | * @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Entry", inversedBy="annotations") |
206bade5 | 94 | * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade") |
f38e03dc TC |
95 | */ |
96 | private $entry; | |
97 | ||
98 | /* | |
99 | * @param User $user | |
100 | */ | |
5d6f6f56 | 101 | public function __construct(User $user) |
f38e03dc TC |
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 | * | |
4dc87223 | 121 | * @return Annotation |
f38e03dc TC |
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 | ||
f38e03dc TC |
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 | * | |
4dc87223 | 175 | * @return Annotation |
f38e03dc TC |
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 | * | |
4dc87223 | 199 | * @return Annotation |
f38e03dc TC |
200 | */ |
201 | public function setRanges($ranges) | |
202 | { | |
203 | $this->ranges = $ranges; | |
204 | ||
205 | return $this; | |
206 | } | |
207 | ||
208 | /** | |
209 | * Set user. | |
210 | * | |
5d6f6f56 | 211 | * @param User $user |
f38e03dc | 212 | * |
4dc87223 | 213 | * @return Annotation |
f38e03dc TC |
214 | */ |
215 | public function setUser($user) | |
216 | { | |
217 | $this->user = $user; | |
218 | ||
219 | return $this; | |
220 | } | |
221 | ||
222 | /** | |
223 | * Get user. | |
224 | * | |
5d6f6f56 | 225 | * @return User |
f38e03dc TC |
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 | * | |
4dc87223 | 246 | * @return Annotation |
f38e03dc TC |
247 | */ |
248 | public function setEntry($entry) | |
249 | { | |
250 | $this->entry = $entry; | |
4dc87223 | 251 | $entry->setAnnotation($this); |
f38e03dc TC |
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 | } |